BlueGit

ict rusty-teams

✨ feat(settings): choose the menu bar and tray icon (#66)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

metis Michael Wallner · pushed by metis

Authored 2026-11-18 · 12 days ago

Hash
50da5d018625b42ba62a72e4d83d8b53534baedb
Parent
cdc19a4b
6 files changed +163 −16
crates/app-base/locales/app.yml +12 −0
@@ -613,6 +613,18 @@ settings:
613 613 app_icon_detail:
614 614 en: Shown in the title bar, taskbar and tray
615 615 de: In Titelleiste, Taskleiste und Infobereich
616 tray_icon:
617 en: Menu bar and tray icon
618 de: Symbol in Menüleiste und Infobereich
619 tray_icon_detail:
620 en: Shown in the macOS menu bar or the system tray. With None, closing the window quits the app
621 de: In der macOS-Menüleiste oder im Infobereich der Taskleiste. Mit Keines beendet das Schliessen des Fensters die App
622 tray_icon_same:
623 en: Same as app icon
624 de: Wie App-Symbol
625 tray_icon_none:
626 en: None
627 de: Keines
616 628 language:
617 629 title:
618 630 en: Language
@@ -613,6 +613,18 @@ settings:
613 app_icon_detail:
613 app_icon_detail:
614 en: Shown in the title bar, taskbar and tray
614 en: Shown in the title bar, taskbar and tray
615 de: In Titelleiste, Taskleiste und Infobereich
615 de: In Titelleiste, Taskleiste und Infobereich
616 tray_icon:
617 en: Menu bar and tray icon
618 de: Symbol in Menüleiste und Infobereich
619 tray_icon_detail:
620 en: Shown in the macOS menu bar or the system tray. With None, closing the window quits the app
621 de: In der macOS-Menüleiste oder im Infobereich der Taskleiste. Mit Keines beendet das Schliessen des Fensters die App
622 tray_icon_same:
623 en: Same as app icon
624 de: Wie App-Symbol
625 tray_icon_none:
626 en: None
627 de: Keines
616 language:
628 language:
617 title:
629 title:
618 en: Language
630 en: Language
crates/app-base/src/appearance.rs +68 −1
@@ -5,6 +5,7 @@ use crate::theme::{self, ColorScheme, Shade};
5 5 const META_KEY: &str = "appearance.settings";
6 6 const COLOR_SCHEME_KEY: &str = "color_scheme";
7 7 const APP_ICON_KEY: &str = "app_icon";
8 const TRAY_ICON_KEY: &str = "tray_icon";
8 9 const THEME_KEY: &str = "theme";
9 10 const ZOOM_KEY: &str = "zoom";
10 11 pub const ZOOM_STEPS: [f32; 14] = [
@@ -51,6 +52,39 @@ impl AppIcon {
51 52 }
52 53 }
53 54
55 /// What the menu bar or system tray shows.
56 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57 pub enum TrayIconChoice {
58 #[default]
59 SameAsApp,
60 Icon(AppIcon),
61 /// No tray entry at all, so closing the main window quits the app.
62 Hidden,
63 }
64
65 impl TrayIconChoice {
66 pub const ALL: [TrayIconChoice; 4] = [
67 TrayIconChoice::SameAsApp,
68 TrayIconChoice::Icon(AppIcon::RustyTeams),
69 TrayIconChoice::Icon(AppIcon::MicrosoftTeams),
70 TrayIconChoice::Hidden,
71 ];
72
73 pub fn key(self) -> &'static str {
74 match self {
75 TrayIconChoice::SameAsApp => "same-as-app",
76 TrayIconChoice::Icon(icon) => icon.key(),
77 TrayIconChoice::Hidden => "none",
78 }
79 }
80
81 pub fn from_key(key: &str) -> Option<TrayIconChoice> {
82 TrayIconChoice::ALL
83 .into_iter()
84 .find(|choice| choice.key() == key)
85 }
86 }
87
54 88 #[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
55 89 pub enum ThemeChoice {
56 90 FollowOperatingSystem,
@@ -114,15 +148,28 @@ pub struct SystemTheme {
114 148 pub struct AppearanceSettings {
115 149 pub color_scheme: &'static ColorScheme,
116 150 pub app_icon: AppIcon,
151 pub tray_icon: TrayIconChoice,
117 152 pub theme: ThemeChoice,
118 153 pub zoom: f32,
119 154 }
120 155
156 impl AppearanceSettings {
157 /// The icon the tray shows, `None` when the tray is switched off.
158 pub fn shown_tray_icon(&self) -> Option<AppIcon> {
159 match self.tray_icon {
160 TrayIconChoice::SameAsApp => Some(self.app_icon),
161 TrayIconChoice::Icon(icon) => Some(icon),
162 TrayIconChoice::Hidden => None,
163 }
164 }
165 }
166
121 167 impl Default for AppearanceSettings {
122 168 fn default() -> Self {
123 169 AppearanceSettings {
124 170 color_scheme: theme::default_scheme(),
125 171 app_icon: AppIcon::default(),
172 tray_icon: TrayIconChoice::default(),
126 173 theme: ThemeChoice::default(),
127 174 zoom: DEFAULT_ZOOM,
128 175 }
@@ -196,9 +243,10 @@ pub fn save(store: &Store, settings: &AppearanceSettings) {
196 243
197 244 fn serialize(settings: &AppearanceSettings) -> String {
198 245 format!(
199 "{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}\n{THEME_KEY}={}\n{ZOOM_KEY}={}",
246 "{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}\n{TRAY_ICON_KEY}={}\n{THEME_KEY}={}\n{ZOOM_KEY}={}",
200 247 settings.color_scheme.id,
201 248 settings.app_icon.key(),
249 settings.tray_icon.key(),
202 250 settings.theme.key(),
203 251 settings.zoom
204 252 )
@@ -218,6 +266,11 @@ fn parse(text: &str) -> AppearanceSettings {
218 266 settings.app_icon = icon;
219 267 }
220 268 }
269 Some((TRAY_ICON_KEY, value)) => {
270 if let Some(choice) = TrayIconChoice::from_key(value) {
271 settings.tray_icon = choice;
272 }
273 }
221 274 Some((THEME_KEY, value)) => {
222 275 if let Some(choice) = ThemeChoice::from_key(value) {
223 276 settings.theme = choice;
@@ -252,6 +305,7 @@ mod tests {
252 305 let settings = AppearanceSettings {
253 306 color_scheme: theme::SCHEMES[1],
254 307 app_icon: AppIcon::MicrosoftTeams,
308 tray_icon: TrayIconChoice::Icon(AppIcon::RustyTeams),
255 309 theme: ThemeChoice::FollowOperatingSystem,
256 310 zoom: 1.25,
257 311 };
@@ -274,6 +328,7 @@ mod tests {
274 328 let changed = AppearanceSettings {
275 329 color_scheme: theme::scheme_by_id("teams").unwrap(),
276 330 app_icon: AppIcon::MicrosoftTeams,
331 tray_icon: TrayIconChoice::Hidden,
277 332 theme: ThemeChoice::Light,
278 333 zoom: 0.9,
279 334 };
@@ -289,6 +344,18 @@ mod tests {
289 344 assert_eq!(parse("zoom=1.3").zoom, 1.25);
290 345 }
291 346
347 #[test]
348 fn the_tray_icon_follows_the_app_icon_until_one_is_chosen() {
349 let following = parse("app_icon=microsoft-teams");
350 assert_eq!(following.tray_icon, TrayIconChoice::SameAsApp);
351 assert_eq!(following.shown_tray_icon(), Some(AppIcon::MicrosoftTeams));
352 let chosen = parse("app_icon=microsoft-teams\ntray_icon=rusty-teams");
353 assert_eq!(chosen.shown_tray_icon(), Some(AppIcon::RustyTeams));
354 let hidden = parse("app_icon=microsoft-teams\ntray_icon=none");
355 assert_eq!(hidden.shown_tray_icon(), None);
356 assert_eq!(parse(&serialize(&hidden)), hidden);
357 }
358
292 359 #[test]
293 360 fn follow_os_takes_dark_light_and_forced_contrast_from_the_system() {
294 361 let follow = ThemeChoice::FollowOperatingSystem;
@@ -5,6 +5,7 @@ use crate::theme::{self, ColorScheme, Shade};
5const META_KEY: &str = "appearance.settings";
5const META_KEY: &str = "appearance.settings";
6const COLOR_SCHEME_KEY: &str = "color_scheme";
6const COLOR_SCHEME_KEY: &str = "color_scheme";
7const APP_ICON_KEY: &str = "app_icon";
7const APP_ICON_KEY: &str = "app_icon";
8const TRAY_ICON_KEY: &str = "tray_icon";
8const THEME_KEY: &str = "theme";
9const THEME_KEY: &str = "theme";
9const ZOOM_KEY: &str = "zoom";
10const ZOOM_KEY: &str = "zoom";
10pub const ZOOM_STEPS: [f32; 14] = [
11pub const ZOOM_STEPS: [f32; 14] = [
@@ -51,6 +52,39 @@ impl AppIcon {
51 }
52 }
52}
53}
53
54
55/// What the menu bar or system tray shows.
56#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
57pub enum TrayIconChoice {
58 #[default]
59 SameAsApp,
60 Icon(AppIcon),
61 /// No tray entry at all, so closing the main window quits the app.
62 Hidden,
63}
64
65impl TrayIconChoice {
66 pub const ALL: [TrayIconChoice; 4] = [
67 TrayIconChoice::SameAsApp,
68 TrayIconChoice::Icon(AppIcon::RustyTeams),
69 TrayIconChoice::Icon(AppIcon::MicrosoftTeams),
70 TrayIconChoice::Hidden,
71 ];
72
73 pub fn key(self) -> &'static str {
74 match self {
75 TrayIconChoice::SameAsApp => "same-as-app",
76 TrayIconChoice::Icon(icon) => icon.key(),
77 TrayIconChoice::Hidden => "none",
78 }
79 }
80
81 pub fn from_key(key: &str) -> Option<TrayIconChoice> {
82 TrayIconChoice::ALL
83 .into_iter()
84 .find(|choice| choice.key() == key)
85 }
86}
87
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
88#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
55pub enum ThemeChoice {
89pub enum ThemeChoice {
56 FollowOperatingSystem,
90 FollowOperatingSystem,
@@ -114,15 +148,28 @@ pub struct SystemTheme {
114pub struct AppearanceSettings {
148pub struct AppearanceSettings {
115 pub color_scheme: &'static ColorScheme,
149 pub color_scheme: &'static ColorScheme,
116 pub app_icon: AppIcon,
150 pub app_icon: AppIcon,
151 pub tray_icon: TrayIconChoice,
117 pub theme: ThemeChoice,
152 pub theme: ThemeChoice,
118 pub zoom: f32,
153 pub zoom: f32,
119}
154}
120
155
156impl AppearanceSettings {
157 /// The icon the tray shows, `None` when the tray is switched off.
158 pub fn shown_tray_icon(&self) -> Option<AppIcon> {
159 match self.tray_icon {
160 TrayIconChoice::SameAsApp => Some(self.app_icon),
161 TrayIconChoice::Icon(icon) => Some(icon),
162 TrayIconChoice::Hidden => None,
163 }
164 }
165}
166
121impl Default for AppearanceSettings {
167impl Default for AppearanceSettings {
122 fn default() -> Self {
168 fn default() -> Self {
123 AppearanceSettings {
169 AppearanceSettings {
124 color_scheme: theme::default_scheme(),
170 color_scheme: theme::default_scheme(),
125 app_icon: AppIcon::default(),
171 app_icon: AppIcon::default(),
172 tray_icon: TrayIconChoice::default(),
126 theme: ThemeChoice::default(),
173 theme: ThemeChoice::default(),
127 zoom: DEFAULT_ZOOM,
174 zoom: DEFAULT_ZOOM,
128 }
175 }
@@ -196,9 +243,10 @@ pub fn save(store: &Store, settings: &AppearanceSettings) {
196
243
197fn serialize(settings: &AppearanceSettings) -> String {
244fn serialize(settings: &AppearanceSettings) -> String {
198 format!(
245 format!(
199 "{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}\n{THEME_KEY}={}\n{ZOOM_KEY}={}",
246 "{COLOR_SCHEME_KEY}={}\n{APP_ICON_KEY}={}\n{TRAY_ICON_KEY}={}\n{THEME_KEY}={}\n{ZOOM_KEY}={}",
200 settings.color_scheme.id,
247 settings.color_scheme.id,
201 settings.app_icon.key(),
248 settings.app_icon.key(),
249 settings.tray_icon.key(),
202 settings.theme.key(),
250 settings.theme.key(),
203 settings.zoom
251 settings.zoom
204 )
252 )
@@ -218,6 +266,11 @@ fn parse(text: &str) -> AppearanceSettings {
218 settings.app_icon = icon;
266 settings.app_icon = icon;
219 }
267 }
220 }
268 }
269 Some((TRAY_ICON_KEY, value)) => {
270 if let Some(choice) = TrayIconChoice::from_key(value) {
271 settings.tray_icon = choice;
272 }
273 }
221 Some((THEME_KEY, value)) => {
274 Some((THEME_KEY, value)) => {
222 if let Some(choice) = ThemeChoice::from_key(value) {
275 if let Some(choice) = ThemeChoice::from_key(value) {
223 settings.theme = choice;
276 settings.theme = choice;
@@ -252,6 +305,7 @@ mod tests {
252 let settings = AppearanceSettings {
305 let settings = AppearanceSettings {
253 color_scheme: theme::SCHEMES[1],
306 color_scheme: theme::SCHEMES[1],
254 app_icon: AppIcon::MicrosoftTeams,
307 app_icon: AppIcon::MicrosoftTeams,
308 tray_icon: TrayIconChoice::Icon(AppIcon::RustyTeams),
255 theme: ThemeChoice::FollowOperatingSystem,
309 theme: ThemeChoice::FollowOperatingSystem,
256 zoom: 1.25,
310 zoom: 1.25,
257 };
311 };
@@ -274,6 +328,7 @@ mod tests {
274 let changed = AppearanceSettings {
328 let changed = AppearanceSettings {
275 color_scheme: theme::scheme_by_id("teams").unwrap(),
329 color_scheme: theme::scheme_by_id("teams").unwrap(),
276 app_icon: AppIcon::MicrosoftTeams,
330 app_icon: AppIcon::MicrosoftTeams,
331 tray_icon: TrayIconChoice::Hidden,
277 theme: ThemeChoice::Light,
332 theme: ThemeChoice::Light,
278 zoom: 0.9,
333 zoom: 0.9,
279 };
334 };
@@ -289,6 +344,18 @@ mod tests {
289 assert_eq!(parse("zoom=1.3").zoom, 1.25);
344 assert_eq!(parse("zoom=1.3").zoom, 1.25);
290 }
345 }
291
346
347 #[test]
348 fn the_tray_icon_follows_the_app_icon_until_one_is_chosen() {
349 let following = parse("app_icon=microsoft-teams");
350 assert_eq!(following.tray_icon, TrayIconChoice::SameAsApp);
351 assert_eq!(following.shown_tray_icon(), Some(AppIcon::MicrosoftTeams));
352 let chosen = parse("app_icon=microsoft-teams\ntray_icon=rusty-teams");
353 assert_eq!(chosen.shown_tray_icon(), Some(AppIcon::RustyTeams));
354 let hidden = parse("app_icon=microsoft-teams\ntray_icon=none");
355 assert_eq!(hidden.shown_tray_icon(), None);
356 assert_eq!(parse(&serialize(&hidden)), hidden);
357 }
358
292 #[test]
359 #[test]
293 fn follow_os_takes_dark_light_and_forced_contrast_from_the_system() {
360 fn follow_os_takes_dark_light_and_forced_contrast_from_the_system() {
294 let follow = ThemeChoice::FollowOperatingSystem;
361 let follow = ThemeChoice::FollowOperatingSystem;
crates/app/src/active_appearance.rs +12 −1
@@ -1,7 +1,9 @@
1 1 use gpui_kit::*;
2 2 use store::Store;
3 3
4 use crate::appearance::{self, AppIcon, AppearanceSettings, SystemTheme, ThemeChoice};
4 use crate::appearance::{
5 self, AppIcon, AppearanceSettings, SystemTheme, ThemeChoice, TrayIconChoice,
6 };
5 7 use crate::theme::{self, ColorScheme};
6 8 use crate::zoom;
7 9
@@ -99,6 +101,15 @@ pub fn set_app_icon(icon: AppIcon, store: &Store, cx: &mut App) {
99 101 cx.refresh_windows();
100 102 }
101 103
104 pub fn set_tray_icon(choice: TrayIconChoice, store: &Store, cx: &mut App) {
105 let settings = AppearanceSettings {
106 tray_icon: choice,
107 ..current(cx)
108 };
109 store_settings(settings, store, cx);
110 cx.refresh_windows();
111 }
112
102 113 pub fn set_zoom(zoom: f32, store: &Store, cx: &mut App) -> bool {
103 114 let current = current(cx);
104 115 if (current.zoom - zoom).abs() < f32::EPSILON {
@@ -1,7 +1,9 @@
1use gpui_kit::*;
1use gpui_kit::*;
2use store::Store;
2use store::Store;
3
3
4use crate::appearance::{self, AppIcon, AppearanceSettings, SystemTheme, ThemeChoice};
4use crate::appearance::{
5 self, AppIcon, AppearanceSettings, SystemTheme, ThemeChoice, TrayIconChoice,
6};
5use crate::theme::{self, ColorScheme};
7use crate::theme::{self, ColorScheme};
6use crate::zoom;
8use crate::zoom;
7
9
@@ -99,6 +101,15 @@ pub fn set_app_icon(icon: AppIcon, store: &Store, cx: &mut App) {
99 cx.refresh_windows();
101 cx.refresh_windows();
100}
102}
101
103
104pub fn set_tray_icon(choice: TrayIconChoice, store: &Store, cx: &mut App) {
105 let settings = AppearanceSettings {
106 tray_icon: choice,
107 ..current(cx)
108 };
109 store_settings(settings, store, cx);
110 cx.refresh_windows();
111}
112
102pub fn set_zoom(zoom: f32, store: &Store, cx: &mut App) -> bool {
113pub fn set_zoom(zoom: f32, store: &Store, cx: &mut App) -> bool {
103 let current = current(cx);
114 let current = current(cx);
104 if (current.zoom - zoom).abs() < f32::EPSILON {
115 if (current.zoom - zoom).abs() < f32::EPSILON {
crates/app/src/notify/center.rs +32 −12
@@ -43,7 +43,7 @@ use crate::activity::ActivityCenter;
43 43 use crate::agent_api::{self, pending::PendingProposal};
44 44 use crate::agents::{AgentRun, AgentRunsEvent, RunState};
45 45 use crate::app_state::{AppEvent, AppState, selection_for};
46 use crate::appearance::AppIcon;
46 use crate::appearance::{AppIcon, AppearanceSettings};
47 47 use crate::autostart::{self, StartupSettings};
48 48 use crate::call::DemoScene;
49 49 use crate::data::{self, Directory, PresenceKind};
@@ -126,6 +126,7 @@ pub struct NotificationCenter {
126 126 desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,
127 127 last_tray_presence: Option<TrayPresence>,
128 128 app_icon: AppIcon,
129 tray_icon: Option<AppIcon>,
129 130 shown_badge: Option<Badge>,
130 131 shown_mention_dot: bool,
131 132 animations: bool,
@@ -148,17 +149,19 @@ impl NotificationCenter {
148 149 ) -> Self {
149 150 let mut settings = settings::load(&app.read(cx).store);
150 151 settings.account = app.read(cx).account_chat_settings().notifications;
151 let app_icon = active_appearance::current(cx).app_icon;
152 let appearance = active_appearance::current(cx);
153 let app_icon = appearance.app_icon;
154 let tray_icon = appearance.shown_tray_icon();
152 155 let initial_presence = tray_presence_from(&app.read(cx), false);
153 156 let tray = if app.read(cx).mode.demo {
154 157 None
155 158 } else {
156 Tray::new(initial_presence.clone(), app_icon.png())
159 tray_icon.and_then(|icon| Tray::new(initial_presence.clone(), icon.png()))
157 160 };
158 161 let last_tray_presence = tray.as_ref().map(|_| initial_presence);
159 162 platform::set_window_icon(window, app_icon.png());
160 163 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
161 this.apply_app_icon(active_appearance::current(cx).app_icon, cx)
164 this.apply_icons(active_appearance::current(cx), cx)
162 165 });
163 166 let locale_observation = cx.observe_global::<ActiveLocale>(|this, cx| {
164 167 // Locale changes the presence title; force a tray sync.
@@ -221,6 +224,7 @@ impl NotificationCenter {
221 224 desktop_avatar_cache: HashMap::new(),
222 225 last_tray_presence,
223 226 app_icon,
227 tray_icon,
224 228 shown_badge: None,
225 229 shown_mention_dot: false,
226 230 animations: platform::animations_enabled(),
@@ -1580,21 +1584,37 @@ impl NotificationCenter {
1580 1584 .ok();
1581 1585 }
1582 1586
1583 fn apply_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {
1584 if icon != self.app_icon {
1585 self.show_app_icon(icon, cx);
1587 fn apply_icons(&mut self, appearance: AppearanceSettings, cx: &mut Context<Self>) {
1588 let tray_icon = appearance.shown_tray_icon();
1589 if tray_icon != self.tray_icon {
1590 self.tray_icon = tray_icon;
1591 self.show_tray_icon(tray_icon, cx);
1592 }
1593 let app_icon = appearance.app_icon;
1594 if app_icon != self.app_icon {
1595 self.app_icon = app_icon;
1596 let _ = self.main_window.update(cx, |_, window, _| {
1597 platform::set_window_icon(window, app_icon.png())
1598 });
1586 1599 }
1587 1600 }
1588 1601
1589 fn show_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {
1590 self.app_icon = icon;
1602 /// Removes the tray for `None` and creates it again when an icon comes back.
1603 fn show_tray_icon(&mut self, icon: Option<AppIcon>, cx: &mut Context<Self>) {
1604 let Some(icon) = icon else {
1605 self.tray = None;
1606 self.last_tray_presence = None;
1607 return;
1608 };
1591 1609 let mention = !self.unread_mentions.is_empty();
1592 1610 if let Some(tray) = &mut self.tray {
1593 1611 tray.set_app_icon(icon.png(), mention);
1612 } else if !self.demo_mode {
1613 let presence = tray_presence_from(self.app.read(cx), mention);
1614 self.tray = Tray::new(presence, icon.png());
1615 self.last_tray_presence = None;
1616 self.sync_tray(cx);
1594 1617 }
1595 let _ = self.main_window.update(cx, |_, window, _| {
1596 platform::set_window_icon(window, icon.png())
1597 });
1598 1618 }
1599 1619
1600 1620 fn relocalize_tray(&self) {
@@ -43,7 +43,7 @@ use crate::activity::ActivityCenter;
43use crate::agent_api::{self, pending::PendingProposal};
43use crate::agent_api::{self, pending::PendingProposal};
44use crate::agents::{AgentRun, AgentRunsEvent, RunState};
44use crate::agents::{AgentRun, AgentRunsEvent, RunState};
45use crate::app_state::{AppEvent, AppState, selection_for};
45use crate::app_state::{AppEvent, AppState, selection_for};
46use crate::appearance::AppIcon;
46use crate::appearance::{AppIcon, AppearanceSettings};
47use crate::autostart::{self, StartupSettings};
47use crate::autostart::{self, StartupSettings};
48use crate::call::DemoScene;
48use crate::call::DemoScene;
49use crate::data::{self, Directory, PresenceKind};
49use crate::data::{self, Directory, PresenceKind};
@@ -126,6 +126,7 @@ pub struct NotificationCenter {
126 desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,
126 desktop_avatar_cache: HashMap<String, (u64, NotificationImage)>,
127 last_tray_presence: Option<TrayPresence>,
127 last_tray_presence: Option<TrayPresence>,
128 app_icon: AppIcon,
128 app_icon: AppIcon,
129 tray_icon: Option<AppIcon>,
129 shown_badge: Option<Badge>,
130 shown_badge: Option<Badge>,
130 shown_mention_dot: bool,
131 shown_mention_dot: bool,
131 animations: bool,
132 animations: bool,
@@ -148,17 +149,19 @@ impl NotificationCenter {
148 ) -> Self {
149 ) -> Self {
149 let mut settings = settings::load(&app.read(cx).store);
150 let mut settings = settings::load(&app.read(cx).store);
150 settings.account = app.read(cx).account_chat_settings().notifications;
151 settings.account = app.read(cx).account_chat_settings().notifications;
151 let app_icon = active_appearance::current(cx).app_icon;
152 let appearance = active_appearance::current(cx);
153 let app_icon = appearance.app_icon;
154 let tray_icon = appearance.shown_tray_icon();
152 let initial_presence = tray_presence_from(&app.read(cx), false);
155 let initial_presence = tray_presence_from(&app.read(cx), false);
153 let tray = if app.read(cx).mode.demo {
156 let tray = if app.read(cx).mode.demo {
154 None
157 None
155 } else {
158 } else {
156 Tray::new(initial_presence.clone(), app_icon.png())
159 tray_icon.and_then(|icon| Tray::new(initial_presence.clone(), icon.png()))
157 };
160 };
158 let last_tray_presence = tray.as_ref().map(|_| initial_presence);
161 let last_tray_presence = tray.as_ref().map(|_| initial_presence);
159 platform::set_window_icon(window, app_icon.png());
162 platform::set_window_icon(window, app_icon.png());
160 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
163 let appearance_observation = cx.observe_global::<ActiveAppearance>(|this, cx| {
161 this.apply_app_icon(active_appearance::current(cx).app_icon, cx)
164 this.apply_icons(active_appearance::current(cx), cx)
162 });
165 });
163 let locale_observation = cx.observe_global::<ActiveLocale>(|this, cx| {
166 let locale_observation = cx.observe_global::<ActiveLocale>(|this, cx| {
164 // Locale changes the presence title; force a tray sync.
167 // Locale changes the presence title; force a tray sync.
@@ -221,6 +224,7 @@ impl NotificationCenter {
221 desktop_avatar_cache: HashMap::new(),
224 desktop_avatar_cache: HashMap::new(),
222 last_tray_presence,
225 last_tray_presence,
223 app_icon,
226 app_icon,
227 tray_icon,
224 shown_badge: None,
228 shown_badge: None,
225 shown_mention_dot: false,
229 shown_mention_dot: false,
226 animations: platform::animations_enabled(),
230 animations: platform::animations_enabled(),
@@ -1580,21 +1584,37 @@ impl NotificationCenter {
1580 .ok();
1584 .ok();
1581 }
1585 }
1582
1586
1583 fn apply_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {
1587 fn apply_icons(&mut self, appearance: AppearanceSettings, cx: &mut Context<Self>) {
1584 if icon != self.app_icon {
1588 let tray_icon = appearance.shown_tray_icon();
1585 self.show_app_icon(icon, cx);
1589 if tray_icon != self.tray_icon {
1590 self.tray_icon = tray_icon;
1591 self.show_tray_icon(tray_icon, cx);
1592 }
1593 let app_icon = appearance.app_icon;
1594 if app_icon != self.app_icon {
1595 self.app_icon = app_icon;
1596 let _ = self.main_window.update(cx, |_, window, _| {
1597 platform::set_window_icon(window, app_icon.png())
1598 });
1586 }
1599 }
1587 }
1600 }
1588
1601
1589 fn show_app_icon(&mut self, icon: AppIcon, cx: &mut Context<Self>) {
1602 /// Removes the tray for `None` and creates it again when an icon comes back.
1590 self.app_icon = icon;
1603 fn show_tray_icon(&mut self, icon: Option<AppIcon>, cx: &mut Context<Self>) {
1604 let Some(icon) = icon else {
1605 self.tray = None;
1606 self.last_tray_presence = None;
1607 return;
1608 };
1591 let mention = !self.unread_mentions.is_empty();
1609 let mention = !self.unread_mentions.is_empty();
1592 if let Some(tray) = &mut self.tray {
1610 if let Some(tray) = &mut self.tray {
1593 tray.set_app_icon(icon.png(), mention);
1611 tray.set_app_icon(icon.png(), mention);
1612 } else if !self.demo_mode {
1613 let presence = tray_presence_from(self.app.read(cx), mention);
1614 self.tray = Tray::new(presence, icon.png());
1615 self.last_tray_presence = None;
1616 self.sync_tray(cx);
1594 }
1617 }
1595 let _ = self.main_window.update(cx, |_, window, _| {
1596 platform::set_window_icon(window, icon.png())
1597 });
1598 }
1618 }
1599
1619
1600 fn relocalize_tray(&self) {
1620 fn relocalize_tray(&self) {
crates/app/src/settings/appearance.rs +37 −2
@@ -6,7 +6,7 @@ use super::rows::{Choice, ROW_INSET, caption, control_row, select_with_width, ti
6 6 use crate::active_appearance;
7 7 use crate::active_locale;
8 8 use crate::app_state::AppState;
9 use crate::appearance::{AppIcon, ThemeChoice};
9 use crate::appearance::{AppIcon, ThemeChoice, TrayIconChoice};
10 10 use crate::i18n::tr;
11 11 use crate::theme::{self, Palette};
12 12 use crate::views::title_bar::app_icon_image;
@@ -81,6 +81,30 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
81 81 active_appearance::set_app_icon(icon, &store, cx);
82 82 })
83 83 });
84 let tray_tiles = TrayIconChoice::ALL.into_iter().map(|choice| {
85 let app = app.clone();
86 let (label, preview) = match choice {
87 TrayIconChoice::SameAsApp => (
88 SharedString::from(tr("settings.appearance.tray_icon_same")),
89 icon_preview(current.app_icon),
90 ),
91 TrayIconChoice::Icon(icon) => (SharedString::from(icon.label()), icon_preview(icon)),
92 TrayIconChoice::Hidden => (
93 SharedString::from(tr("settings.appearance.tray_icon_none")),
94 preview_frame(theme::background()),
95 ),
96 };
97 tile(
98 SharedString::from(format!("settings-tray-icon-{}", choice.key())),
99 label,
100 choice == current.tray_icon,
101 preview,
102 )
103 .on_click(move |_, _, cx| {
104 let store = app.read(cx).store.clone();
105 active_appearance::set_tray_icon(choice, &store, cx);
106 })
107 });
84 108 let theme_choices = ThemeChoice::ALL
85 109 .into_iter()
86 110 .map(|choice| {
@@ -130,6 +154,11 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
130 154 app_icon_detail(),
131 155 icon_tiles,
132 156 ))
157 .child(choice_group(
158 tr("settings.appearance.tray_icon"),
159 tr("settings.appearance.tray_icon_detail"),
160 tray_tiles,
161 ))
133 162 }
134 163
135 164 fn choice_group(
@@ -152,7 +181,13 @@ fn choice_group(
152 181 )
153 182 }
154 183
155 fn tile(id: SharedString, label: &'static str, selected: bool, preview: Div) -> Stateful<Div> {
184 fn tile(
185 id: SharedString,
186 label: impl Into<SharedString>,
187 selected: bool,
188 preview: Div,
189 ) -> Stateful<Div> {
190 let label = label.into();
156 191 v_flex()
157 192 .id(id)
158 193 .w(px(TILE_WIDTH))
@@ -6,7 +6,7 @@ use super::rows::{Choice, ROW_INSET, caption, control_row, select_with_width, ti
6use crate::active_appearance;
6use crate::active_appearance;
7use crate::active_locale;
7use crate::active_locale;
8use crate::app_state::AppState;
8use crate::app_state::AppState;
9use crate::appearance::{AppIcon, ThemeChoice};
9use crate::appearance::{AppIcon, ThemeChoice, TrayIconChoice};
10use crate::i18n::tr;
10use crate::i18n::tr;
11use crate::theme::{self, Palette};
11use crate::theme::{self, Palette};
12use crate::views::title_bar::app_icon_image;
12use crate::views::title_bar::app_icon_image;
@@ -81,6 +81,30 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
81 active_appearance::set_app_icon(icon, &store, cx);
81 active_appearance::set_app_icon(icon, &store, cx);
82 })
82 })
83 });
83 });
84 let tray_tiles = TrayIconChoice::ALL.into_iter().map(|choice| {
85 let app = app.clone();
86 let (label, preview) = match choice {
87 TrayIconChoice::SameAsApp => (
88 SharedString::from(tr("settings.appearance.tray_icon_same")),
89 icon_preview(current.app_icon),
90 ),
91 TrayIconChoice::Icon(icon) => (SharedString::from(icon.label()), icon_preview(icon)),
92 TrayIconChoice::Hidden => (
93 SharedString::from(tr("settings.appearance.tray_icon_none")),
94 preview_frame(theme::background()),
95 ),
96 };
97 tile(
98 SharedString::from(format!("settings-tray-icon-{}", choice.key())),
99 label,
100 choice == current.tray_icon,
101 preview,
102 )
103 .on_click(move |_, _, cx| {
104 let store = app.read(cx).store.clone();
105 active_appearance::set_tray_icon(choice, &store, cx);
106 })
107 });
84 let theme_choices = ThemeChoice::ALL
108 let theme_choices = ThemeChoice::ALL
85 .into_iter()
109 .into_iter()
86 .map(|choice| {
110 .map(|choice| {
@@ -130,6 +154,11 @@ pub fn render(app: &Entity<AppState>, cx: &App) -> Div {
130 app_icon_detail(),
154 app_icon_detail(),
131 icon_tiles,
155 icon_tiles,
132 ))
156 ))
157 .child(choice_group(
158 tr("settings.appearance.tray_icon"),
159 tr("settings.appearance.tray_icon_detail"),
160 tray_tiles,
161 ))
133}
162}
134
163
135fn choice_group(
164fn choice_group(
@@ -152,7 +181,13 @@ fn choice_group(
152 )
181 )
153}
182}
154
183
155fn tile(id: SharedString, label: &'static str, selected: bool, preview: Div) -> Stateful<Div> {
184fn tile(
185 id: SharedString,
186 label: impl Into<SharedString>,
187 selected: bool,
188 preview: Div,
189) -> Stateful<Div> {
190 let label = label.into();
156 v_flex()
191 v_flex()
157 .id(id)
192 .id(id)
158 .w(px(TILE_WIDTH))
193 .w(px(TILE_WIDTH))
crates/app/src/settings/nav.rs +2 −0
@@ -80,6 +80,7 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
80 80 tr("settings.appearance.theme"),
81 81 tr("settings.appearance.color_scheme"),
82 82 tr("settings.appearance.app_icon"),
83 tr("settings.appearance.tray_icon"),
83 84 ],
84 85 SettingsSection::Chats => vec![
85 86 tr("settings.chats.density"),
@@ -429,6 +430,7 @@ mod tests {
429 430 "settings.appearance.theme",
430 431 "settings.appearance.color_scheme",
431 432 "settings.appearance.app_icon",
433 "settings.appearance.tray_icon",
432 434 ],
433 435 SettingsSection::Chats => &[
434 436 "settings.chats.density",
@@ -80,6 +80,7 @@ fn search_terms(section: SettingsSection) -> Vec<String> {
80 tr("settings.appearance.theme"),
80 tr("settings.appearance.theme"),
81 tr("settings.appearance.color_scheme"),
81 tr("settings.appearance.color_scheme"),
82 tr("settings.appearance.app_icon"),
82 tr("settings.appearance.app_icon"),
83 tr("settings.appearance.tray_icon"),
83 ],
84 ],
84 SettingsSection::Chats => vec![
85 SettingsSection::Chats => vec![
85 tr("settings.chats.density"),
86 tr("settings.chats.density"),
@@ -429,6 +430,7 @@ mod tests {
429 "settings.appearance.theme",
430 "settings.appearance.theme",
430 "settings.appearance.color_scheme",
431 "settings.appearance.color_scheme",
431 "settings.appearance.app_icon",
432 "settings.appearance.app_icon",
433 "settings.appearance.tray_icon",
432 ],
434 ],
433 SettingsSection::Chats => &[
435 SettingsSection::Chats => &[
434 "settings.chats.density",
436 "settings.chats.density",