feedback2.rs

 1use gpui::{actions, AppContext, ClipboardItem, PromptLevel};
 2use system_specs::SystemSpecs;
 3use workspace::Workspace;
 4
 5pub mod deploy_feedback_button;
 6pub mod feedback_modal;
 7
 8actions!(GiveFeedback, SubmitFeedback);
 9
10mod system_specs;
11
12actions!(
13    CopySystemSpecsIntoClipboard,
14    FileBugReport,
15    RequestFeature,
16    OpenZedCommunityRepo
17);
18
19pub fn init(cx: &mut AppContext) {
20    // TODO: a way to combine these two into one?
21    cx.observe_new_views(feedback_modal::FeedbackModal::register)
22        .detach();
23
24    cx.observe_new_views(|workspace: &mut Workspace, _| {
25        workspace
26            .register_action(|_, _: &CopySystemSpecsIntoClipboard, cx| {
27                    let specs = SystemSpecs::new(&cx).to_string();
28
29                    let prompt = cx.prompt(
30                        PromptLevel::Info,
31                        &format!("Copied into clipboard:\n\n{specs}"),
32                        &["OK"],
33                    );
34                    cx.spawn(|_, _cx| async move {
35                        prompt.await.ok();
36                    })
37                    .detach();
38                    let item = ClipboardItem::new(specs.clone());
39                    cx.write_to_clipboard(item);
40                })
41            .register_action(|_, _: &RequestFeature, cx| {
42                let url = "https://github.com/zed-industries/community/issues/new?assignees=&labels=enhancement%2Ctriage&template=0_feature_request.yml";
43                cx.open_url(url);
44            })
45            .register_action(move |_, _: &FileBugReport, cx| {
46                let url = format!(
47                    "https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}",
48                    urlencoding::encode(&SystemSpecs::new(&cx).to_string())
49                );
50                cx.open_url(&url);
51            })
52            .register_action(move |_, _: &OpenZedCommunityRepo, cx| {
53                let url = "https://github.com/zed-industries/community";
54                cx.open_url(&url);
55        });
56    })
57    .detach();
58}