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        OpenZedRepo
19    ]
20);
21
22const fn zed_repo_url() -> &'static str {
23    "https://github.com/zed-industries/zed"
24}
25
26const fn request_feature_url() -> &'static str {
27    "https://github.com/zed-industries/zed/issues/new?assignees=&labels=enhancement%2Ctriage&template=0_feature_request.yml"
28}
29
30fn file_bug_report_url(specs: &SystemSpecs) -> String {
31    format!(
32        "https://github.com/zed-industries/zed/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}",
33        urlencoding::encode(&specs.to_string())
34    )
35}
36
37pub fn init(cx: &mut AppContext) {
38    cx.observe_new_views(|workspace: &mut Workspace, cx| {
39        feedback_modal::FeedbackModal::register(workspace, cx);
40        workspace
41            .register_action(|_, _: &CopySystemSpecsIntoClipboard, cx| {
42                let specs = SystemSpecs::new(&cx).to_string();
43
44                let prompt = cx.prompt(
45                    PromptLevel::Info,
46                    "Copied into clipboard",
47                    Some(&specs),
48                    &["OK"],
49                );
50                cx.spawn(|_, _cx| async move {
51                    prompt.await.ok();
52                })
53                .detach();
54                cx.write_to_clipboard(ClipboardItem::new(specs.clone()));
55            })
56            .register_action(|_, _: &RequestFeature, cx| {
57                cx.open_url(request_feature_url());
58            })
59            .register_action(move |_, _: &FileBugReport, cx| {
60                cx.open_url(&file_bug_report_url(&SystemSpecs::new(&cx)));
61            })
62            .register_action(move |_, _: &OpenZedRepo, cx| {
63                cx.open_url(zed_repo_url());
64            });
65    })
66    .detach();
67}