BlueGit

ict rusty-teams

Files

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

support_actions.rs

support_actions.rs 3.8 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 let diagnostics = support::diagnostics_log_path()
27 .unwrap_or_else(|| data_dir.join(app_base::diagnostics::DIAGNOSTICS_FILE));
28 support_bundle::write_support_bundle(&data_dir, &self.client_info(), &diagnostics)
29 .map_err(|error| error.to_string())
30 }
31
32 pub fn github_issue_url_for_bundle(&self, bundle: &SupportBundle) -> String {
33 support::issue_url(
34 &self.client_info(),
35 &SupportBundlePaths {
36 directory: bundle.directory.clone(),
37 folder_name: bundle.folder_name.clone(),
38 },
39 )
40 }
41
42 pub fn reveal_support_bundle(bundle: &SupportBundle) {
43 crate::downloads::reveal_in_file_manager(&bundle.directory);
44 }
45
46 pub fn reveal_logs_folder() {
47 if let Some(directory) = support::local_data_dir().or_else(app_base::diagnostics::directory)
48 {
49 crate::downloads::reveal_in_file_manager(&directory);
50 }
51 }
52
53 pub fn open_github_issue_with_bundle(&mut self, cx: &mut Context<Self>) -> Result<(), String> {
54 let bundle = self.create_support_bundle()?;
55 let url = self.github_issue_url_for_bundle(&bundle);
56 let folder = bundle.directory.clone();
57 crate::external_browser::open_url(cx, &self.store, &url);
58 let action = NoticeAction::new("Open folder", move |_, _| {
59 crate::downloads::reveal_in_file_manager(&folder);
60 });
61 self.raise_notice(
62 format!(
63 "Support package ready: {}. Attach those files to the GitHub issue.",
64 bundle.folder_name
65 ),
66 Some(action),
67 cx,
68 );
69 Ok(())
70 }
71
72 pub fn diagnostics_enabled(&self) -> bool {
73 app_base::diagnostics::is_enabled()
74 }
75
76 pub fn set_diagnostics_enabled(&mut self, on: bool, cx: &mut Context<Self>) {
77 app_base::diagnostics::set_enabled(on);
78 let _ = self.store.set_meta(
79 app_base::diagnostics::DIAGNOSTICS_SETTING_KEY,
80 if on { "1" } else { "0" },
81 );
82 if on {
83 app_base::support::record_startup_client_line(
84 env!("CARGO_PKG_VERSION"),
85 app_base::ui_locale::effective_locale(app_base::ui_locale::load(&self.store)),
86 self.directory.me.is_some(),
87 self.call_report_enabled,
88 );
89 }
90 cx.notify();
91 }
92
93 pub fn clear_diagnostic_logs(&mut self, cx: &mut Context<Self>) {
94 if let Err(error) = app_base::diagnostics::clear_logs() {
95 app_base::diagnostics::record(format!("clear logs: {error}"));
96 }
97 cx.notify();
98 }
99}
100
101fn device_label(choice: &DeviceChoice) -> String {
102 match choice {
103 DeviceChoice::SystemDefault => "default".to_owned(),
104 DeviceChoice::Device(key) if key.is_empty() => "none".to_owned(),
105 DeviceChoice::Device(_) => "selected".to_owned(),
106 }
107}