1use gpui::{App, ClipboardItem, PromptLevel, actions};
2use system_specs::{CopySystemSpecsIntoClipboard, SystemSpecs};
3use util::ResultExt;
4use workspace::Workspace;
5use zed_actions::feedback::{EmailZed, FileBugReport, RequestFeature};
6
7actions!(
8 zed,
9 [
10 /// Opens the Zed repository on GitHub.
11 OpenZedRepo,
12 ]
13);
14
15const ZED_REPO_URL: &str = "https://github.com/zed-industries/zed";
16
17const REQUEST_FEATURE_URL: &str = "https://github.com/zed-industries/zed/discussions/new/choose";
18
19fn file_bug_report_url(specs: &SystemSpecs) -> String {
20 format!(
21 concat!(
22 "https://github.com/zed-industries/zed/issues/new",
23 "?",
24 "template=10_bug_report.yml",
25 "&",
26 "environment={}"
27 ),
28 urlencoding::encode(&specs.to_string())
29 )
30}
31
32fn email_zed_url(specs: &SystemSpecs) -> String {
33 format!(
34 concat!("mailto:hi@zed.dev", "?", "body={}"),
35 email_body(specs)
36 )
37}
38
39fn email_body(specs: &SystemSpecs) -> String {
40 let body = format!("\n\nSystem Information:\n\n{}", specs);
41 urlencoding::encode(&body).to_string()
42}
43
44pub fn init(cx: &mut App) {
45 cx.observe_new(|workspace: &mut Workspace, _, _| {
46 workspace
47 .register_action(|_, _: &CopySystemSpecsIntoClipboard, window, cx| {
48 let specs = SystemSpecs::new(window, cx);
49
50 cx.spawn_in(window, async move |_, cx| {
51 let specs = specs.await.to_string();
52
53 cx.update(|_, cx| {
54 cx.write_to_clipboard(ClipboardItem::new_string(specs.clone()))
55 })
56 .log_err();
57
58 cx.prompt(
59 PromptLevel::Info,
60 "Copied into clipboard",
61 Some(&specs),
62 &["OK"],
63 )
64 .await
65 })
66 .detach();
67 })
68 .register_action(|_, _: &RequestFeature, _, cx| {
69 cx.open_url(REQUEST_FEATURE_URL);
70 })
71 .register_action(move |_, _: &FileBugReport, window, cx| {
72 let specs = SystemSpecs::new(window, cx);
73 cx.spawn_in(window, async move |_, cx| {
74 let specs = specs.await;
75 cx.update(|_, cx| {
76 cx.open_url(&file_bug_report_url(&specs));
77 })
78 .log_err();
79 })
80 .detach();
81 })
82 .register_action(move |_, _: &EmailZed, window, cx| {
83 let specs = SystemSpecs::new(window, cx);
84 cx.spawn_in(window, async move |_, cx| {
85 let specs = specs.await;
86 cx.update(|_, cx| {
87 cx.open_url(&email_zed_url(&specs));
88 })
89 .log_err();
90 })
91 .detach();
92 })
93 .register_action(move |_, _: &OpenZedRepo, _, cx| {
94 cx.open_url(ZED_REPO_URL);
95 });
96 })
97 .detach();
98}