BlueGit

ict rusty-teams

Files

rusty-teams / crates / app-state / src / support_actions.rs

support_actions.rs

support_actions.rs 3.6 KiB Download Raw
1use gpui_kit::Context;
2
3use crate::app_state::AppState;
4use crate::notice::NoticeAction;
5use crate::support::{self, ClientInfo, SupportBundlePaths};
6use crate::support_bundle::{self, SupportBundle};
7use calling::DeviceChoice;
8
9impl AppState {
10 pub fn client_info(&self) -> ClientInfo {
11 let locale = app_base::ui_locale::effective_locale(app_base::ui_locale::load(&self.store));
12 ClientInfo::capture(
13 env!("CARGO_PKG_VERSION"),
14 locale,
15 self.directory.me.is_some(),
16 self.call_report_enabled,
17 device_label(&self.call_input),
18 device_label(&self.call_output),
19 device_label(&self.call_camera),
20 )
21 }
22
23 pub fn create_support_bundle(&self) -> Result<SupportBundle, String> {
24 let data_dir =
25 support::local_data_dir().ok_or_else(|| "data directory unavailable".to_owned())?;
26 support_bundle::write_support_bundle(&data_dir, &self.client_info())
27 .map_err(|error| error.to_string())
28 }
29
30 pub fn github_issue_url_for_bundle(&self, bundle: &SupportBundle) -> String {
31 support::issue_url(
32 &self.client_info(),
33 &SupportBundlePaths {
34 directory: bundle.directory.clone(),
35 folder_name: bundle.folder_name.clone(),
36 },
37 )
38 }
39
40 pub fn reveal_support_bundle(bundle: &SupportBundle) {
41 crate::downloads::reveal_in_file_manager(&bundle.directory);
42 }
43
44 pub fn reveal_logs_folder() {
45 if let Some(directory) = support::local_data_dir().or_else(app_base::diagnostics::directory)
46 {
47 crate::downloads::reveal_in_file_manager(&directory);
48 }
49 }
50
51 pub fn open_github_issue_with_bundle(&mut self, cx: &mut Context<Self>) -> Result<(), String> {
52 let bundle = self.create_support_bundle()?;
53 let url = self.github_issue_url_for_bundle(&bundle);
54 let folder = bundle.directory.clone();
55 crate::external_browser::open_url(cx, &self.store, &url);
56 let action = NoticeAction::new("Open folder", move |_, _| {
57 crate::downloads::reveal_in_file_manager(&folder);
58 });
59 self.raise_notice(
60 format!(
61 "Support package ready: {}. Attach those files to the GitHub issue.",
62 bundle.folder_name
63 ),
64 Some(action),
65 cx,
66 );
67 Ok(())
68 }
69
70 pub fn diagnostics_enabled(&self) -> bool {
71 app_base::diagnostics::is_enabled()
72 }
73
74 pub fn set_diagnostics_enabled(&mut self, on: bool, cx: &mut Context<Self>) {
75 app_base::diagnostics::set_enabled(on);
76 let _ = self.store.set_meta(
77 app_base::diagnostics::DIAGNOSTICS_SETTING_KEY,
78 if on { "1" } else { "0" },
79 );
80 if on {
81 app_base::support::record_startup_client_line(
82 env!("CARGO_PKG_VERSION"),
83 app_base::ui_locale::effective_locale(app_base::ui_locale::load(&self.store)),
84 self.directory.me.is_some(),
85 self.call_report_enabled,
86 );
87 }
88 cx.notify();
89 }
90
91 pub fn clear_diagnostic_logs(&mut self, cx: &mut Context<Self>) {
92 if let Err(error) = app_base::diagnostics::clear_logs() {
93 app_base::diagnostics::record(format!("clear logs: {error}"));
94 }
95 cx.notify();
96 }
97}
98
99fn device_label(choice: &DeviceChoice) -> String {
100 match choice {
101 DeviceChoice::SystemDefault => "default".to_owned(),
102 DeviceChoice::Device(key) if key.is_empty() => "none".to_owned(),
103 DeviceChoice::Device(_) => "selected".to_owned(),
104 }
105}