feedback.rs

 1use gpui::{actions, App, 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() -> String {
25    "https://github.com/zed-industries/zed/discussions/new/choose".to_string()
26}
27
28fn file_bug_report_url(specs: &SystemSpecs) -> String {
29    format!(
30        concat!(
31            "https://github.com/zed-industries/zed/issues/new",
32            "?",
33            "template=1_bug_report.yml",
34            "&",
35            "environment={}"
36        ),
37        urlencoding::encode(&specs.to_string())
38    )
39}
40
41pub fn init(cx: &mut App) {
42    cx.observe_new(|workspace: &mut Workspace, window, cx| {
43        let Some(window) = window else {
44            return;
45        };
46        feedback_modal::FeedbackModal::register(workspace, window, cx);
47        workspace
48            .register_action(|_, _: &CopySystemSpecsIntoClipboard, window, cx| {
49                let specs = SystemSpecs::new(window, cx);
50
51                cx.spawn_in(window, |_, mut cx| async move {
52                    let specs = specs.await.to_string();
53
54                    cx.update(|_, cx| {
55                        cx.write_to_clipboard(ClipboardItem::new_string(specs.clone()))
56                    })
57                    .log_err();
58
59                    cx.prompt(
60                        PromptLevel::Info,
61                        "Copied into clipboard",
62                        Some(&specs),
63                        &["OK"],
64                    )
65                    .await
66                })
67                .detach();
68            })
69            .register_action(|_, _: &RequestFeature, window, cx| {
70                cx.spawn_in(window, |_, mut cx| async move {
71                    cx.update(|_, cx| {
72                        cx.open_url(&request_feature_url());
73                    })
74                    .log_err();
75                })
76                .detach();
77            })
78            .register_action(move |_, _: &FileBugReport, window, cx| {
79                let specs = SystemSpecs::new(window, cx);
80                cx.spawn_in(window, |_, mut cx| async move {
81                    let specs = specs.await;
82                    cx.update(|_, cx| {
83                        cx.open_url(&file_bug_report_url(&specs));
84                    })
85                    .log_err();
86                })
87                .detach();
88            })
89            .register_action(move |_, _: &OpenZedRepo, _, cx| {
90                cx.open_url(zed_repo_url());
91            });
92    })
93    .detach();
94}