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() -> 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 AppContext) {
42 cx.observe_new_views(|workspace: &mut Workspace, cx| {
43 feedback_modal::FeedbackModal::register(workspace, cx);
44 workspace
45 .register_action(|_, _: &CopySystemSpecsIntoClipboard, cx| {
46 let specs = SystemSpecs::new(cx);
47
48 cx.spawn(|_, mut cx| async move {
49 let specs = specs.await.to_string();
50
51 cx.update(|cx| cx.write_to_clipboard(ClipboardItem::new_string(specs.clone())))
52 .log_err();
53
54 cx.prompt(
55 PromptLevel::Info,
56 "Copied into clipboard",
57 Some(&specs),
58 &["OK"],
59 )
60 .await
61 .ok();
62 })
63 .detach();
64 })
65 .register_action(|_, _: &RequestFeature, cx| {
66 cx.spawn(|_, mut cx| async move {
67 cx.update(|cx| {
68 cx.open_url(&request_feature_url());
69 })
70 .log_err();
71 })
72 .detach();
73 })
74 .register_action(move |_, _: &FileBugReport, cx| {
75 let specs = SystemSpecs::new(cx);
76 cx.spawn(|_, mut cx| async move {
77 let specs = specs.await;
78 cx.update(|cx| {
79 cx.open_url(&file_bug_report_url(&specs));
80 })
81 .log_err();
82 })
83 .detach();
84 })
85 .register_action(move |_, _: &OpenZedRepo, cx| {
86 cx.open_url(zed_repo_url());
87 });
88 })
89 .detach();
90}