feedback.rs

 1use gpui::{actions, AppContext, ClipboardItem, PromptLevel};
 2use system_specs::SystemSpecs;
 3use util::ResultExt;
 4use workspace::Workspace;
 5
 6pub mod feedback_modal;
 7
 8mod system_specs;
 9
10actions!(
11    zed,
12    [
13        CopySystemSpecsIntoClipboard,
14        FileBugReport,
15        RequestFeature,
16        OpenZedRepo
17    ]
18);
19
20const fn zed_repo_url() -> &'static str {
21    "https://github.com/zed-industries/zed"
22}
23
24fn request_feature_url(specs: &SystemSpecs) -> String {
25    format!(
26        concat!(
27            "https://github.com/zed-industries/zed/issues/new",
28            "?labels=admin+read%2Ctriage%2Cenhancement",
29            "&template=0_feature_request.yml",
30            "&environment={}"
31        ),
32        urlencoding::encode(&specs.to_string())
33    )
34}
35
36fn file_bug_report_url(specs: &SystemSpecs) -> String {
37    format!(
38        concat!(
39            "https://github.com/zed-industries/zed/issues/new",
40            "?labels=admin+read%2Ctriage%2Cbug",
41            "&template=1_bug_report.yml",
42            "&environment={}"
43        ),
44        urlencoding::encode(&specs.to_string())
45    )
46}
47
48pub fn init(cx: &mut AppContext) {
49    cx.observe_new_views(|workspace: &mut Workspace, cx| {
50        feedback_modal::FeedbackModal::register(workspace, cx);
51        workspace
52            .register_action(|_, _: &CopySystemSpecsIntoClipboard, cx| {
53                let specs = SystemSpecs::new(cx);
54
55                cx.spawn(|_, mut cx| async move {
56                    let specs = specs.await.to_string();
57
58                    cx.update(|cx| cx.write_to_clipboard(ClipboardItem::new_string(specs.clone())))
59                        .log_err();
60
61                    cx.prompt(
62                        PromptLevel::Info,
63                        "Copied into clipboard",
64                        Some(&specs),
65                        &["OK"],
66                    )
67                    .await
68                    .ok();
69                })
70                .detach();
71            })
72            .register_action(|_, _: &RequestFeature, cx| {
73                let specs = SystemSpecs::new(cx);
74                cx.spawn(|_, mut cx| async move {
75                    let specs = specs.await;
76                    cx.update(|cx| {
77                        cx.open_url(&request_feature_url(&specs));
78                    })
79                    .log_err();
80                })
81                .detach();
82            })
83            .register_action(move |_, _: &FileBugReport, cx| {
84                let specs = SystemSpecs::new(cx);
85                cx.spawn(|_, mut cx| async move {
86                    let specs = specs.await;
87                    cx.update(|cx| {
88                        cx.open_url(&file_bug_report_url(&specs));
89                    })
90                    .log_err();
91                })
92                .detach();
93            })
94            .register_action(move |_, _: &OpenZedRepo, cx| {
95                cx.open_url(zed_repo_url());
96            });
97    })
98    .detach();
99}