BlueGit

ict rusty-teams

feat(settings): Auto-start Teams and Open application in background

- Settings > General > System: "Auto-start Teams", "Open application in background" (Teams strings and order, above "On close, keep the application running")
- auto-start: Windows HKCU\Software\Microsoft\Windows\CurrentVersion\Run value "Rusty Teams", Linux ~/.config/autostart/rusty-teams.desktop; command "<exe>" --autostart; the switch reads the real entry, demo mode never writes it
- open in background: local setting (Teams does not keep it on the account); a --autostart launch hides to the tray, or minimizes when there is no tray (Linux)
- background switch is dimmed while auto-start is off
- deviation: Efficiency mode not built

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

metis Daniel Däschle · pushed by metis

Authored 2026-11-04 · 3 weeks ago

Hash
4857761744f19bb31b65e48cf090d6a07b1271a8
Parent
85506f7a
9 files changed +274 −2
crates/app-base/Cargo.toml +1 −0
@@ -50,6 +50,7 @@ windows = { version = "0.62", features = [
50 50 "Win32_Storage_FileSystem",
51 51 "Win32_System_Com",
52 52 "Win32_System_Pipes",
53 "Win32_System_Registry",
53 54 "Win32_System_SystemInformation",
54 55 "Win32_System_Threading",
55 56 "Win32_UI_Accessibility",
@@ -50,6 +50,7 @@ windows = { version = "0.62", features = [
50 "Win32_Storage_FileSystem",
50 "Win32_Storage_FileSystem",
51 "Win32_System_Com",
51 "Win32_System_Com",
52 "Win32_System_Pipes",
52 "Win32_System_Pipes",
53 "Win32_System_Registry",
53 "Win32_System_SystemInformation",
54 "Win32_System_SystemInformation",
54 "Win32_System_Threading",
55 "Win32_System_Threading",
55 "Win32_UI_Accessibility",
56 "Win32_UI_Accessibility",
crates/app-base/src/autostart.rs added +182 −0
@@ -0,0 +1,182 @@
1 use std::io;
2 use std::path::Path;
3
4 pub const AUTOSTART_FLAG: &str = "--autostart";
5 const BACKGROUND_META_KEY: &str = "startup.open_in_background";
6
7 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8 pub struct StartupSettings {
9 pub auto_start: bool,
10 pub open_in_background: bool,
11 }
12
13 impl StartupSettings {
14 pub fn load(store: &store::Store, read_system: bool) -> StartupSettings {
15 StartupSettings {
16 auto_start: read_system && is_enabled(crate::APP_NAME),
17 open_in_background: store.meta(BACKGROUND_META_KEY).ok().flatten().as_deref()
18 == Some("1"),
19 }
20 }
21
22 pub fn save_background(&self, store: &store::Store) {
23 let _ = store.set_meta(
24 BACKGROUND_META_KEY,
25 if self.open_in_background { "1" } else { "0" },
26 );
27 }
28
29 pub fn starts_hidden(&self, launched_by_autostart: bool) -> bool {
30 launched_by_autostart && self.auto_start && self.open_in_background
31 }
32 }
33
34 pub fn launch_command(executable: &Path) -> String {
35 format!("\"{}\" {AUTOSTART_FLAG}", executable.display())
36 }
37
38 pub fn desktop_entry(name: &str, executable: &Path) -> String {
39 format!(
40 "[Desktop Entry]\nType=Application\nName={name}\nExec={}\nX-GNOME-Autostart-enabled=true\n",
41 launch_command(executable)
42 )
43 }
44
45 pub fn launched_by_autostart(arguments: impl IntoIterator<Item = String>) -> bool {
46 arguments
47 .into_iter()
48 .any(|argument| argument == AUTOSTART_FLAG)
49 }
50
51 #[cfg(not(windows))]
52 fn entry_path(name: &str) -> Option<std::path::PathBuf> {
53 let file_name = format!("{}.desktop", name.to_lowercase().replace(' ', "-"));
54 directories::BaseDirs::new().map(|base| base.config_dir().join("autostart").join(file_name))
55 }
56
57 #[cfg(not(windows))]
58 pub fn is_enabled(name: &str) -> bool {
59 entry_path(name).is_some_and(|path| path.is_file())
60 }
61
62 #[cfg(not(windows))]
63 pub fn set_enabled(name: &str, enabled: bool) -> io::Result<()> {
64 let path = entry_path(name).ok_or_else(|| io::Error::other("no config directory"))?;
65 if !enabled {
66 return match std::fs::remove_file(&path) {
67 Err(error) if error.kind() != io::ErrorKind::NotFound => Err(error),
68 _ => Ok(()),
69 };
70 }
71 if let Some(directory) = path.parent() {
72 std::fs::create_dir_all(directory)?;
73 }
74 std::fs::write(&path, desktop_entry(name, &std::env::current_exe()?))
75 }
76
77 #[cfg(windows)]
78 const RUN_KEY: &str = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
79
80 #[cfg(windows)]
81 fn wide(text: &str) -> Vec<u16> {
82 text.encode_utf16().chain(std::iter::once(0)).collect()
83 }
84
85 #[cfg(windows)]
86 pub fn is_enabled(name: &str) -> bool {
87 use windows::Win32::System::Registry::{HKEY_CURRENT_USER, RRF_RT_REG_SZ, RegGetValueW};
88 use windows::core::PCWSTR;
89 let (key, value) = (wide(RUN_KEY), wide(name));
90 unsafe {
91 RegGetValueW(
92 HKEY_CURRENT_USER,
93 PCWSTR(key.as_ptr()),
94 PCWSTR(value.as_ptr()),
95 RRF_RT_REG_SZ,
96 None,
97 None,
98 None,
99 )
100 .is_ok()
101 }
102 }
103
104 #[cfg(windows)]
105 pub fn set_enabled(name: &str, enabled: bool) -> io::Result<()> {
106 use windows::Win32::Foundation::ERROR_FILE_NOT_FOUND;
107 use windows::Win32::System::Registry::{
108 HKEY_CURRENT_USER, REG_SZ, RegDeleteKeyValueW, RegSetKeyValueW,
109 };
110 use windows::core::PCWSTR;
111 let (key, value) = (wide(RUN_KEY), wide(name));
112 let status = if enabled {
113 let command = wide(&launch_command(&std::env::current_exe()?));
114 unsafe {
115 RegSetKeyValueW(
116 HKEY_CURRENT_USER,
117 PCWSTR(key.as_ptr()),
118 PCWSTR(value.as_ptr()),
119 REG_SZ.0,
120 Some(command.as_ptr().cast()),
121 (command.len() * size_of::<u16>()) as u32,
122 )
123 }
124 } else {
125 match unsafe {
126 RegDeleteKeyValueW(HKEY_CURRENT_USER, PCWSTR(key.as_ptr()), PCWSTR(value.as_ptr()))
127 } {
128 ERROR_FILE_NOT_FOUND => return Ok(()),
129 status => status,
130 }
131 };
132 status
133 .ok()
134 .map_err(|error| io::Error::other(error.message()))
135 }
136
137 #[cfg(test)]
138 mod tests {
139 use std::path::Path;
140
141 use super::{
142 AUTOSTART_FLAG, StartupSettings, desktop_entry, launch_command, launched_by_autostart,
143 };
144
145 #[test]
146 fn background_choice_survives_a_restart_and_only_applies_to_autostart() {
147 let store = store::Store::open_in_memory().unwrap();
148 let loaded = StartupSettings::load(&store, false);
149 assert_eq!(loaded, StartupSettings::default());
150 let settings = StartupSettings {
151 auto_start: true,
152 open_in_background: true,
153 };
154 settings.save_background(&store);
155 assert!(StartupSettings::load(&store, false).open_in_background);
156 assert!(settings.starts_hidden(true));
157 assert!(!settings.starts_hidden(false));
158 assert!(
159 !StartupSettings {
160 auto_start: false,
161 ..settings
162 }
163 .starts_hidden(true)
164 );
165 }
166
167 #[test]
168 fn the_start_command_quotes_the_path_and_marks_the_autostart() {
169 let command = launch_command(Path::new("/opt/rusty teams/teams"));
170 assert_eq!(command, format!("\"/opt/rusty teams/teams\" {AUTOSTART_FLAG}"));
171 let entry = desktop_entry("Rusty Teams", Path::new("/opt/teams"));
172 assert!(entry.starts_with("[Desktop Entry]\n"));
173 assert!(entry.contains(&format!("Exec=\"/opt/teams\" {AUTOSTART_FLAG}\n")));
174 assert!(entry.contains("Name=Rusty Teams\n"));
175 }
176
177 #[test]
178 fn only_the_autostart_flag_marks_a_background_start() {
179 assert!(launched_by_autostart(["--demo".into(), AUTOSTART_FLAG.into()]));
180 assert!(!launched_by_autostart(["--demo".to_owned()]));
181 }
182 }
@@ -0,0 +1,182 @@
1use std::io;
2use std::path::Path;
3
4pub const AUTOSTART_FLAG: &str = "--autostart";
5const BACKGROUND_META_KEY: &str = "startup.open_in_background";
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8pub struct StartupSettings {
9 pub auto_start: bool,
10 pub open_in_background: bool,
11}
12
13impl StartupSettings {
14 pub fn load(store: &store::Store, read_system: bool) -> StartupSettings {
15 StartupSettings {
16 auto_start: read_system && is_enabled(crate::APP_NAME),
17 open_in_background: store.meta(BACKGROUND_META_KEY).ok().flatten().as_deref()
18 == Some("1"),
19 }
20 }
21
22 pub fn save_background(&self, store: &store::Store) {
23 let _ = store.set_meta(
24 BACKGROUND_META_KEY,
25 if self.open_in_background { "1" } else { "0" },
26 );
27 }
28
29 pub fn starts_hidden(&self, launched_by_autostart: bool) -> bool {
30 launched_by_autostart && self.auto_start && self.open_in_background
31 }
32}
33
34pub fn launch_command(executable: &Path) -> String {
35 format!("\"{}\" {AUTOSTART_FLAG}", executable.display())
36}
37
38pub fn desktop_entry(name: &str, executable: &Path) -> String {
39 format!(
40 "[Desktop Entry]\nType=Application\nName={name}\nExec={}\nX-GNOME-Autostart-enabled=true\n",
41 launch_command(executable)
42 )
43}
44
45pub fn launched_by_autostart(arguments: impl IntoIterator<Item = String>) -> bool {
46 arguments
47 .into_iter()
48 .any(|argument| argument == AUTOSTART_FLAG)
49}
50
51#[cfg(not(windows))]
52fn entry_path(name: &str) -> Option<std::path::PathBuf> {
53 let file_name = format!("{}.desktop", name.to_lowercase().replace(' ', "-"));
54 directories::BaseDirs::new().map(|base| base.config_dir().join("autostart").join(file_name))
55}
56
57#[cfg(not(windows))]
58pub fn is_enabled(name: &str) -> bool {
59 entry_path(name).is_some_and(|path| path.is_file())
60}
61
62#[cfg(not(windows))]
63pub fn set_enabled(name: &str, enabled: bool) -> io::Result<()> {
64 let path = entry_path(name).ok_or_else(|| io::Error::other("no config directory"))?;
65 if !enabled {
66 return match std::fs::remove_file(&path) {
67 Err(error) if error.kind() != io::ErrorKind::NotFound => Err(error),
68 _ => Ok(()),
69 };
70 }
71 if let Some(directory) = path.parent() {
72 std::fs::create_dir_all(directory)?;
73 }
74 std::fs::write(&path, desktop_entry(name, &std::env::current_exe()?))
75}
76
77#[cfg(windows)]
78const RUN_KEY: &str = "Software\\Microsoft\\Windows\\CurrentVersion\\Run";
79
80#[cfg(windows)]
81fn wide(text: &str) -> Vec<u16> {
82 text.encode_utf16().chain(std::iter::once(0)).collect()
83}
84
85#[cfg(windows)]
86pub fn is_enabled(name: &str) -> bool {
87 use windows::Win32::System::Registry::{HKEY_CURRENT_USER, RRF_RT_REG_SZ, RegGetValueW};
88 use windows::core::PCWSTR;
89 let (key, value) = (wide(RUN_KEY), wide(name));
90 unsafe {
91 RegGetValueW(
92 HKEY_CURRENT_USER,
93 PCWSTR(key.as_ptr()),
94 PCWSTR(value.as_ptr()),
95 RRF_RT_REG_SZ,
96 None,
97 None,
98 None,
99 )
100 .is_ok()
101 }
102}
103
104#[cfg(windows)]
105pub fn set_enabled(name: &str, enabled: bool) -> io::Result<()> {
106 use windows::Win32::Foundation::ERROR_FILE_NOT_FOUND;
107 use windows::Win32::System::Registry::{
108 HKEY_CURRENT_USER, REG_SZ, RegDeleteKeyValueW, RegSetKeyValueW,
109 };
110 use windows::core::PCWSTR;
111 let (key, value) = (wide(RUN_KEY), wide(name));
112 let status = if enabled {
113 let command = wide(&launch_command(&std::env::current_exe()?));
114 unsafe {
115 RegSetKeyValueW(
116 HKEY_CURRENT_USER,
117 PCWSTR(key.as_ptr()),
118 PCWSTR(value.as_ptr()),
119 REG_SZ.0,
120 Some(command.as_ptr().cast()),
121 (command.len() * size_of::<u16>()) as u32,
122 )
123 }
124 } else {
125 match unsafe {
126 RegDeleteKeyValueW(HKEY_CURRENT_USER, PCWSTR(key.as_ptr()), PCWSTR(value.as_ptr()))
127 } {
128 ERROR_FILE_NOT_FOUND => return Ok(()),
129 status => status,
130 }
131 };
132 status
133 .ok()
134 .map_err(|error| io::Error::other(error.message()))
135}
136
137#[cfg(test)]
138mod tests {
139 use std::path::Path;
140
141 use super::{
142 AUTOSTART_FLAG, StartupSettings, desktop_entry, launch_command, launched_by_autostart,
143 };
144
145 #[test]
146 fn background_choice_survives_a_restart_and_only_applies_to_autostart() {
147 let store = store::Store::open_in_memory().unwrap();
148 let loaded = StartupSettings::load(&store, false);
149 assert_eq!(loaded, StartupSettings::default());
150 let settings = StartupSettings {
151 auto_start: true,
152 open_in_background: true,
153 };
154 settings.save_background(&store);
155 assert!(StartupSettings::load(&store, false).open_in_background);
156 assert!(settings.starts_hidden(true));
157 assert!(!settings.starts_hidden(false));
158 assert!(
159 !StartupSettings {
160 auto_start: false,
161 ..settings
162 }
163 .starts_hidden(true)
164 );
165 }
166
167 #[test]
168 fn the_start_command_quotes_the_path_and_marks_the_autostart() {
169 let command = launch_command(Path::new("/opt/rusty teams/teams"));
170 assert_eq!(command, format!("\"/opt/rusty teams/teams\" {AUTOSTART_FLAG}"));
171 let entry = desktop_entry("Rusty Teams", Path::new("/opt/teams"));
172 assert!(entry.starts_with("[Desktop Entry]\n"));
173 assert!(entry.contains(&format!("Exec=\"/opt/teams\" {AUTOSTART_FLAG}\n")));
174 assert!(entry.contains("Name=Rusty Teams\n"));
175 }
176
177 #[test]
178 fn only_the_autostart_flag_marks_a_background_start() {
179 assert!(launched_by_autostart(["--demo".into(), AUTOSTART_FLAG.into()]));
180 assert!(!launched_by_autostart(["--demo".to_owned()]));
181 }
182}
crates/app-base/src/lib.rs +1 −0
@@ -2,6 +2,7 @@ pub mod agent_api;
2 2 pub mod appearance;
3 3 pub mod agents;
4 4 pub mod assets;
5 pub mod autostart;
5 6 pub mod avatar_image;
6 7 pub mod channel_files;
7 8 pub mod crash_log;
@@ -2,6 +2,7 @@ pub mod agent_api;
2pub mod appearance;
2pub mod appearance;
3pub mod agents;
3pub mod agents;
4pub mod assets;
4pub mod assets;
5pub mod autostart;
5pub mod avatar_image;
6pub mod avatar_image;
6pub mod channel_files;
7pub mod channel_files;
7pub mod crash_log;
8pub mod crash_log;
crates/app-state/src/lib.rs +1 −1
@@ -56,7 +56,7 @@ pub mod urgent_ack;
56 56
57 57 pub use app_ui_kit::render;
58 58 pub use app_base::{
59 APP_NAME, appearance, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
59 APP_NAME, appearance, autostart, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
60 60 demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,
61 61 emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,
62 62 single_instance, stickers, theme, translation, updater, user_activity, zoom,
@@ -56,7 +56,7 @@ pub mod urgent_ack;
56
56
57pub use app_ui_kit::render;
57pub use app_ui_kit::render;
58pub use app_base::{
58pub use app_base::{
59 APP_NAME, appearance, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
59 APP_NAME, appearance, autostart, avatar_image, channel_files, crash_log, demo_cards, demo_chart_cards, demo_gifs,
60 demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,
60 demo_input_cards, demo_library, demo_recap, diagnostics, downloads, format, frame_log, fuzzy,
61 emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,
61 emoticons, image_clipboard, image_view_math, inline_image, presence_link, read_state, recap, remote_image, runtime, schedule_time,
62 single_instance, stickers, theme, translation, updater, user_activity, zoom,
62 single_instance, stickers, theme, translation, updater, user_activity, zoom,
crates/app/src/layout_guard.rs +1 −0
@@ -716,6 +716,7 @@ mod frames {
716 716 switcher_query: None,
717 717 composer_text: None,
718 718 reply_to_last: false,
719 launched_by_autostart: false,
719 720 };
720 721 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
721 722 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
@@ -716,6 +716,7 @@ mod frames {
716 switcher_query: None,
716 switcher_query: None,
717 composer_text: None,
717 composer_text: None,
718 reply_to_last: false,
718 reply_to_last: false,
719 launched_by_autostart: false,
719 };
720 };
720 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
721 let window = gpui_kit::open_window(WindowOptions::default(), cx, move |window, cx| {
721 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
722 cx.new(|cx| AppShell::new(state, None, startup, window, cx))
crates/app/src/main.rs +6 −1
@@ -49,6 +49,7 @@ struct Arguments {
49 49 composer_text: Option<String>,
50 50 reply_to_last: bool,
51 51 channels_tab: bool,
52 autostart: bool,
52 53 demo_sync: Option<Duration>,
53 54 }
54 55
@@ -66,6 +67,7 @@ fn parse_arguments() -> Arguments {
66 67 "--type" => arguments.composer_text = input.next(),
67 68 "--reply-last" => arguments.reply_to_last = true,
68 69 "--channels-tab" => arguments.channels_tab = true,
70 autostart::AUTOSTART_FLAG => arguments.autostart = true,
69 71 "--demo-sync" => {
70 72 arguments.demo_sync = input
71 73 .next()
@@ -235,6 +237,7 @@ fn main() {
235 237 switcher_query: arguments.switcher_query,
236 238 composer_text: arguments.composer_text,
237 239 reply_to_last: arguments.reply_to_last,
240 launched_by_autostart: arguments.autostart,
238 241 };
239 242 let (main_window, _) = gpui_kit::open_window(options, cx, move |window, cx| {
240 243 cx.new(|cx| AppShell::new(state, open_target, startup, window, cx))
@@ -247,7 +250,9 @@ fn main() {
247 250 }
248 251 })
249 252 .detach();
250 cx.activate(true);
253 if !arguments.autostart {
254 cx.activate(true);
255 }
251 256 cx.spawn(async move |cx| {
252 257 loop {
253 258 app_base::native_dumps::heartbeat();
@@ -49,6 +49,7 @@ struct Arguments {
49 composer_text: Option<String>,
49 composer_text: Option<String>,
50 reply_to_last: bool,
50 reply_to_last: bool,
51 channels_tab: bool,
51 channels_tab: bool,
52 autostart: bool,
52 demo_sync: Option<Duration>,
53 demo_sync: Option<Duration>,
53}
54}
54
55
@@ -66,6 +67,7 @@ fn parse_arguments() -> Arguments {
66 "--type" => arguments.composer_text = input.next(),
67 "--type" => arguments.composer_text = input.next(),
67 "--reply-last" => arguments.reply_to_last = true,
68 "--reply-last" => arguments.reply_to_last = true,
68 "--channels-tab" => arguments.channels_tab = true,
69 "--channels-tab" => arguments.channels_tab = true,
70 autostart::AUTOSTART_FLAG => arguments.autostart = true,
69 "--demo-sync" => {
71 "--demo-sync" => {
70 arguments.demo_sync = input
72 arguments.demo_sync = input
71 .next()
73 .next()
@@ -235,6 +237,7 @@ fn main() {
235 switcher_query: arguments.switcher_query,
237 switcher_query: arguments.switcher_query,
236 composer_text: arguments.composer_text,
238 composer_text: arguments.composer_text,
237 reply_to_last: arguments.reply_to_last,
239 reply_to_last: arguments.reply_to_last,
240 launched_by_autostart: arguments.autostart,
238 };
241 };
239 let (main_window, _) = gpui_kit::open_window(options, cx, move |window, cx| {
242 let (main_window, _) = gpui_kit::open_window(options, cx, move |window, cx| {
240 cx.new(|cx| AppShell::new(state, open_target, startup, window, cx))
243 cx.new(|cx| AppShell::new(state, open_target, startup, window, cx))
@@ -247,7 +250,9 @@ fn main() {
247 }
250 }
248 })
251 })
249 .detach();
252 .detach();
250 cx.activate(true);
253 if !arguments.autostart {
254 cx.activate(true);
255 }
251 cx.spawn(async move |cx| {
256 cx.spawn(async move |cx| {
252 loop {
257 loop {
253 app_base::native_dumps::heartbeat();
258 app_base::native_dumps::heartbeat();
crates/app/src/notify/center.rs +33 −0
@@ -32,6 +32,7 @@ use crate::activity::ActivityCenter;
32 32 use crate::agent_api::{self, pending::PendingProposal};
33 33 use crate::agents::{AgentRun, AgentRunsEvent, RunState};
34 34 use crate::app_state::{AppEvent, AppState, selection_for};
35 use crate::autostart::{self, StartupSettings};
35 36 use crate::appearance::AppIcon;
36 37 use crate::call::DemoScene;
37 38 use crate::data::{self, Directory, PresenceKind};
@@ -77,6 +78,7 @@ pub struct NotificationCenter {
77 78 main_window: AnyWindowHandle,
78 79 main_native: Option<NativeHandle>,
79 80 settings: Settings,
81 startup: StartupSettings,
80 82 stack: ToastStack,
81 83 tracker: IncomingTracker,
82 84 throttle: SoundThrottle,
@@ -152,6 +154,7 @@ impl NotificationCenter {
152 154 main_window: window.window_handle(),
153 155 main_native: platform::native_handle(window),
154 156 settings,
157 startup: StartupSettings::load(&app.read(cx).store, !app.read(cx).mode.demo),
155 158 stack: ToastStack::default(),
156 159 tracker: IncomingTracker::new(Utc::now()),
157 160 throttle: SoundThrottle::default(),
@@ -270,6 +273,36 @@ impl NotificationCenter {
270 273 self.stack.get(id).map(|toast| toast.reply_text.clone())
271 274 }
272 275
276 pub fn startup(&self) -> StartupSettings {
277 self.startup
278 }
279
280 pub fn set_auto_start(&mut self, enabled: bool, cx: &mut Context<Self>) {
281 if !self.demo_mode
282 && let Err(error) = autostart::set_enabled(crate::APP_NAME, enabled)
283 {
284 self.app.update(cx, |state, cx| {
285 state.raise_notice(format!("Auto-start could not be changed: {error}"), None, cx)
286 });
287 return;
288 }
289 self.startup.auto_start = enabled;
290 cx.notify();
291 }
292
293 pub fn set_open_in_background(&mut self, enabled: bool, cx: &mut Context<Self>) {
294 self.startup.open_in_background = enabled;
295 self.startup.save_background(&self.app.read(cx).store);
296 cx.notify();
297 }
298
299 pub fn start_in_background(&self, window: &mut Window) {
300 match (&self.tray, self.main_native) {
301 (Some(_), Some(native)) => platform::hide_window(native),
302 _ => window.minimize_window(),
303 }
304 }
305
273 306 pub fn intercept_close(&self, _cx: &App) -> bool {
274 307 match (self.settings.close_to_tray, &self.tray, self.main_native) {
275 308 (true, Some(_), Some(native)) => {
@@ -32,6 +32,7 @@ use crate::activity::ActivityCenter;
32use crate::agent_api::{self, pending::PendingProposal};
32use crate::agent_api::{self, pending::PendingProposal};
33use crate::agents::{AgentRun, AgentRunsEvent, RunState};
33use crate::agents::{AgentRun, AgentRunsEvent, RunState};
34use crate::app_state::{AppEvent, AppState, selection_for};
34use crate::app_state::{AppEvent, AppState, selection_for};
35use crate::autostart::{self, StartupSettings};
35use crate::appearance::AppIcon;
36use crate::appearance::AppIcon;
36use crate::call::DemoScene;
37use crate::call::DemoScene;
37use crate::data::{self, Directory, PresenceKind};
38use crate::data::{self, Directory, PresenceKind};
@@ -77,6 +78,7 @@ pub struct NotificationCenter {
77 main_window: AnyWindowHandle,
78 main_window: AnyWindowHandle,
78 main_native: Option<NativeHandle>,
79 main_native: Option<NativeHandle>,
79 settings: Settings,
80 settings: Settings,
81 startup: StartupSettings,
80 stack: ToastStack,
82 stack: ToastStack,
81 tracker: IncomingTracker,
83 tracker: IncomingTracker,
82 throttle: SoundThrottle,
84 throttle: SoundThrottle,
@@ -152,6 +154,7 @@ impl NotificationCenter {
152 main_window: window.window_handle(),
154 main_window: window.window_handle(),
153 main_native: platform::native_handle(window),
155 main_native: platform::native_handle(window),
154 settings,
156 settings,
157 startup: StartupSettings::load(&app.read(cx).store, !app.read(cx).mode.demo),
155 stack: ToastStack::default(),
158 stack: ToastStack::default(),
156 tracker: IncomingTracker::new(Utc::now()),
159 tracker: IncomingTracker::new(Utc::now()),
157 throttle: SoundThrottle::default(),
160 throttle: SoundThrottle::default(),
@@ -270,6 +273,36 @@ impl NotificationCenter {
270 self.stack.get(id).map(|toast| toast.reply_text.clone())
273 self.stack.get(id).map(|toast| toast.reply_text.clone())
271 }
274 }
272
275
276 pub fn startup(&self) -> StartupSettings {
277 self.startup
278 }
279
280 pub fn set_auto_start(&mut self, enabled: bool, cx: &mut Context<Self>) {
281 if !self.demo_mode
282 && let Err(error) = autostart::set_enabled(crate::APP_NAME, enabled)
283 {
284 self.app.update(cx, |state, cx| {
285 state.raise_notice(format!("Auto-start could not be changed: {error}"), None, cx)
286 });
287 return;
288 }
289 self.startup.auto_start = enabled;
290 cx.notify();
291 }
292
293 pub fn set_open_in_background(&mut self, enabled: bool, cx: &mut Context<Self>) {
294 self.startup.open_in_background = enabled;
295 self.startup.save_background(&self.app.read(cx).store);
296 cx.notify();
297 }
298
299 pub fn start_in_background(&self, window: &mut Window) {
300 match (&self.tray, self.main_native) {
301 (Some(_), Some(native)) => platform::hide_window(native),
302 _ => window.minimize_window(),
303 }
304 }
305
273 pub fn intercept_close(&self, _cx: &App) -> bool {
306 pub fn intercept_close(&self, _cx: &App) -> bool {
274 match (self.settings.close_to_tray, &self.tray, self.main_native) {
307 match (self.settings.close_to_tray, &self.tray, self.main_native) {
275 (true, Some(_), Some(native)) => {
308 (true, Some(_), Some(native)) => {
crates/app/src/settings/general.rs +37 −0
@@ -5,6 +5,7 @@ use gpui_kit::component::{
5 5 menu::{DropdownMenu as _, PopupMenuItem},
6 6 v_flex,
7 7 };
8 use gpui_kit::prelude::FluentBuilder as _;
8 9 use gpui_kit::*;
9 10 use teams_core::{ChatSettingChange, TranslationBehavior};
10 11
@@ -21,14 +22,50 @@ const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
21 22 ("Never translate", TranslationBehavior::Never),
22 23 ];
23 24 const CHIP_HEIGHT: f32 = 24.;
25 const DISABLED_OPACITY: f32 = 0.4;
24 26 const LANGUAGE_MENU_HEIGHT: f32 = 320.;
25 27
28 fn startup_rows(center: &Entity<NotificationCenter>, cx: &App) -> [Stateful<Div>; 2] {
29 let startup = center.read(cx).startup();
30 let (auto_start_center, background_center) = (center.clone(), center.clone());
31 [
32 toggle_row(
33 "settings-auto-start",
34 "Auto-start Teams",
35 "",
36 theme::text_muted(),
37 startup.auto_start,
38 )
39 .on_click(move |_, _, cx| {
40 auto_start_center.update(cx, |center, cx| {
41 center.set_auto_start(!startup.auto_start, cx)
42 })
43 }),
44 toggle_row(
45 "settings-open-in-background",
46 "Open application in background",
47 "",
48 theme::text_muted(),
49 startup.open_in_background,
50 )
51 .when(!startup.auto_start, |row| row.opacity(DISABLED_OPACITY))
52 .when(startup.auto_start, |row| {
53 row.on_click(move |_, _, cx| {
54 background_center.update(cx, |center, cx| {
55 center.set_open_in_background(!startup.open_in_background, cx)
56 })
57 })
58 }),
59 ]
60 }
61
26 62 pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
27 63 let close_to_tray = center.read(cx).settings().close_to_tray;
28 64 let toggle_center = center.clone();
29 65 v_flex()
30 66 .w_full()
31 67 .child(caption("SYSTEM"))
68 .children(startup_rows(center, cx))
32 69 .child(
33 70 toggle_row(
34 71 "settings-close-to-tray",
@@ -5,6 +5,7 @@ use gpui_kit::component::{
5 menu::{DropdownMenu as _, PopupMenuItem},
5 menu::{DropdownMenu as _, PopupMenuItem},
6 v_flex,
6 v_flex,
7};
7};
8use gpui_kit::prelude::FluentBuilder as _;
8use gpui_kit::*;
9use gpui_kit::*;
9use teams_core::{ChatSettingChange, TranslationBehavior};
10use teams_core::{ChatSettingChange, TranslationBehavior};
10
11
@@ -21,14 +22,50 @@ const BEHAVIORS: [(&str, TranslationBehavior); 3] = [
21 ("Never translate", TranslationBehavior::Never),
22 ("Never translate", TranslationBehavior::Never),
22];
23];
23const CHIP_HEIGHT: f32 = 24.;
24const CHIP_HEIGHT: f32 = 24.;
25const DISABLED_OPACITY: f32 = 0.4;
24const LANGUAGE_MENU_HEIGHT: f32 = 320.;
26const LANGUAGE_MENU_HEIGHT: f32 = 320.;
25
27
28fn startup_rows(center: &Entity<NotificationCenter>, cx: &App) -> [Stateful<Div>; 2] {
29 let startup = center.read(cx).startup();
30 let (auto_start_center, background_center) = (center.clone(), center.clone());
31 [
32 toggle_row(
33 "settings-auto-start",
34 "Auto-start Teams",
35 "",
36 theme::text_muted(),
37 startup.auto_start,
38 )
39 .on_click(move |_, _, cx| {
40 auto_start_center.update(cx, |center, cx| {
41 center.set_auto_start(!startup.auto_start, cx)
42 })
43 }),
44 toggle_row(
45 "settings-open-in-background",
46 "Open application in background",
47 "",
48 theme::text_muted(),
49 startup.open_in_background,
50 )
51 .when(!startup.auto_start, |row| row.opacity(DISABLED_OPACITY))
52 .when(startup.auto_start, |row| {
53 row.on_click(move |_, _, cx| {
54 background_center.update(cx, |center, cx| {
55 center.set_open_in_background(!startup.open_in_background, cx)
56 })
57 })
58 }),
59 ]
60}
61
26pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
62pub fn render(center: &Entity<NotificationCenter>, app: &Entity<AppState>, cx: &App) -> Div {
27 let close_to_tray = center.read(cx).settings().close_to_tray;
63 let close_to_tray = center.read(cx).settings().close_to_tray;
28 let toggle_center = center.clone();
64 let toggle_center = center.clone();
29 v_flex()
65 v_flex()
30 .w_full()
66 .w_full()
31 .child(caption("SYSTEM"))
67 .child(caption("SYSTEM"))
68 .children(startup_rows(center, cx))
32 .child(
69 .child(
33 toggle_row(
70 toggle_row(
34 "settings-close-to-tray",
71 "settings-close-to-tray",
crates/app/src/views/shell.rs +12 −0
@@ -78,6 +78,7 @@ pub struct Startup {
78 78 pub switcher_query: Option<String>,
79 79 pub composer_text: Option<String>,
80 80 pub reply_to_last: bool,
81 pub launched_by_autostart: bool,
81 82 }
82 83
83 84 pub const SIDEBAR_HIDDEN_BELOW: f32 = 960.;
@@ -358,7 +359,18 @@ impl AppShell {
358 359 switcher_query,
359 360 composer_text,
360 361 reply_to_last,
362 launched_by_autostart,
361 363 } = startup;
364 if shell
365 .notifications
366 .read(cx)
367 .startup()
368 .starts_hidden(launched_by_autostart)
369 {
370 cx.defer_in(window, |this, window, cx| {
371 this.notifications.read(cx).start_in_background(window)
372 });
373 }
362 374 if let Some(query) = switcher_query {
363 375 shell.toggle_switcher(&query, window, cx);
364 376 }
@@ -78,6 +78,7 @@ pub struct Startup {
78 pub switcher_query: Option<String>,
78 pub switcher_query: Option<String>,
79 pub composer_text: Option<String>,
79 pub composer_text: Option<String>,
80 pub reply_to_last: bool,
80 pub reply_to_last: bool,
81 pub launched_by_autostart: bool,
81}
82}
82
83
83pub const SIDEBAR_HIDDEN_BELOW: f32 = 960.;
84pub const SIDEBAR_HIDDEN_BELOW: f32 = 960.;
@@ -358,7 +359,18 @@ impl AppShell {
358 switcher_query,
359 switcher_query,
359 composer_text,
360 composer_text,
360 reply_to_last,
361 reply_to_last,
362 launched_by_autostart,
361 } = startup;
363 } = startup;
364 if shell
365 .notifications
366 .read(cx)
367 .startup()
368 .starts_hidden(launched_by_autostart)
369 {
370 cx.defer_in(window, |this, window, cx| {
371 this.notifications.read(cx).start_in_background(window)
372 });
373 }
362 if let Some(query) = switcher_query {
374 if let Some(query) = switcher_query {
363 shell.toggle_switcher(&query, window, cx);
375 shell.toggle_switcher(&query, window, cx);
364 }
376 }