1use std::sync::Arc;
2
3pub mod feedback_editor;
4mod system_specs;
5use gpui::{actions, impl_actions, ClipboardItem, ViewContext};
6use serde::Deserialize;
7use system_specs::SystemSpecs;
8use workspace::Workspace;
9
10// TODO FEEDBACK: This open brownser code is duplicated from the zed crate, where should we refactor it to?
11#[derive(Deserialize, Clone, PartialEq)]
12struct OpenBrowser {
13 url: Arc<str>,
14}
15
16impl_actions!(zed, [OpenBrowser]);
17
18actions!(
19 zed,
20 [CopySystemSpecsIntoClipboard, FileBugReport, RequestFeature,]
21);
22
23pub fn init(cx: &mut gpui::MutableAppContext) {
24 feedback_editor::init(cx);
25
26 cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
27
28 cx.add_action(
29 |_: &mut Workspace, _: &CopySystemSpecsIntoClipboard, cx: &mut ViewContext<Workspace>| {
30 let system_specs = SystemSpecs::new(cx).to_string();
31 let item = ClipboardItem::new(system_specs.clone());
32 cx.prompt(
33 gpui::PromptLevel::Info,
34 &format!("Copied into clipboard:\n\n{system_specs}"),
35 &["OK"],
36 );
37 cx.write_to_clipboard(item);
38 },
39 );
40
41 cx.add_action(
42 |_: &mut Workspace, _: &RequestFeature, cx: &mut ViewContext<Workspace>| {
43 let url = "https://github.com/zed-industries/feedback/issues/new?assignees=&labels=enhancement%2Ctriage&template=0_feature_request.yml";
44 cx.dispatch_action(OpenBrowser {
45 url: url.into(),
46 });
47 },
48 );
49
50 cx.add_action(
51 |_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext<Workspace>| {
52 let system_specs_text = SystemSpecs::new(cx).to_string();
53 let url = format!(
54 "https://github.com/zed-industries/feedback/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}",
55 urlencoding::encode(&system_specs_text)
56 );
57 cx.dispatch_action(OpenBrowser {
58 url: url.into(),
59 });
60 },
61 );
62}