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