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