BlueGit

ict rusty-teams

feat(shell): replace the status bar with a connection banner, toasts and title bar pieces

- status bar removed
- connection banner above the islands, only after 4 s of a bad state, shown at least 3 s; offline text is the Teams string plus "Last synced HH:MM", "Retry" skips the realtime retry wait
- notices (failures, "Image copied", ...) as toasts bottom right, action button kept; update failure as error toast
- "Restart to update" button next to the avatar, "Demo" / "Read-only" pill next to the app name
- version and build id in the avatar button tooltip (Settings > About unchanged)
- deviation: Teams shows "No internet..." when the browser reports offline; we cannot tell that apart, so always the generic Teams connection string. Connecting / reconnecting / live unavailable / sign-in banners are own texts

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

metis Daniel Däschle · pushed by metis

Authored 2026-10-17 · 6 weeks ago

Hash
19f7f89d0ca0b31d1e835a1e0e6cba363324f1c2
Parent
a46c574d
12 files changed +537 −230
crates/app-state/src/app_state.rs +7 −0
@@ -104,6 +104,8 @@ pub struct AppState {
104 104 pub bot_apps: HashMap<String, Vec<ChatApp>>,
105 105 pub bot_apps_pending: HashSet<String>,
106 106 pub notice: Option<Notice>,
107 pub connection_banner: crate::connection_banner::BannerTiming,
108 pub live_retry: Option<Arc<tokio::sync::Notify>>,
107 109 pub notice_count: u64,
108 110 pub keep_unread: Option<String>,
109 111 pub typing: TypingState,
@@ -253,6 +255,8 @@ impl AppState {
253 255 bot_apps: HashMap::new(),
254 256 bot_apps_pending: HashSet::new(),
255 257 notice: None,
258 connection_banner: Default::default(),
259 live_retry: None,
256 260 notice_count: 0,
257 261 keep_unread: None,
258 262 typing: TypingState::default(),
@@ -898,8 +902,10 @@ impl AppState {
898 902 match event {
899 903 BackendEvent::Connection(connection) => {
900 904 self.connection = connection;
905 self.refresh_connection_banner(cx);
901 906 cx.emit(AppEvent::Status);
902 907 }
908 BackendEvent::LiveRetry(retry) => self.live_retry = Some(retry),
903 909 BackendEvent::Calls(launcher) => {
904 910 launcher.set_default_camera(self.call_camera.clone());
905 911 self.call_launcher = Some(launcher);
@@ -976,6 +982,7 @@ impl AppState {
976 982 BackendEvent::Typing(event) => self.apply_typing(event, cx),
977 983 BackendEvent::Live(live) => {
978 984 self.live = live;
985 self.refresh_connection_banner(cx);
979 986 cx.emit(AppEvent::Status);
980 987 }
981 988 BackendEvent::Favorites(ids) => {
@@ -104,6 +104,8 @@ pub struct AppState {
104 pub bot_apps: HashMap<String, Vec<ChatApp>>,
104 pub bot_apps: HashMap<String, Vec<ChatApp>>,
105 pub bot_apps_pending: HashSet<String>,
105 pub bot_apps_pending: HashSet<String>,
106 pub notice: Option<Notice>,
106 pub notice: Option<Notice>,
107 pub connection_banner: crate::connection_banner::BannerTiming,
108 pub live_retry: Option<Arc<tokio::sync::Notify>>,
107 pub notice_count: u64,
109 pub notice_count: u64,
108 pub keep_unread: Option<String>,
110 pub keep_unread: Option<String>,
109 pub typing: TypingState,
111 pub typing: TypingState,
@@ -253,6 +255,8 @@ impl AppState {
253 bot_apps: HashMap::new(),
255 bot_apps: HashMap::new(),
254 bot_apps_pending: HashSet::new(),
256 bot_apps_pending: HashSet::new(),
255 notice: None,
257 notice: None,
258 connection_banner: Default::default(),
259 live_retry: None,
256 notice_count: 0,
260 notice_count: 0,
257 keep_unread: None,
261 keep_unread: None,
258 typing: TypingState::default(),
262 typing: TypingState::default(),
@@ -898,8 +902,10 @@ impl AppState {
898 match event {
902 match event {
899 BackendEvent::Connection(connection) => {
903 BackendEvent::Connection(connection) => {
900 self.connection = connection;
904 self.connection = connection;
905 self.refresh_connection_banner(cx);
901 cx.emit(AppEvent::Status);
906 cx.emit(AppEvent::Status);
902 }
907 }
908 BackendEvent::LiveRetry(retry) => self.live_retry = Some(retry),
903 BackendEvent::Calls(launcher) => {
909 BackendEvent::Calls(launcher) => {
904 launcher.set_default_camera(self.call_camera.clone());
910 launcher.set_default_camera(self.call_camera.clone());
905 self.call_launcher = Some(launcher);
911 self.call_launcher = Some(launcher);
@@ -976,6 +982,7 @@ impl AppState {
976 BackendEvent::Typing(event) => self.apply_typing(event, cx),
982 BackendEvent::Typing(event) => self.apply_typing(event, cx),
977 BackendEvent::Live(live) => {
983 BackendEvent::Live(live) => {
978 self.live = live;
984 self.live = live;
985 self.refresh_connection_banner(cx);
979 cx.emit(AppEvent::Status);
986 cx.emit(AppEvent::Status);
980 }
987 }
981 BackendEvent::Favorites(ids) => {
988 BackendEvent::Favorites(ids) => {
crates/app-state/src/backend.rs +9 −1
@@ -69,6 +69,7 @@ pub enum BackendEvent {
69 69 Typing(TypingEvent),
70 70 Favorites(Vec<String>),
71 71 Synced(DateTime<Utc>),
72 LiveRetry(Arc<Notify>),
72 73 }
73 74
74 75 type EventSender = mpsc::UnboundedSender<BackendEvent>;
@@ -167,6 +168,8 @@ async fn supervise(
167 168 let (nudge, nudges) = mpsc::unbounded_channel();
168 169 let resend = Arc::new(Notify::new());
169 170 let link = presence_link::start(&session, activity.clone(), resend.clone());
171 let live_retry = Arc::new(Notify::new());
172 let _ = events.send(BackendEvent::LiveRetry(live_retry.clone()));
170 173 tokio::spawn(realtime_loop(
171 174 session.clone(),
172 175 engine.clone(),
@@ -175,6 +178,7 @@ async fn supervise(
175 178 activity,
176 179 resend,
177 180 link,
181 live_retry,
178 182 ));
179 183 tokio::spawn(calendar_loop(session.clone(), events.clone()));
180 184 tokio::spawn(pins_loop(session, events.clone()));
@@ -244,6 +248,7 @@ async fn realtime_loop(
244 248 mut activity: watch::Receiver<bool>,
245 249 resend: Arc<Notify>,
246 250 link: mpsc::UnboundedSender<LinkSignal>,
251 live_retry: Arc<Notify>,
247 252 ) {
248 253 loop {
249 254 let _ = events.send(BackendEvent::Live(LiveState::Connecting));
@@ -320,7 +325,10 @@ async fn realtime_loop(
320 325 let _ = link.send(LinkSignal::Disconnected);
321 326 }
322 327 }
323 tokio::time::sleep(REALTIME_RETRY).await;
328 tokio::select! {
329 _ = tokio::time::sleep(REALTIME_RETRY) => {}
330 _ = live_retry.notified() => {}
331 }
324 332 }
325 333 }
326 334
@@ -69,6 +69,7 @@ pub enum BackendEvent {
69 Typing(TypingEvent),
69 Typing(TypingEvent),
70 Favorites(Vec<String>),
70 Favorites(Vec<String>),
71 Synced(DateTime<Utc>),
71 Synced(DateTime<Utc>),
72 LiveRetry(Arc<Notify>),
72}
73}
73
74
74type EventSender = mpsc::UnboundedSender<BackendEvent>;
75type EventSender = mpsc::UnboundedSender<BackendEvent>;
@@ -167,6 +168,8 @@ async fn supervise(
167 let (nudge, nudges) = mpsc::unbounded_channel();
168 let (nudge, nudges) = mpsc::unbounded_channel();
168 let resend = Arc::new(Notify::new());
169 let resend = Arc::new(Notify::new());
169 let link = presence_link::start(&session, activity.clone(), resend.clone());
170 let link = presence_link::start(&session, activity.clone(), resend.clone());
171 let live_retry = Arc::new(Notify::new());
172 let _ = events.send(BackendEvent::LiveRetry(live_retry.clone()));
170 tokio::spawn(realtime_loop(
173 tokio::spawn(realtime_loop(
171 session.clone(),
174 session.clone(),
172 engine.clone(),
175 engine.clone(),
@@ -175,6 +178,7 @@ async fn supervise(
175 activity,
178 activity,
176 resend,
179 resend,
177 link,
180 link,
181 live_retry,
178 ));
182 ));
179 tokio::spawn(calendar_loop(session.clone(), events.clone()));
183 tokio::spawn(calendar_loop(session.clone(), events.clone()));
180 tokio::spawn(pins_loop(session, events.clone()));
184 tokio::spawn(pins_loop(session, events.clone()));
@@ -244,6 +248,7 @@ async fn realtime_loop(
244 mut activity: watch::Receiver<bool>,
248 mut activity: watch::Receiver<bool>,
245 resend: Arc<Notify>,
249 resend: Arc<Notify>,
246 link: mpsc::UnboundedSender<LinkSignal>,
250 link: mpsc::UnboundedSender<LinkSignal>,
251 live_retry: Arc<Notify>,
247) {
252) {
248 loop {
253 loop {
249 let _ = events.send(BackendEvent::Live(LiveState::Connecting));
254 let _ = events.send(BackendEvent::Live(LiveState::Connecting));
@@ -320,7 +325,10 @@ async fn realtime_loop(
320 let _ = link.send(LinkSignal::Disconnected);
325 let _ = link.send(LinkSignal::Disconnected);
321 }
326 }
322 }
327 }
323 tokio::time::sleep(REALTIME_RETRY).await;
328 tokio::select! {
329 _ = tokio::time::sleep(REALTIME_RETRY) => {}
330 _ = live_retry.notified() => {}
331 }
324 }
332 }
325}
333}
326
334
crates/app-state/src/connection_banner.rs added +244 −0
@@ -0,0 +1,244 @@
1 use std::time::{Duration, Instant};
2
3 use chrono::{DateTime, Local, Utc};
4 use gpui_kit::*;
5
6 use crate::app_state::AppState;
7 use crate::backend::{ConnectionState, LiveState};
8
9 pub const SHOW_AFTER: Duration = Duration::from_secs(4);
10 pub const MIN_VISIBLE: Duration = Duration::from_secs(3);
11 const OFFLINE_TEXT: &str =
12 "Something went wrong while connecting to Teams. Reconnect to keep the conversation going.";
13 const DEMO_OFFLINE_VARIABLE: &str = "TEAMS_DEMO_OFFLINE";
14 const DEMO_LAST_SYNC_AGO: chrono::Duration = chrono::Duration::minutes(12);
15
16 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
17 pub enum BannerKind {
18 Connecting,
19 Reconnecting,
20 Offline,
21 SignIn,
22 LiveUnavailable,
23 }
24
25 #[derive(Debug, Clone, PartialEq, Eq)]
26 pub struct BannerText {
27 pub text: String,
28 pub detail: Option<String>,
29 pub retry: bool,
30 }
31
32 /// What is wrong right now; `None` while live or while only missed messages are being synced.
33 pub fn banner_kind(connection: &ConnectionState, live: LiveState) -> Option<BannerKind> {
34 match connection {
35 ConnectionState::Connecting => return Some(BannerKind::Connecting),
36 ConnectionState::LoginRequired => return Some(BannerKind::SignIn),
37 ConnectionState::NoBrowser | ConnectionState::NoAppTab | ConnectionState::Failed(_) => {
38 return Some(BannerKind::Offline);
39 }
40 ConnectionState::Online => {}
41 }
42 match live {
43 LiveState::Off | LiveState::Live | LiveState::MessageLoss => None,
44 LiveState::Connecting => Some(BannerKind::Connecting),
45 LiveState::Reconnecting => Some(BannerKind::Reconnecting),
46 LiveState::Failed => Some(BannerKind::LiveUnavailable),
47 }
48 }
49
50 pub fn banner_text(kind: BannerKind, last_sync: Option<DateTime<Utc>>) -> BannerText {
51 let text = |text: &str| BannerText {
52 text: text.to_owned(),
53 detail: None,
54 retry: false,
55 };
56 match kind {
57 BannerKind::Connecting => text("Connecting..."),
58 BannerKind::Reconnecting => text("Reconnecting..."),
59 BannerKind::Offline => BannerText {
60 detail: last_sync
61 .map(|time| format!("Last synced {}", time.with_timezone(&Local).format("%H:%M"))),
62 ..text(OFFLINE_TEXT)
63 },
64 BannerKind::SignIn => text("Sign-in required. Sign in to Teams in the window that opened."),
65 BannerKind::LiveUnavailable => BannerText {
66 retry: true,
67 ..text("Live updates unavailable")
68 },
69 }
70 }
71
72 /// Shows a bad state only once it lasted `SHOW_AFTER`, and keeps a shown banner at least `MIN_VISIBLE`.
73 #[derive(Debug, Default)]
74 pub struct BannerTiming {
75 bad_since: Option<Instant>,
76 shown: Option<(BannerKind, Instant)>,
77 }
78
79 impl BannerTiming {
80 pub fn visible(&self) -> Option<BannerKind> {
81 self.shown.map(|(kind, _)| kind)
82 }
83
84 /// Returns when to check again, if the visible banner may change without a new state.
85 pub fn update(&mut self, wanted: Option<BannerKind>, now: Instant) -> Option<Duration> {
86 match wanted {
87 Some(kind) => {
88 let bad_since = *self.bad_since.get_or_insert(now);
89 if let Some((shown_kind, _)) = self.shown.as_mut() {
90 *shown_kind = kind;
91 return None;
92 }
93 let waited = now.duration_since(bad_since);
94 if waited >= SHOW_AFTER {
95 self.shown = Some((kind, now));
96 return None;
97 }
98 Some(SHOW_AFTER - waited)
99 }
100 None => {
101 self.bad_since = None;
102 let (_, shown_at) = self.shown?;
103 let visible_for = now.duration_since(shown_at);
104 if visible_for >= MIN_VISIBLE {
105 self.shown = None;
106 return None;
107 }
108 Some(MIN_VISIBLE - visible_for)
109 }
110 }
111 }
112 }
113
114 impl AppState {
115 pub fn refresh_connection_banner(&mut self, cx: &mut Context<Self>) {
116 let wanted = if self.mode.demo {
117 let offline = std::env::var_os(DEMO_OFFLINE_VARIABLE).is_some();
118 if offline {
119 self.last_sync
120 .get_or_insert_with(|| Utc::now() - DEMO_LAST_SYNC_AGO);
121 }
122 offline.then_some(BannerKind::Offline)
123 } else {
124 banner_kind(&self.connection, self.live)
125 };
126 let before = self.connection_banner.visible();
127 let recheck = self.connection_banner.update(wanted, Instant::now());
128 if let Some(wait) = recheck {
129 cx.spawn(async move |this, cx| {
130 cx.background_executor().timer(wait).await;
131 this.update(cx, |state, cx| state.refresh_connection_banner(cx))
132 .ok();
133 })
134 .detach();
135 }
136 if self.connection_banner.visible() != before {
137 cx.emit(crate::app_state::AppEvent::Status);
138 cx.notify();
139 }
140 }
141
142 pub fn connection_banner_text(&self) -> Option<BannerText> {
143 self.connection_banner
144 .visible()
145 .map(|kind| banner_text(kind, self.last_sync))
146 }
147
148 pub fn retry_live(&mut self) {
149 if let Some(retry) = &self.live_retry {
150 retry.notify_one();
151 }
152 }
153 }
154
155 #[cfg(test)]
156 mod tests {
157 use std::time::{Duration, Instant};
158
159 use chrono::Utc;
160
161 use super::{BannerKind, BannerTiming, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
162 use crate::backend::{ConnectionState, LiveState};
163
164 #[test]
165 fn a_short_bad_state_never_shows() {
166 let mut timing = BannerTiming::default();
167 let start = Instant::now();
168 assert_eq!(
169 timing.update(Some(BannerKind::Reconnecting), start),
170 Some(SHOW_AFTER)
171 );
172 assert_eq!(timing.update(None, start + Duration::from_secs(2)), None);
173 assert_eq!(timing.visible(), None);
174 }
175
176 #[test]
177 fn a_lasting_bad_state_shows_after_the_delay() {
178 let mut timing = BannerTiming::default();
179 let start = Instant::now();
180 timing.update(Some(BannerKind::Reconnecting), start);
181 let wait = timing.update(Some(BannerKind::Offline), start + Duration::from_secs(1));
182 assert_eq!(wait, Some(SHOW_AFTER - Duration::from_secs(1)));
183 assert_eq!(
184 timing.update(Some(BannerKind::Offline), start + SHOW_AFTER),
185 None
186 );
187 assert_eq!(timing.visible(), Some(BannerKind::Offline));
188 }
189
190 #[test]
191 fn a_shown_banner_stays_for_the_minimum_then_goes() {
192 let mut timing = BannerTiming::default();
193 let start = Instant::now();
194 timing.update(Some(BannerKind::Offline), start);
195 let shown_at = start + SHOW_AFTER;
196 timing.update(Some(BannerKind::Offline), shown_at);
197 let back = shown_at + Duration::from_secs(1);
198 assert_eq!(
199 timing.update(None, back),
200 Some(MIN_VISIBLE - Duration::from_secs(1))
201 );
202 assert_eq!(timing.visible(), Some(BannerKind::Offline));
203 assert_eq!(timing.update(None, shown_at + MIN_VISIBLE), None);
204 assert_eq!(timing.visible(), None);
205 }
206
207 #[test]
208 fn a_new_bad_state_while_shown_changes_the_text_at_once() {
209 let mut timing = BannerTiming::default();
210 let start = Instant::now();
211 timing.update(Some(BannerKind::Offline), start);
212 timing.update(Some(BannerKind::Offline), start + SHOW_AFTER);
213 timing.update(None, start + SHOW_AFTER);
214 timing.update(Some(BannerKind::Reconnecting), start + SHOW_AFTER);
215 assert_eq!(timing.visible(), Some(BannerKind::Reconnecting));
216 }
217
218 #[test]
219 fn live_and_missed_messages_need_no_banner() {
220 let online = ConnectionState::Online;
221 assert_eq!(banner_kind(&online, LiveState::Live), None);
222 assert_eq!(banner_kind(&online, LiveState::MessageLoss), None);
223 assert_eq!(
224 banner_kind(&online, LiveState::Failed),
225 Some(BannerKind::LiveUnavailable)
226 );
227 assert_eq!(
228 banner_kind(&ConnectionState::LoginRequired, LiveState::Live),
229 Some(BannerKind::SignIn)
230 );
231 assert_eq!(
232 banner_kind(&ConnectionState::Failed("x".into()), LiveState::Off),
233 Some(BannerKind::Offline)
234 );
235 }
236
237 #[test]
238 fn the_offline_banner_names_the_last_sync() {
239 let text = banner_text(BannerKind::Offline, Some(Utc::now()));
240 assert!(text.detail.unwrap().starts_with("Last synced "));
241 assert!(banner_text(BannerKind::Offline, None).detail.is_none());
242 assert!(banner_text(BannerKind::LiveUnavailable, None).retry);
243 }
244 }
@@ -0,0 +1,244 @@
1use std::time::{Duration, Instant};
2
3use chrono::{DateTime, Local, Utc};
4use gpui_kit::*;
5
6use crate::app_state::AppState;
7use crate::backend::{ConnectionState, LiveState};
8
9pub const SHOW_AFTER: Duration = Duration::from_secs(4);
10pub const MIN_VISIBLE: Duration = Duration::from_secs(3);
11const OFFLINE_TEXT: &str =
12 "Something went wrong while connecting to Teams. Reconnect to keep the conversation going.";
13const DEMO_OFFLINE_VARIABLE: &str = "TEAMS_DEMO_OFFLINE";
14const DEMO_LAST_SYNC_AGO: chrono::Duration = chrono::Duration::minutes(12);
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum BannerKind {
18 Connecting,
19 Reconnecting,
20 Offline,
21 SignIn,
22 LiveUnavailable,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq)]
26pub struct BannerText {
27 pub text: String,
28 pub detail: Option<String>,
29 pub retry: bool,
30}
31
32/// What is wrong right now; `None` while live or while only missed messages are being synced.
33pub fn banner_kind(connection: &ConnectionState, live: LiveState) -> Option<BannerKind> {
34 match connection {
35 ConnectionState::Connecting => return Some(BannerKind::Connecting),
36 ConnectionState::LoginRequired => return Some(BannerKind::SignIn),
37 ConnectionState::NoBrowser | ConnectionState::NoAppTab | ConnectionState::Failed(_) => {
38 return Some(BannerKind::Offline);
39 }
40 ConnectionState::Online => {}
41 }
42 match live {
43 LiveState::Off | LiveState::Live | LiveState::MessageLoss => None,
44 LiveState::Connecting => Some(BannerKind::Connecting),
45 LiveState::Reconnecting => Some(BannerKind::Reconnecting),
46 LiveState::Failed => Some(BannerKind::LiveUnavailable),
47 }
48}
49
50pub fn banner_text(kind: BannerKind, last_sync: Option<DateTime<Utc>>) -> BannerText {
51 let text = |text: &str| BannerText {
52 text: text.to_owned(),
53 detail: None,
54 retry: false,
55 };
56 match kind {
57 BannerKind::Connecting => text("Connecting..."),
58 BannerKind::Reconnecting => text("Reconnecting..."),
59 BannerKind::Offline => BannerText {
60 detail: last_sync
61 .map(|time| format!("Last synced {}", time.with_timezone(&Local).format("%H:%M"))),
62 ..text(OFFLINE_TEXT)
63 },
64 BannerKind::SignIn => text("Sign-in required. Sign in to Teams in the window that opened."),
65 BannerKind::LiveUnavailable => BannerText {
66 retry: true,
67 ..text("Live updates unavailable")
68 },
69 }
70}
71
72/// Shows a bad state only once it lasted `SHOW_AFTER`, and keeps a shown banner at least `MIN_VISIBLE`.
73#[derive(Debug, Default)]
74pub struct BannerTiming {
75 bad_since: Option<Instant>,
76 shown: Option<(BannerKind, Instant)>,
77}
78
79impl BannerTiming {
80 pub fn visible(&self) -> Option<BannerKind> {
81 self.shown.map(|(kind, _)| kind)
82 }
83
84 /// Returns when to check again, if the visible banner may change without a new state.
85 pub fn update(&mut self, wanted: Option<BannerKind>, now: Instant) -> Option<Duration> {
86 match wanted {
87 Some(kind) => {
88 let bad_since = *self.bad_since.get_or_insert(now);
89 if let Some((shown_kind, _)) = self.shown.as_mut() {
90 *shown_kind = kind;
91 return None;
92 }
93 let waited = now.duration_since(bad_since);
94 if waited >= SHOW_AFTER {
95 self.shown = Some((kind, now));
96 return None;
97 }
98 Some(SHOW_AFTER - waited)
99 }
100 None => {
101 self.bad_since = None;
102 let (_, shown_at) = self.shown?;
103 let visible_for = now.duration_since(shown_at);
104 if visible_for >= MIN_VISIBLE {
105 self.shown = None;
106 return None;
107 }
108 Some(MIN_VISIBLE - visible_for)
109 }
110 }
111 }
112}
113
114impl AppState {
115 pub fn refresh_connection_banner(&mut self, cx: &mut Context<Self>) {
116 let wanted = if self.mode.demo {
117 let offline = std::env::var_os(DEMO_OFFLINE_VARIABLE).is_some();
118 if offline {
119 self.last_sync
120 .get_or_insert_with(|| Utc::now() - DEMO_LAST_SYNC_AGO);
121 }
122 offline.then_some(BannerKind::Offline)
123 } else {
124 banner_kind(&self.connection, self.live)
125 };
126 let before = self.connection_banner.visible();
127 let recheck = self.connection_banner.update(wanted, Instant::now());
128 if let Some(wait) = recheck {
129 cx.spawn(async move |this, cx| {
130 cx.background_executor().timer(wait).await;
131 this.update(cx, |state, cx| state.refresh_connection_banner(cx))
132 .ok();
133 })
134 .detach();
135 }
136 if self.connection_banner.visible() != before {
137 cx.emit(crate::app_state::AppEvent::Status);
138 cx.notify();
139 }
140 }
141
142 pub fn connection_banner_text(&self) -> Option<BannerText> {
143 self.connection_banner
144 .visible()
145 .map(|kind| banner_text(kind, self.last_sync))
146 }
147
148 pub fn retry_live(&mut self) {
149 if let Some(retry) = &self.live_retry {
150 retry.notify_one();
151 }
152 }
153}
154
155#[cfg(test)]
156mod tests {
157 use std::time::{Duration, Instant};
158
159 use chrono::Utc;
160
161 use super::{BannerKind, BannerTiming, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
162 use crate::backend::{ConnectionState, LiveState};
163
164 #[test]
165 fn a_short_bad_state_never_shows() {
166 let mut timing = BannerTiming::default();
167 let start = Instant::now();
168 assert_eq!(
169 timing.update(Some(BannerKind::Reconnecting), start),
170 Some(SHOW_AFTER)
171 );
172 assert_eq!(timing.update(None, start + Duration::from_secs(2)), None);
173 assert_eq!(timing.visible(), None);
174 }
175
176 #[test]
177 fn a_lasting_bad_state_shows_after_the_delay() {
178 let mut timing = BannerTiming::default();
179 let start = Instant::now();
180 timing.update(Some(BannerKind::Reconnecting), start);
181 let wait = timing.update(Some(BannerKind::Offline), start + Duration::from_secs(1));
182 assert_eq!(wait, Some(SHOW_AFTER - Duration::from_secs(1)));
183 assert_eq!(
184 timing.update(Some(BannerKind::Offline), start + SHOW_AFTER),
185 None
186 );
187 assert_eq!(timing.visible(), Some(BannerKind::Offline));
188 }
189
190 #[test]
191 fn a_shown_banner_stays_for_the_minimum_then_goes() {
192 let mut timing = BannerTiming::default();
193 let start = Instant::now();
194 timing.update(Some(BannerKind::Offline), start);
195 let shown_at = start + SHOW_AFTER;
196 timing.update(Some(BannerKind::Offline), shown_at);
197 let back = shown_at + Duration::from_secs(1);
198 assert_eq!(
199 timing.update(None, back),
200 Some(MIN_VISIBLE - Duration::from_secs(1))
201 );
202 assert_eq!(timing.visible(), Some(BannerKind::Offline));
203 assert_eq!(timing.update(None, shown_at + MIN_VISIBLE), None);
204 assert_eq!(timing.visible(), None);
205 }
206
207 #[test]
208 fn a_new_bad_state_while_shown_changes_the_text_at_once() {
209 let mut timing = BannerTiming::default();
210 let start = Instant::now();
211 timing.update(Some(BannerKind::Offline), start);
212 timing.update(Some(BannerKind::Offline), start + SHOW_AFTER);
213 timing.update(None, start + SHOW_AFTER);
214 timing.update(Some(BannerKind::Reconnecting), start + SHOW_AFTER);
215 assert_eq!(timing.visible(), Some(BannerKind::Reconnecting));
216 }
217
218 #[test]
219 fn live_and_missed_messages_need_no_banner() {
220 let online = ConnectionState::Online;
221 assert_eq!(banner_kind(&online, LiveState::Live), None);
222 assert_eq!(banner_kind(&online, LiveState::MessageLoss), None);
223 assert_eq!(
224 banner_kind(&online, LiveState::Failed),
225 Some(BannerKind::LiveUnavailable)
226 );
227 assert_eq!(
228 banner_kind(&ConnectionState::LoginRequired, LiveState::Live),
229 Some(BannerKind::SignIn)
230 );
231 assert_eq!(
232 banner_kind(&ConnectionState::Failed("x".into()), LiveState::Off),
233 Some(BannerKind::Offline)
234 );
235 }
236
237 #[test]
238 fn the_offline_banner_names_the_last_sync() {
239 let text = banner_text(BannerKind::Offline, Some(Utc::now()));
240 assert!(text.detail.unwrap().starts_with("Last synced "));
241 assert!(banner_text(BannerKind::Offline, None).detail.is_none());
242 assert!(banner_text(BannerKind::LiveUnavailable, None).retry);
243 }
244}
crates/app-state/src/lib.rs +1 −0
@@ -11,6 +11,7 @@ pub mod card_refresh;
11 11 pub mod card_state;
12 12 pub mod chat_actions;
13 13 pub mod chat_members;
14 pub mod connection_banner;
14 15 pub mod data;
15 16 pub mod demo;
16 17 pub mod demo_meetings;
@@ -11,6 +11,7 @@ pub mod card_refresh;
11pub mod card_state;
11pub mod card_state;
12pub mod chat_actions;
12pub mod chat_actions;
13pub mod chat_members;
13pub mod chat_members;
14pub mod connection_banner;
14pub mod data;
15pub mod data;
15pub mod demo;
16pub mod demo;
16pub mod demo_meetings;
17pub mod demo_meetings;
crates/app/src/layout_guard.rs +0 −1
@@ -193,7 +193,6 @@ mod frames {
193 193 "shell/islands/rail",
194 194 "shell/islands/sidebar",
195 195 "shell/islands/main",
196 "shell/status-bar",
197 196 ];
198 197 const CALL_GUARDED: &[&str] = &[
199 198 "shell/islands/main/call-header",
@@ -193,7 +193,6 @@ mod frames {
193 "shell/islands/rail",
193 "shell/islands/rail",
194 "shell/islands/sidebar",
194 "shell/islands/sidebar",
195 "shell/islands/main",
195 "shell/islands/main",
196 "shell/status-bar",
197 ];
196 ];
198 const CALL_GUARDED: &[&str] = &[
197 const CALL_GUARDED: &[&str] = &[
199 "shell/islands/main/call-header",
198 "shell/islands/main/call-header",
crates/app/src/views/connection_banner.rs added +64 −0
@@ -0,0 +1,64 @@
1 use gpui_kit::assets::IconName;
2 use gpui_kit::component::h_flex;
3 use gpui_kit::prelude::FluentBuilder as _;
4 use gpui_kit::*;
5
6 use super::widgets::icon;
7 use crate::connection_banner::BannerText;
8 use crate::theme;
9 use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH};
10
11 const BANNER_HEIGHT: f32 = 32.;
12 const BANNER_TEXT_SIZE: f32 = 12.;
13 const BANNER_ICON_SIZE: f32 = 14.;
14
15 pub fn render_connection_banner(
16 banner: BannerText,
17 on_retry: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
18 ) -> impl IntoElement {
19 h_flex()
20 .debug_selector(|| "shell/connection-banner".into())
21 .flex_none()
22 .h(px(BANNER_HEIGHT))
23 .ml(px(RAIL_WIDTH))
24 .mr(px(ISLAND_GAP))
25 .mb(px(ISLAND_GAP))
26 .px(px(12.))
27 .gap(px(8.))
28 .items_center()
29 .rounded(px(8.))
30 .border_1()
31 .border_color(theme::amber().opacity(0.45))
32 .bg(theme::amber().opacity(0.14))
33 .text_size(px(BANNER_TEXT_SIZE))
34 .text_color(theme::text())
35 .child(icon(
36 IconName::TriangleAlert,
37 BANNER_ICON_SIZE,
38 theme::amber(),
39 ))
40 .child(div().min_w_0().truncate().child(banner.text))
41 .children(banner.detail.map(|detail| {
42 div()
43 .flex_none()
44 .text_color(theme::text_muted())
45 .child(detail)
46 }))
47 .when(banner.retry, |row| {
48 row.child(
49 div()
50 .id("connection-banner-retry")
51 .flex_none()
52 .ml_auto()
53 .px(px(8.))
54 .py(px(2.))
55 .rounded(px(4.))
56 .cursor_pointer()
57 .font_weight(FontWeight::SEMIBOLD)
58 .text_color(theme::accent_text())
59 .hover(|button| button.bg(theme::row_hover()))
60 .child("Retry")
61 .on_click(on_retry),
62 )
63 })
64 }
@@ -0,0 +1,64 @@
1use gpui_kit::assets::IconName;
2use gpui_kit::component::h_flex;
3use gpui_kit::prelude::FluentBuilder as _;
4use gpui_kit::*;
5
6use super::widgets::icon;
7use crate::connection_banner::BannerText;
8use crate::theme;
9use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH};
10
11const BANNER_HEIGHT: f32 = 32.;
12const BANNER_TEXT_SIZE: f32 = 12.;
13const BANNER_ICON_SIZE: f32 = 14.;
14
15pub fn render_connection_banner(
16 banner: BannerText,
17 on_retry: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
18) -> impl IntoElement {
19 h_flex()
20 .debug_selector(|| "shell/connection-banner".into())
21 .flex_none()
22 .h(px(BANNER_HEIGHT))
23 .ml(px(RAIL_WIDTH))
24 .mr(px(ISLAND_GAP))
25 .mb(px(ISLAND_GAP))
26 .px(px(12.))
27 .gap(px(8.))
28 .items_center()
29 .rounded(px(8.))
30 .border_1()
31 .border_color(theme::amber().opacity(0.45))
32 .bg(theme::amber().opacity(0.14))
33 .text_size(px(BANNER_TEXT_SIZE))
34 .text_color(theme::text())
35 .child(icon(
36 IconName::TriangleAlert,
37 BANNER_ICON_SIZE,
38 theme::amber(),
39 ))
40 .child(div().min_w_0().truncate().child(banner.text))
41 .children(banner.detail.map(|detail| {
42 div()
43 .flex_none()
44 .text_color(theme::text_muted())
45 .child(detail)
46 }))
47 .when(banner.retry, |row| {
48 row.child(
49 div()
50 .id("connection-banner-retry")
51 .flex_none()
52 .ml_auto()
53 .px(px(8.))
54 .py(px(2.))
55 .rounded(px(4.))
56 .cursor_pointer()
57 .font_weight(FontWeight::SEMIBOLD)
58 .text_color(theme::accent_text())
59 .hover(|button| button.bg(theme::row_hover()))
60 .child("Retry")
61 .on_click(on_retry),
62 )
63 })
64}
crates/app/src/views/mod.rs +2 −1
@@ -34,6 +34,7 @@ pub mod card_table;
34 34 pub mod card_widgets;
35 35 pub mod chat_members;
36 36 pub mod composer;
37 pub mod connection_banner;
37 38 pub mod conversation;
38 39 pub mod dialog_overlay;
39 40 pub mod emoji_popup;
@@ -48,6 +49,7 @@ pub mod link_preview;
48 49 pub mod message_actions;
49 50 pub mod message_row;
50 51 pub mod new_chat;
52 pub mod notice_toast;
51 53 pub mod new_meeting_dialog;
52 54 pub mod pin_banner;
53 55 pub mod post_card;
@@ -68,7 +70,6 @@ pub mod shell;
68 70 pub mod shortcuts;
69 71 pub mod shortcuts_dialog;
70 72 pub mod sidebar;
71 pub mod status_bar;
72 73 pub mod status_menu;
73 74 pub mod status_message_dialog;
74 75 pub mod switcher;
@@ -34,6 +34,7 @@ pub mod card_table;
34pub mod card_widgets;
34pub mod card_widgets;
35pub mod chat_members;
35pub mod chat_members;
36pub mod composer;
36pub mod composer;
37pub mod connection_banner;
37pub mod conversation;
38pub mod conversation;
38pub mod dialog_overlay;
39pub mod dialog_overlay;
39pub mod emoji_popup;
40pub mod emoji_popup;
@@ -48,6 +49,7 @@ pub mod link_preview;
48pub mod message_actions;
49pub mod message_actions;
49pub mod message_row;
50pub mod message_row;
50pub mod new_chat;
51pub mod new_chat;
52pub mod notice_toast;
51pub mod new_meeting_dialog;
53pub mod new_meeting_dialog;
52pub mod pin_banner;
54pub mod pin_banner;
53pub mod post_card;
55pub mod post_card;
@@ -68,7 +70,6 @@ pub mod shell;
68pub mod shortcuts;
70pub mod shortcuts;
69pub mod shortcuts_dialog;
71pub mod shortcuts_dialog;
70pub mod sidebar;
72pub mod sidebar;
71pub mod status_bar;
72pub mod status_menu;
73pub mod status_menu;
73pub mod status_message_dialog;
74pub mod status_message_dialog;
74pub mod switcher;
75pub mod switcher;
crates/app/src/views/notice_toast.rs added +91 −0
@@ -0,0 +1,91 @@
1 use gpui_kit::component::WindowExt as _;
2 use gpui_kit::component::button::{Button, ButtonVariants as _};
3 use gpui_kit::component::notification::Notification;
4 use gpui_kit::*;
5
6 use crate::app_state::AppState;
7 use crate::notice::Notice;
8
9 struct NoticeToast;
10 struct UpdateFailedToast;
11
12 /// Mirrors `AppState::notice` as a toast bottom right; the state keeps the 6 s lifetime.
13 #[derive(Default)]
14 pub struct NoticeToasts {
15 shown: Option<u64>,
16 update_failure: Option<String>,
17 }
18
19 fn toast_placement() -> Anchor {
20 Anchor::BottomRight
21 }
22
23 impl NoticeToasts {
24 pub fn sync(
25 &mut self,
26 app: &Entity<AppState>,
27 notice: Option<&Notice>,
28 window: &mut Window,
29 cx: &mut App,
30 ) {
31 let current = notice.map(|notice| notice.id);
32 if current == self.shown {
33 return;
34 }
35 if let Some(previous) = self.shown.take() {
36 window.defer(cx, move |window, cx| {
37 window.remove_notification1::<NoticeToast>(previous, cx)
38 });
39 }
40 let Some(notice) = notice else {
41 return;
42 };
43 self.shown = Some(notice.id);
44 let mut toast = Notification::new()
45 .id1::<NoticeToast>(notice.id)
46 .placement(toast_placement())
47 .message(notice.text.clone())
48 .autohide(false);
49 if let Some(action) = notice.action.as_ref() {
50 let label = SharedString::from(action.label.clone());
51 let app = app.clone();
52 toast = toast.action(move |_, _, _| {
53 let app = app.clone();
54 Button::new("notice-toast-action")
55 .primary()
56 .label(label.clone())
57 .on_click(move |_, _, cx| {
58 app.update(cx, |state, cx| state.run_notice_action(cx))
59 })
60 });
61 }
62 let dismiss = app.clone();
63 let notice_id = notice.id;
64 toast = toast.on_close(move |_, cx| {
65 dismiss.update(cx, |state, cx| {
66 if state
67 .notice
68 .as_ref()
69 .is_some_and(|notice| notice.id == notice_id)
70 {
71 state.dismiss_notice(cx);
72 }
73 })
74 });
75 window.defer(cx, move |window, cx| window.push_notification(toast, cx));
76 }
77
78 pub fn update_failed(&mut self, message: Option<&str>, window: &mut Window, cx: &mut App) {
79 if message == self.update_failure.as_deref() {
80 return;
81 }
82 self.update_failure = message.map(str::to_owned);
83 let Some(message) = message else {
84 return;
85 };
86 let toast = Notification::error(format!("Update failed: {message}"))
87 .id::<UpdateFailedToast>()
88 .placement(toast_placement());
89 window.defer(cx, move |window, cx| window.push_notification(toast, cx));
90 }
91 }
@@ -0,0 +1,91 @@
1use gpui_kit::component::WindowExt as _;
2use gpui_kit::component::button::{Button, ButtonVariants as _};
3use gpui_kit::component::notification::Notification;
4use gpui_kit::*;
5
6use crate::app_state::AppState;
7use crate::notice::Notice;
8
9struct NoticeToast;
10struct UpdateFailedToast;
11
12/// Mirrors `AppState::notice` as a toast bottom right; the state keeps the 6 s lifetime.
13#[derive(Default)]
14pub struct NoticeToasts {
15 shown: Option<u64>,
16 update_failure: Option<String>,
17}
18
19fn toast_placement() -> Anchor {
20 Anchor::BottomRight
21}
22
23impl NoticeToasts {
24 pub fn sync(
25 &mut self,
26 app: &Entity<AppState>,
27 notice: Option<&Notice>,
28 window: &mut Window,
29 cx: &mut App,
30 ) {
31 let current = notice.map(|notice| notice.id);
32 if current == self.shown {
33 return;
34 }
35 if let Some(previous) = self.shown.take() {
36 window.defer(cx, move |window, cx| {
37 window.remove_notification1::<NoticeToast>(previous, cx)
38 });
39 }
40 let Some(notice) = notice else {
41 return;
42 };
43 self.shown = Some(notice.id);
44 let mut toast = Notification::new()
45 .id1::<NoticeToast>(notice.id)
46 .placement(toast_placement())
47 .message(notice.text.clone())
48 .autohide(false);
49 if let Some(action) = notice.action.as_ref() {
50 let label = SharedString::from(action.label.clone());
51 let app = app.clone();
52 toast = toast.action(move |_, _, _| {
53 let app = app.clone();
54 Button::new("notice-toast-action")
55 .primary()
56 .label(label.clone())
57 .on_click(move |_, _, cx| {
58 app.update(cx, |state, cx| state.run_notice_action(cx))
59 })
60 });
61 }
62 let dismiss = app.clone();
63 let notice_id = notice.id;
64 toast = toast.on_close(move |_, cx| {
65 dismiss.update(cx, |state, cx| {
66 if state
67 .notice
68 .as_ref()
69 .is_some_and(|notice| notice.id == notice_id)
70 {
71 state.dismiss_notice(cx);
72 }
73 })
74 });
75 window.defer(cx, move |window, cx| window.push_notification(toast, cx));
76 }
77
78 pub fn update_failed(&mut self, message: Option<&str>, window: &mut Window, cx: &mut App) {
79 if message == self.update_failure.as_deref() {
80 return;
81 }
82 self.update_failure = message.map(str::to_owned);
83 let Some(message) = message else {
84 return;
85 };
86 let toast = Notification::error(format!("Update failed: {message}"))
87 .id::<UpdateFailedToast>()
88 .placement(toast_placement());
89 window.defer(cx, move |window, cx| window.push_notification(toast, cx));
90 }
91}
crates/app/src/views/shell.rs +35 −13
@@ -29,11 +29,12 @@ use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
29 29 use super::sidebar::SidebarView;
30 30 use app_ui_kit::render::hooks::RenderHooks;
31 31 use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
32 use super::status_bar::render_status_bar;
32 use super::connection_banner::render_connection_banner;
33 use super::notice_toast::NoticeToasts;
33 34 use super::status_menu::own_status_button;
34 35 use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
35 36 use super::switcher::{Switcher, SwitcherEvent, candidates_from};
36 use super::title_bar::render_title_bar;
37 use super::title_bar::{mode_label, render_title_bar, update_button};
37 38 use crate::activity::ActivityCenter;
38 39 use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
39 40 use crate::app_state::{AppEvent, AppState, Selection, selection_for};
@@ -105,6 +106,8 @@ fn jump_to_quoted(message_id: String, cx: &mut App) {
105 106 });
106 107 }
107 108
109 const DEMO_UPDATE_VARIABLE: &str = "TEAMS_DEMO_UPDATE";
110
108 111 pub struct AppShell {
109 112 state: Entity<AppState>,
110 113 rail: Entity<RailView>,
@@ -127,6 +130,7 @@ pub struct AppShell {
127 130 window_was_fullscreen: bool,
128 131 open_target: Option<OpenTarget>,
129 132 update: UpdateStatus,
133 toasts: NoticeToasts,
130 134 user_input: Arc<UserInput>,
131 135 _subscription: Subscription,
132 136 call_mini: Entity<CallMiniView>,
@@ -310,6 +314,7 @@ impl AppShell {
310 314 window_was_fullscreen: false,
311 315 open_target,
312 316 update: UpdateStatus::UpToDate,
317 toasts: NoticeToasts::default(),
313 318 user_input,
314 319 _subscription: subscription,
315 320 call_mini,
@@ -321,6 +326,12 @@ impl AppShell {
321 326 _activation_observation: activation_observation,
322 327 };
323 328 shell.apply_open_target(cx);
329 shell
330 .state
331 .update(cx, |state, cx| state.refresh_connection_banner(cx));
332 if shell.state.read(cx).mode.demo && std::env::var_os(DEMO_UPDATE_VARIABLE).is_some() {
333 shell.update = UpdateStatus::Ready;
334 }
324 335 let Startup {
325 336 switcher_query,
326 337 composer_text,
@@ -829,6 +840,13 @@ impl Render for AppShell {
829 840 let chat_thread = self.state.read(cx).call_chat_thread();
830 841 self.sync_call_chat(chat_thread, window, cx);
831 842 self.sync_prejoin(window, cx);
843 let notice = self.state.read(cx).notice.clone();
844 self.toasts.sync(&self.state, notice.as_ref(), window, cx);
845 let update_failure = match &self.update {
846 UpdateStatus::Failed(message) => Some(message.clone()),
847 _ => None,
848 };
849 self.toasts.update_failed(update_failure.as_deref(), window, cx);
832 850 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
833 851 let state = self.state.read(cx);
834 852 let call_fullscreen = state.call_fullscreen();
@@ -858,16 +876,20 @@ impl Render for AppShell {
858 876 .is_some_and(|call| !call.viewing)
859 877 .then(|| self.call_mini.clone());
860 878 let stage_overlay = render_stage_overlay(&self.state, state);
861 let status = render_status_bar(
862 state,
863 &self.update,
864 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
865 cx.listener(|this, _, _, cx| {
866 this.state
867 .update(cx, |state, cx| state.run_notice_action(cx))
868 }),
869 );
879 let banner = state.connection_banner_text().map(|banner| {
880 render_connection_banner(
881 banner,
882 cx.listener(|this, _, _, cx| {
883 this.state.update(cx, |state, _| state.retry_live())
884 }),
885 )
886 });
870 887 let title_bar = render_title_bar(
888 mode_label(state.mode),
889 update_button(
890 &self.update,
891 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
892 ),
871 893 own_status_button(&self.state, state),
872 894 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
873 895 );
@@ -1015,8 +1037,8 @@ impl Render for AppShell {
1015 1037 .debug_selector(|| "shell".into())
1016 1038 .size_full()
1017 1039 .child(title_bar)
1018 .child(self.islands(call_view, show_sidebar))
1019 .child(status),
1040 .children(banner)
1041 .child(self.islands(call_view, show_sidebar)),
1020 1042 )
1021 1043 .children(call_mini)
1022 1044 .children(call_overlay)
@@ -29,11 +29,12 @@ use super::shortcuts_dialog::{ShortcutsDialog, ShortcutsDialogEvent};
29use super::sidebar::SidebarView;
29use super::sidebar::SidebarView;
30use app_ui_kit::render::hooks::RenderHooks;
30use app_ui_kit::render::hooks::RenderHooks;
31use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
31use app_ui_kit::layout::{ISLAND_GAP, RAIL_WIDTH, SIDEBAR_WIDTH};
32use super::status_bar::render_status_bar;
32use super::connection_banner::render_connection_banner;
33use super::notice_toast::NoticeToasts;
33use super::status_menu::own_status_button;
34use super::status_menu::own_status_button;
34use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
35use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
35use super::switcher::{Switcher, SwitcherEvent, candidates_from};
36use super::switcher::{Switcher, SwitcherEvent, candidates_from};
36use super::title_bar::render_title_bar;
37use super::title_bar::{mode_label, render_title_bar, update_button};
37use crate::activity::ActivityCenter;
38use crate::activity::ActivityCenter;
38use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
39use crate::agents::{AgentRunsEvent, StartDialog, StartDialogEvent, StartRequest};
39use crate::app_state::{AppEvent, AppState, Selection, selection_for};
40use crate::app_state::{AppEvent, AppState, Selection, selection_for};
@@ -105,6 +106,8 @@ fn jump_to_quoted(message_id: String, cx: &mut App) {
105 });
106 });
106}
107}
107
108
109const DEMO_UPDATE_VARIABLE: &str = "TEAMS_DEMO_UPDATE";
110
108pub struct AppShell {
111pub struct AppShell {
109 state: Entity<AppState>,
112 state: Entity<AppState>,
110 rail: Entity<RailView>,
113 rail: Entity<RailView>,
@@ -127,6 +130,7 @@ pub struct AppShell {
127 window_was_fullscreen: bool,
130 window_was_fullscreen: bool,
128 open_target: Option<OpenTarget>,
131 open_target: Option<OpenTarget>,
129 update: UpdateStatus,
132 update: UpdateStatus,
133 toasts: NoticeToasts,
130 user_input: Arc<UserInput>,
134 user_input: Arc<UserInput>,
131 _subscription: Subscription,
135 _subscription: Subscription,
132 call_mini: Entity<CallMiniView>,
136 call_mini: Entity<CallMiniView>,
@@ -310,6 +314,7 @@ impl AppShell {
310 window_was_fullscreen: false,
314 window_was_fullscreen: false,
311 open_target,
315 open_target,
312 update: UpdateStatus::UpToDate,
316 update: UpdateStatus::UpToDate,
317 toasts: NoticeToasts::default(),
313 user_input,
318 user_input,
314 _subscription: subscription,
319 _subscription: subscription,
315 call_mini,
320 call_mini,
@@ -321,6 +326,12 @@ impl AppShell {
321 _activation_observation: activation_observation,
326 _activation_observation: activation_observation,
322 };
327 };
323 shell.apply_open_target(cx);
328 shell.apply_open_target(cx);
329 shell
330 .state
331 .update(cx, |state, cx| state.refresh_connection_banner(cx));
332 if shell.state.read(cx).mode.demo && std::env::var_os(DEMO_UPDATE_VARIABLE).is_some() {
333 shell.update = UpdateStatus::Ready;
334 }
324 let Startup {
335 let Startup {
325 switcher_query,
336 switcher_query,
326 composer_text,
337 composer_text,
@@ -829,6 +840,13 @@ impl Render for AppShell {
829 let chat_thread = self.state.read(cx).call_chat_thread();
840 let chat_thread = self.state.read(cx).call_chat_thread();
830 self.sync_call_chat(chat_thread, window, cx);
841 self.sync_call_chat(chat_thread, window, cx);
831 self.sync_prejoin(window, cx);
842 self.sync_prejoin(window, cx);
843 let notice = self.state.read(cx).notice.clone();
844 self.toasts.sync(&self.state, notice.as_ref(), window, cx);
845 let update_failure = match &self.update {
846 UpdateStatus::Failed(message) => Some(message.clone()),
847 _ => None,
848 };
849 self.toasts.update_failed(update_failure.as_deref(), window, cx);
832 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
850 let chat_panel = self.call_chat.as_ref().map(|(_, view)| view.clone().into());
833 let state = self.state.read(cx);
851 let state = self.state.read(cx);
834 let call_fullscreen = state.call_fullscreen();
852 let call_fullscreen = state.call_fullscreen();
@@ -858,16 +876,20 @@ impl Render for AppShell {
858 .is_some_and(|call| !call.viewing)
876 .is_some_and(|call| !call.viewing)
859 .then(|| self.call_mini.clone());
877 .then(|| self.call_mini.clone());
860 let stage_overlay = render_stage_overlay(&self.state, state);
878 let stage_overlay = render_stage_overlay(&self.state, state);
861 let status = render_status_bar(
879 let banner = state.connection_banner_text().map(|banner| {
862 state,
880 render_connection_banner(
863 &self.update,
881 banner,
864 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
882 cx.listener(|this, _, _, cx| {
865 cx.listener(|this, _, _, cx| {
883 this.state.update(cx, |state, _| state.retry_live())
866 this.state
884 }),
867 .update(cx, |state, cx| state.run_notice_action(cx))
885 )
868 }),
886 });
869 );
870 let title_bar = render_title_bar(
887 let title_bar = render_title_bar(
888 mode_label(state.mode),
889 update_button(
890 &self.update,
891 cx.listener(|this, _, _, cx| this.restart_into_update(cx)),
892 ),
871 own_status_button(&self.state, state),
893 own_status_button(&self.state, state),
872 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
894 cx.listener(|this, _, window, cx| this.toggle_switcher("", window, cx)),
873 );
895 );
@@ -1015,8 +1037,8 @@ impl Render for AppShell {
1015 .debug_selector(|| "shell".into())
1037 .debug_selector(|| "shell".into())
1016 .size_full()
1038 .size_full()
1017 .child(title_bar)
1039 .child(title_bar)
1018 .child(self.islands(call_view, show_sidebar))
1040 .children(banner)
1019 .child(status),
1041 .child(self.islands(call_view, show_sidebar)),
1020 )
1042 )
1021 .children(call_mini)
1043 .children(call_mini)
1022 .children(call_overlay)
1044 .children(call_overlay)
crates/app/src/views/status_bar.rs deleted +0 −214
@@ -1,214 +0,0 @@
1 use chrono::{DateTime, Local, Utc};
2 use gpui_kit::component::{h_flex, tooltip::Tooltip};
3 use gpui_kit::*;
4
5 use crate::app_state::{AppState, Mode};
6 use crate::backend::{ConnectionState, LiveState};
7 use crate::format;
8 use crate::theme;
9 use crate::updater::{self, UpdateStatus};
10
11 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
12 pub enum Tone {
13 Good,
14 Warn,
15 Bad,
16 }
17
18 pub fn connection_text(connection: &ConnectionState, mode: Mode) -> (String, Tone) {
19 if mode.demo {
20 return ("Demo data".to_owned(), Tone::Warn);
21 }
22 match connection {
23 ConnectionState::Connecting => ("Connecting".to_owned(), Tone::Warn),
24 ConnectionState::Online => ("Connected".to_owned(), Tone::Good),
25 ConnectionState::NoBrowser => ("Browser not running".to_owned(), Tone::Bad),
26 ConnectionState::NoAppTab => ("Teams not loaded".to_owned(), Tone::Bad),
27 ConnectionState::LoginRequired => ("Sign-in required".to_owned(), Tone::Bad),
28 ConnectionState::Failed(message) => (format!("Error: {message}"), Tone::Bad),
29 }
30 }
31
32 pub fn live_text(live: LiveState) -> Option<(&'static str, Tone)> {
33 match live {
34 LiveState::Off => None,
35 LiveState::Connecting => Some(("Live: connecting", Tone::Warn)),
36 LiveState::Live => Some(("Live", Tone::Good)),
37 LiveState::Reconnecting => Some(("Live: reconnecting", Tone::Warn)),
38 LiveState::MessageLoss => Some(("Live: missed messages, syncing", Tone::Warn)),
39 LiveState::Failed => Some(("Live: unavailable", Tone::Bad)),
40 }
41 }
42
43 pub fn sync_text(last_sync: Option<DateTime<Utc>>) -> String {
44 match last_sync {
45 Some(time) => format!("Synced {}", time.with_timezone(&Local).format("%H:%M")),
46 None => "Not synced yet".to_owned(),
47 }
48 }
49
50 fn tone_color(tone: Tone) -> Hsla {
51 match tone {
52 Tone::Good => theme::green(),
53 Tone::Warn => theme::amber(),
54 Tone::Bad => theme::red(),
55 }
56 }
57
58 pub fn render_status_bar(
59 state: &AppState,
60 update: &UpdateStatus,
61 on_restart: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
62 on_notice_action: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
63 ) -> impl IntoElement {
64 let (connection, connection_tone) = connection_text(&state.connection, state.mode);
65 let item = |label: String, tone: Tone| {
66 h_flex()
67 .gap(px(6.))
68 .items_center()
69 .child(div().size(px(7.)).rounded_full().bg(tone_color(tone)))
70 .child(label)
71 };
72 let live = live_text(state.live);
73 let mut bar = h_flex()
74 .debug_selector(|| "shell/status-bar".into())
75 .w_full()
76 .h(px(24.))
77 .flex_none()
78 .px(px(12.))
79 .gap(px(14.))
80 .items_center()
81 .text_size(px(11.))
82 .bg(theme::background())
83 .text_color(theme::text_muted());
84 match live {
85 Some((label, tone)) if connection_tone == Tone::Good => {
86 bar = bar.child(item(label.to_owned(), tone))
87 }
88 _ => bar = bar.child(item(connection, connection_tone)),
89 }
90 bar = bar.child(div().child(sync_text(state.last_sync)));
91 if state.mode.read_only {
92 bar = bar.child(div().text_color(theme::amber()).child("Read-only"));
93 }
94 match update {
95 UpdateStatus::UpToDate => {}
96 UpdateStatus::Ready => {
97 bar = bar.child(
98 div()
99 .id("update-restart")
100 .px(px(8.))
101 .rounded(px(4.))
102 .bg(theme::accent())
103 .text_color(theme::on_accent())
104 .cursor_pointer()
105 .hover(|button| button.bg(theme::accent_text()))
106 .child("Update ready - Restart")
107 .on_click(on_restart),
108 )
109 }
110 UpdateStatus::Installing => {
111 bar = bar.child(
112 div()
113 .text_color(theme::accent_text())
114 .child("Restarting..."),
115 )
116 }
117 UpdateStatus::Failed(message) => {
118 bar = bar.child(
119 div()
120 .text_color(theme::red())
121 .child(format!("Update failed: {message}")),
122 )
123 }
124 }
125 if let Some(notice) = &state.notice {
126 bar = bar.child(
127 h_flex()
128 .min_w_0()
129 .gap(px(8.))
130 .items_center()
131 .text_color(theme::amber())
132 .child(div().min_w_0().truncate().child(notice.text.clone()))
133 .children(notice.action.as_ref().map(|action| {
134 div()
135 .id("notice-action")
136 .flex_none()
137 .px(px(6.))
138 .rounded(px(4.))
139 .cursor_pointer()
140 .font_weight(FontWeight::SEMIBOLD)
141 .text_color(theme::accent_text())
142 .hover(|button| button.bg(theme::row_hover()))
143 .child(action.label.clone())
144 .on_click(on_notice_action)
145 })),
146 );
147 }
148 let full_version = updater::running_version();
149 bar.child(
150 div()
151 .id("build-version")
152 .ml_auto()
153 .tooltip(move |window, cx| Tooltip::new(full_version).build(window, cx))
154 .child(format::short_version(
155 full_version,
156 env!("CARGO_PKG_VERSION"),
157 )),
158 )
159 }
160
161 #[cfg(test)]
162 mod tests {
163 use super::{Tone, connection_text, live_text, sync_text};
164 use crate::app_state::Mode;
165 use crate::backend::{ConnectionState, LiveState};
166 use chrono::Utc;
167
168 #[test]
169 fn states_map_to_text_and_tone() {
170 let mode = Mode::default();
171 assert_eq!(
172 connection_text(&ConnectionState::Online, mode).1,
173 Tone::Good
174 );
175 assert_eq!(
176 connection_text(&ConnectionState::LoginRequired, mode).0,
177 "Sign-in required"
178 );
179 assert_eq!(
180 connection_text(&ConnectionState::Connecting, mode).1,
181 Tone::Warn
182 );
183 assert!(
184 connection_text(&ConnectionState::Failed("x".into()), mode)
185 .0
186 .contains('x')
187 );
188 }
189
190 #[test]
191 fn demo_mode_overrides_the_connection() {
192 let mode = Mode {
193 demo: true,
194 read_only: false,
195 demo_sync: None,
196 };
197 assert_eq!(
198 connection_text(&ConnectionState::NoBrowser, mode).0,
199 "Demo data"
200 );
201 }
202
203 #[test]
204 fn live_off_has_no_label() {
205 assert_eq!(live_text(LiveState::Off), None);
206 assert_eq!(live_text(LiveState::Live).unwrap().1, Tone::Good);
207 }
208
209 #[test]
210 fn sync_text_without_sync() {
211 assert_eq!(sync_text(None), "Not synced yet");
212 assert!(sync_text(Some(Utc::now())).starts_with("Synced "));
213 }
214 }
@@ -1,214 +0,0 @@
1use chrono::{DateTime, Local, Utc};
2use gpui_kit::component::{h_flex, tooltip::Tooltip};
3use gpui_kit::*;
4
5use crate::app_state::{AppState, Mode};
6use crate::backend::{ConnectionState, LiveState};
7use crate::format;
8use crate::theme;
9use crate::updater::{self, UpdateStatus};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub enum Tone {
13 Good,
14 Warn,
15 Bad,
16}
17
18pub fn connection_text(connection: &ConnectionState, mode: Mode) -> (String, Tone) {
19 if mode.demo {
20 return ("Demo data".to_owned(), Tone::Warn);
21 }
22 match connection {
23 ConnectionState::Connecting => ("Connecting".to_owned(), Tone::Warn),
24 ConnectionState::Online => ("Connected".to_owned(), Tone::Good),
25 ConnectionState::NoBrowser => ("Browser not running".to_owned(), Tone::Bad),
26 ConnectionState::NoAppTab => ("Teams not loaded".to_owned(), Tone::Bad),
27 ConnectionState::LoginRequired => ("Sign-in required".to_owned(), Tone::Bad),
28 ConnectionState::Failed(message) => (format!("Error: {message}"), Tone::Bad),
29 }
30}
31
32pub fn live_text(live: LiveState) -> Option<(&'static str, Tone)> {
33 match live {
34 LiveState::Off => None,
35 LiveState::Connecting => Some(("Live: connecting", Tone::Warn)),
36 LiveState::Live => Some(("Live", Tone::Good)),
37 LiveState::Reconnecting => Some(("Live: reconnecting", Tone::Warn)),
38 LiveState::MessageLoss => Some(("Live: missed messages, syncing", Tone::Warn)),
39 LiveState::Failed => Some(("Live: unavailable", Tone::Bad)),
40 }
41}
42
43pub fn sync_text(last_sync: Option<DateTime<Utc>>) -> String {
44 match last_sync {
45 Some(time) => format!("Synced {}", time.with_timezone(&Local).format("%H:%M")),
46 None => "Not synced yet".to_owned(),
47 }
48}
49
50fn tone_color(tone: Tone) -> Hsla {
51 match tone {
52 Tone::Good => theme::green(),
53 Tone::Warn => theme::amber(),
54 Tone::Bad => theme::red(),
55 }
56}
57
58pub fn render_status_bar(
59 state: &AppState,
60 update: &UpdateStatus,
61 on_restart: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
62 on_notice_action: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
63) -> impl IntoElement {
64 let (connection, connection_tone) = connection_text(&state.connection, state.mode);
65 let item = |label: String, tone: Tone| {
66 h_flex()
67 .gap(px(6.))
68 .items_center()
69 .child(div().size(px(7.)).rounded_full().bg(tone_color(tone)))
70 .child(label)
71 };
72 let live = live_text(state.live);
73 let mut bar = h_flex()
74 .debug_selector(|| "shell/status-bar".into())
75 .w_full()
76 .h(px(24.))
77 .flex_none()
78 .px(px(12.))
79 .gap(px(14.))
80 .items_center()
81 .text_size(px(11.))
82 .bg(theme::background())
83 .text_color(theme::text_muted());
84 match live {
85 Some((label, tone)) if connection_tone == Tone::Good => {
86 bar = bar.child(item(label.to_owned(), tone))
87 }
88 _ => bar = bar.child(item(connection, connection_tone)),
89 }
90 bar = bar.child(div().child(sync_text(state.last_sync)));
91 if state.mode.read_only {
92 bar = bar.child(div().text_color(theme::amber()).child("Read-only"));
93 }
94 match update {
95 UpdateStatus::UpToDate => {}
96 UpdateStatus::Ready => {
97 bar = bar.child(
98 div()
99 .id("update-restart")
100 .px(px(8.))
101 .rounded(px(4.))
102 .bg(theme::accent())
103 .text_color(theme::on_accent())
104 .cursor_pointer()
105 .hover(|button| button.bg(theme::accent_text()))
106 .child("Update ready - Restart")
107 .on_click(on_restart),
108 )
109 }
110 UpdateStatus::Installing => {
111 bar = bar.child(
112 div()
113 .text_color(theme::accent_text())
114 .child("Restarting..."),
115 )
116 }
117 UpdateStatus::Failed(message) => {
118 bar = bar.child(
119 div()
120 .text_color(theme::red())
121 .child(format!("Update failed: {message}")),
122 )
123 }
124 }
125 if let Some(notice) = &state.notice {
126 bar = bar.child(
127 h_flex()
128 .min_w_0()
129 .gap(px(8.))
130 .items_center()
131 .text_color(theme::amber())
132 .child(div().min_w_0().truncate().child(notice.text.clone()))
133 .children(notice.action.as_ref().map(|action| {
134 div()
135 .id("notice-action")
136 .flex_none()
137 .px(px(6.))
138 .rounded(px(4.))
139 .cursor_pointer()
140 .font_weight(FontWeight::SEMIBOLD)
141 .text_color(theme::accent_text())
142 .hover(|button| button.bg(theme::row_hover()))
143 .child(action.label.clone())
144 .on_click(on_notice_action)
145 })),
146 );
147 }
148 let full_version = updater::running_version();
149 bar.child(
150 div()
151 .id("build-version")
152 .ml_auto()
153 .tooltip(move |window, cx| Tooltip::new(full_version).build(window, cx))
154 .child(format::short_version(
155 full_version,
156 env!("CARGO_PKG_VERSION"),
157 )),
158 )
159}
160
161#[cfg(test)]
162mod tests {
163 use super::{Tone, connection_text, live_text, sync_text};
164 use crate::app_state::Mode;
165 use crate::backend::{ConnectionState, LiveState};
166 use chrono::Utc;
167
168 #[test]
169 fn states_map_to_text_and_tone() {
170 let mode = Mode::default();
171 assert_eq!(
172 connection_text(&ConnectionState::Online, mode).1,
173 Tone::Good
174 );
175 assert_eq!(
176 connection_text(&ConnectionState::LoginRequired, mode).0,
177 "Sign-in required"
178 );
179 assert_eq!(
180 connection_text(&ConnectionState::Connecting, mode).1,
181 Tone::Warn
182 );
183 assert!(
184 connection_text(&ConnectionState::Failed("x".into()), mode)
185 .0
186 .contains('x')
187 );
188 }
189
190 #[test]
191 fn demo_mode_overrides_the_connection() {
192 let mode = Mode {
193 demo: true,
194 read_only: false,
195 demo_sync: None,
196 };
197 assert_eq!(
198 connection_text(&ConnectionState::NoBrowser, mode).0,
199 "Demo data"
200 );
201 }
202
203 #[test]
204 fn live_off_has_no_label() {
205 assert_eq!(live_text(LiveState::Off), None);
206 assert_eq!(live_text(LiveState::Live).unwrap().1, Tone::Good);
207 }
208
209 #[test]
210 fn sync_text_without_sync() {
211 assert_eq!(sync_text(None), "Not synced yet");
212 assert!(sync_text(Some(Utc::now())).starts_with("Synced "));
213 }
214}
crates/app/src/views/status_menu.rs +10 −0
@@ -83,6 +83,7 @@ pub fn own_status_button(app: &Entity<AppState>, state: &AppState) -> Option<Any
83 83 .flex_none()
84 84 .child(
85 85 Button::new("title-own-status")
86 .tooltip(version_tooltip())
86 87 .ghost()
87 88 .p_0()
88 89 .size(px(OWN_STATUS_BUTTON_SIZE))
@@ -105,6 +106,15 @@ pub fn own_status_button(app: &Entity<AppState>, state: &AppState) -> Option<Any
105 106 )
106 107 }
107 108
109 fn version_tooltip() -> String {
110 let build_id = crate::updater::running_version();
111 format!(
112 "{} {}\nBuild {build_id}",
113 app_base::APP_NAME,
114 crate::format::short_version(build_id, env!("CARGO_PKG_VERSION")),
115 )
116 }
117
108 118 fn status_icon(kind: PresenceKind) -> gpui_kit::component::Icon {
109 119 let (name, color) = match kind {
110 120 PresenceKind::Available => ("status_dot", theme::green()),
@@ -83,6 +83,7 @@ pub fn own_status_button(app: &Entity<AppState>, state: &AppState) -> Option<Any
83 .flex_none()
83 .flex_none()
84 .child(
84 .child(
85 Button::new("title-own-status")
85 Button::new("title-own-status")
86 .tooltip(version_tooltip())
86 .ghost()
87 .ghost()
87 .p_0()
88 .p_0()
88 .size(px(OWN_STATUS_BUTTON_SIZE))
89 .size(px(OWN_STATUS_BUTTON_SIZE))
@@ -105,6 +106,15 @@ pub fn own_status_button(app: &Entity<AppState>, state: &AppState) -> Option<Any
105 )
106 )
106}
107}
107
108
109fn version_tooltip() -> String {
110 let build_id = crate::updater::running_version();
111 format!(
112 "{} {}\nBuild {build_id}",
113 app_base::APP_NAME,
114 crate::format::short_version(build_id, env!("CARGO_PKG_VERSION")),
115 )
116}
117
108fn status_icon(kind: PresenceKind) -> gpui_kit::component::Icon {
118fn status_icon(kind: PresenceKind) -> gpui_kit::component::Icon {
109 let (name, color) = match kind {
119 let (name, color) = match kind {
110 PresenceKind::Available => ("status_dot", theme::green()),
120 PresenceKind::Available => ("status_dot", theme::green()),
crates/app/src/views/title_bar.rs +74 −0
@@ -2,10 +2,13 @@ use std::sync::{Arc, OnceLock};
2 2
3 3 use gpui_kit::assets::IconName;
4 4 use gpui_kit::component::{TitleBar, h_flex};
5 use gpui_kit::prelude::FluentBuilder as _;
5 6 use gpui_kit::*;
6 7
7 8 use super::widgets::icon;
9 use crate::app_state::Mode;
8 10 use crate::theme;
11 use crate::updater::UpdateStatus;
9 12
10 13 pub const TITLE_BAR_HEIGHT: f32 = 40.;
11 14 const SEARCH_WIDTH: f32 = 380.;
@@ -20,7 +23,76 @@ fn app_icon() -> Arc<Image> {
20 23 .clone()
21 24 }
22 25
26 fn mode_pill(label: &'static str) -> Div {
27 div()
28 .debug_selector(|| "shell/title-bar/mode-pill".into())
29 .flex_none()
30 .px(px(8.))
31 .h(px(18.))
32 .flex()
33 .items_center()
34 .rounded_full()
35 .border_1()
36 .border_color(theme::amber().opacity(0.5))
37 .bg(theme::amber().opacity(0.14))
38 .text_size(px(11.))
39 .font_weight(FontWeight::SEMIBOLD)
40 .text_color(theme::amber())
41 .child(label)
42 }
43
44 pub fn mode_label(mode: Mode) -> Option<&'static str> {
45 if mode.demo {
46 Some("Demo")
47 } else if mode.read_only {
48 Some("Read-only")
49 } else {
50 None
51 }
52 }
53
54 pub fn update_button(
55 update: &UpdateStatus,
56 on_restart: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
57 ) -> Option<AnyElement> {
58 let installing = match update {
59 UpdateStatus::Ready => false,
60 UpdateStatus::Installing => true,
61 UpdateStatus::UpToDate | UpdateStatus::Failed(_) => return None,
62 };
63 Some(
64 div()
65 .id("title-update-restart")
66 .debug_selector(|| "shell/title-bar/update".into())
67 .flex_none()
68 .h(px(24.))
69 .px(px(10.))
70 .flex()
71 .items_center()
72 .rounded(px(6.))
73 .bg(theme::accent())
74 .text_color(theme::on_accent())
75 .text_size(px(12.))
76 .font_weight(FontWeight::SEMIBOLD)
77 .when(!installing, |button| {
78 button
79 .cursor_pointer()
80 .hover(|button| button.bg(theme::accent_text()))
81 .on_click(on_restart)
82 })
83 .when(installing, |button| button.opacity(0.7))
84 .child(if installing {
85 "Restarting..."
86 } else {
87 "Restart to update"
88 })
89 .into_any_element(),
90 )
91 }
92
23 93 pub fn render_title_bar(
94 mode_label: Option<&'static str>,
95 update: Option<AnyElement>,
24 96 own: Option<AnyElement>,
25 97 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
26 98 ) -> impl IntoElement {
@@ -68,7 +140,9 @@ pub fn render_title_bar(
68 140 .text_color(theme::text())
69 141 .child(app_base::APP_NAME),
70 142 )
143 .children(mode_label.map(mode_pill))
71 144 .child(div().flex_1().flex().justify_center().child(search))
145 .children(update)
72 146 .children(own)
73 147 .child(div().w(px(4.))),
74 148 );
@@ -2,10 +2,13 @@ use std::sync::{Arc, OnceLock};
2
2
3use gpui_kit::assets::IconName;
3use gpui_kit::assets::IconName;
4use gpui_kit::component::{TitleBar, h_flex};
4use gpui_kit::component::{TitleBar, h_flex};
5use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6use gpui_kit::*;
6
7
7use super::widgets::icon;
8use super::widgets::icon;
9use crate::app_state::Mode;
8use crate::theme;
10use crate::theme;
11use crate::updater::UpdateStatus;
9
12
10pub const TITLE_BAR_HEIGHT: f32 = 40.;
13pub const TITLE_BAR_HEIGHT: f32 = 40.;
11const SEARCH_WIDTH: f32 = 380.;
14const SEARCH_WIDTH: f32 = 380.;
@@ -20,7 +23,76 @@ fn app_icon() -> Arc<Image> {
20 .clone()
23 .clone()
21}
24}
22
25
26fn mode_pill(label: &'static str) -> Div {
27 div()
28 .debug_selector(|| "shell/title-bar/mode-pill".into())
29 .flex_none()
30 .px(px(8.))
31 .h(px(18.))
32 .flex()
33 .items_center()
34 .rounded_full()
35 .border_1()
36 .border_color(theme::amber().opacity(0.5))
37 .bg(theme::amber().opacity(0.14))
38 .text_size(px(11.))
39 .font_weight(FontWeight::SEMIBOLD)
40 .text_color(theme::amber())
41 .child(label)
42}
43
44pub fn mode_label(mode: Mode) -> Option<&'static str> {
45 if mode.demo {
46 Some("Demo")
47 } else if mode.read_only {
48 Some("Read-only")
49 } else {
50 None
51 }
52}
53
54pub fn update_button(
55 update: &UpdateStatus,
56 on_restart: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
57) -> Option<AnyElement> {
58 let installing = match update {
59 UpdateStatus::Ready => false,
60 UpdateStatus::Installing => true,
61 UpdateStatus::UpToDate | UpdateStatus::Failed(_) => return None,
62 };
63 Some(
64 div()
65 .id("title-update-restart")
66 .debug_selector(|| "shell/title-bar/update".into())
67 .flex_none()
68 .h(px(24.))
69 .px(px(10.))
70 .flex()
71 .items_center()
72 .rounded(px(6.))
73 .bg(theme::accent())
74 .text_color(theme::on_accent())
75 .text_size(px(12.))
76 .font_weight(FontWeight::SEMIBOLD)
77 .when(!installing, |button| {
78 button
79 .cursor_pointer()
80 .hover(|button| button.bg(theme::accent_text()))
81 .on_click(on_restart)
82 })
83 .when(installing, |button| button.opacity(0.7))
84 .child(if installing {
85 "Restarting..."
86 } else {
87 "Restart to update"
88 })
89 .into_any_element(),
90 )
91}
92
23pub fn render_title_bar(
93pub fn render_title_bar(
94 mode_label: Option<&'static str>,
95 update: Option<AnyElement>,
24 own: Option<AnyElement>,
96 own: Option<AnyElement>,
25 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
97 on_search: impl Fn(&ClickEvent, &mut Window, &mut App) + 'static,
26) -> impl IntoElement {
98) -> impl IntoElement {
@@ -68,7 +140,9 @@ pub fn render_title_bar(
68 .text_color(theme::text())
140 .text_color(theme::text())
69 .child(app_base::APP_NAME),
141 .child(app_base::APP_NAME),
70 )
142 )
143 .children(mode_label.map(mode_pill))
71 .child(div().flex_1().flex().justify_center().child(search))
144 .child(div().flex_1().flex().justify_center().child(search))
145 .children(update)
72 .children(own)
146 .children(own)
73 .child(div().w(px(4.))),
147 .child(div().w(px(4.))),
74 );
148 );