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 EmailZed,
15 FileBugReport,
16 OpenZedRepo,
17 RequestFeature,
18 ]
19);
20
21const ZED_REPO_URL: &str = "https://github.com/zed-industries/zed";
22
23const REQUEST_FEATURE_URL: &str = "https://github.com/zed-industries/zed/discussions/new/choose";
24
25const EMAIL_ZED_URL: &str = "mailto:hi@zed.dev";
26
27fn file_bug_report_url(specs: &SystemSpecs) -> String {
28 format!(
29 concat!(
30 "https://github.com/zed-industries/zed/issues/new",
31 "?",
32 "template=1_bug_report.yml",
33 "&",
34 "environment={}"
35 ),
36 urlencoding::encode(&specs.to_string())
37 )
38}
39
40pub fn init(cx: &mut App) {
41 cx.observe_new(|workspace: &mut Workspace, window, cx| {
42 let Some(window) = window else {
43 return;
44 };
45 feedback_modal::FeedbackModal::register(workspace, window, cx);
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, _, cx| {
83 cx.open_url(EMAIL_ZED_URL);
84 })
85 .register_action(move |_, _: &OpenZedRepo, _, cx| {
86 cx.open_url(ZED_REPO_URL);
87 });
88 })
89 .detach();
90}