BlueGit

ict rusty-teams

feat(app): start-up splash with a loading bar and what is loading

- App icon, endless accent bar and a status line (Starting, Signing in, Loading your chats, Opening <chat>)
- Hides once the sidebar and the open chat can show (at least 400 ms, gives up after 30 s unless sign-in is pending), content rises in
- Sign-in needed stops the bar and says where to sign in; first-start hint after 8 s
- No banner while the splash is up; "Connecting..." waits 15 s before it shows
- Deviation: our app icon instead of the Teams logo

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

metis Daniel Däschle · pushed by metis

Authored 2026-11-11 · 2 weeks ago

Hash
d3b234ef725bf6e8abff07f72c23a7aa46eb22bb
Parent
9e6a7e21
5 files changed +358 −6
crates/app-state/src/connection_banner.rs +22 −3
@@ -7,6 +7,7 @@ use crate::app_state::AppState;
7 7 use crate::backend::{ConnectionState, LiveState};
8 8
9 9 pub const SHOW_AFTER: Duration = Duration::from_secs(4);
10 pub const CONNECTING_SHOW_AFTER: Duration = Duration::from_secs(15);
10 11 pub const MIN_VISIBLE: Duration = Duration::from_secs(3);
11 12 const OFFLINE_TEXT: &str =
12 13 "Something went wrong while connecting to Teams. Reconnect to keep the conversation going.";
@@ -91,11 +92,12 @@ impl BannerTiming {
91 92 return None;
92 93 }
93 94 let waited = now.duration_since(bad_since);
94 if waited >= SHOW_AFTER {
95 let show_after = show_after(kind);
96 if waited >= show_after {
95 97 self.shown = Some((kind, now));
96 98 return None;
97 99 }
98 Some(SHOW_AFTER - waited)
100 Some(show_after - waited)
99 101 }
100 102 None => {
101 103 self.bad_since = None;
@@ -111,6 +113,13 @@ impl BannerTiming {
111 113 }
112 114 }
113 115
116 fn show_after(kind: BannerKind) -> Duration {
117 match kind {
118 BannerKind::Connecting => CONNECTING_SHOW_AFTER,
119 _ => SHOW_AFTER,
120 }
121 }
122
114 123 impl AppState {
115 124 pub fn refresh_connection_banner(&mut self, cx: &mut Context<Self>) {
116 125 let wanted = if self.mode.demo {
@@ -158,7 +167,7 @@ mod tests {
158 167
159 168 use chrono::Utc;
160 169
161 use super::{BannerKind, BannerTiming, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
170 use super::{BannerKind, BannerTiming, CONNECTING_SHOW_AFTER, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
162 171 use crate::backend::{ConnectionState, LiveState};
163 172
164 173 #[test]
@@ -173,6 +182,16 @@ mod tests {
173 182 assert_eq!(timing.visible(), None);
174 183 }
175 184
185 #[test]
186 fn connecting_waits_longer_than_a_lost_connection() {
187 let mut timing = BannerTiming::default();
188 let start = Instant::now();
189 timing.update(Some(BannerKind::Connecting), start);
190 assert!(timing.update(Some(BannerKind::Connecting), start + SHOW_AFTER).is_some());
191 assert_eq!(timing.update(Some(BannerKind::Connecting), start + CONNECTING_SHOW_AFTER), None);
192 assert_eq!(timing.visible(), Some(BannerKind::Connecting));
193 }
194
176 195 #[test]
177 196 fn a_lasting_bad_state_shows_after_the_delay() {
178 197 let mut timing = BannerTiming::default();
@@ -7,6 +7,7 @@ use crate::app_state::AppState;
7use crate::backend::{ConnectionState, LiveState};
7use crate::backend::{ConnectionState, LiveState};
8
8
9pub const SHOW_AFTER: Duration = Duration::from_secs(4);
9pub const SHOW_AFTER: Duration = Duration::from_secs(4);
10pub const CONNECTING_SHOW_AFTER: Duration = Duration::from_secs(15);
10pub const MIN_VISIBLE: Duration = Duration::from_secs(3);
11pub const MIN_VISIBLE: Duration = Duration::from_secs(3);
11const OFFLINE_TEXT: &str =
12const OFFLINE_TEXT: &str =
12 "Something went wrong while connecting to Teams. Reconnect to keep the conversation going.";
13 "Something went wrong while connecting to Teams. Reconnect to keep the conversation going.";
@@ -91,11 +92,12 @@ impl BannerTiming {
91 return None;
92 return None;
92 }
93 }
93 let waited = now.duration_since(bad_since);
94 let waited = now.duration_since(bad_since);
94 if waited >= SHOW_AFTER {
95 let show_after = show_after(kind);
96 if waited >= show_after {
95 self.shown = Some((kind, now));
97 self.shown = Some((kind, now));
96 return None;
98 return None;
97 }
99 }
98 Some(SHOW_AFTER - waited)
100 Some(show_after - waited)
99 }
101 }
100 None => {
102 None => {
101 self.bad_since = None;
103 self.bad_since = None;
@@ -111,6 +113,13 @@ impl BannerTiming {
111 }
113 }
112}
114}
113
115
116fn show_after(kind: BannerKind) -> Duration {
117 match kind {
118 BannerKind::Connecting => CONNECTING_SHOW_AFTER,
119 _ => SHOW_AFTER,
120 }
121}
122
114impl AppState {
123impl AppState {
115 pub fn refresh_connection_banner(&mut self, cx: &mut Context<Self>) {
124 pub fn refresh_connection_banner(&mut self, cx: &mut Context<Self>) {
116 let wanted = if self.mode.demo {
125 let wanted = if self.mode.demo {
@@ -158,7 +167,7 @@ mod tests {
158
167
159 use chrono::Utc;
168 use chrono::Utc;
160
169
161 use super::{BannerKind, BannerTiming, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
170 use super::{BannerKind, BannerTiming, CONNECTING_SHOW_AFTER, MIN_VISIBLE, SHOW_AFTER, banner_kind, banner_text};
162 use crate::backend::{ConnectionState, LiveState};
171 use crate::backend::{ConnectionState, LiveState};
163
172
164 #[test]
173 #[test]
@@ -173,6 +182,16 @@ mod tests {
173 assert_eq!(timing.visible(), None);
182 assert_eq!(timing.visible(), None);
174 }
183 }
175
184
185 #[test]
186 fn connecting_waits_longer_than_a_lost_connection() {
187 let mut timing = BannerTiming::default();
188 let start = Instant::now();
189 timing.update(Some(BannerKind::Connecting), start);
190 assert!(timing.update(Some(BannerKind::Connecting), start + SHOW_AFTER).is_some());
191 assert_eq!(timing.update(Some(BannerKind::Connecting), start + CONNECTING_SHOW_AFTER), None);
192 assert_eq!(timing.visible(), Some(BannerKind::Connecting));
193 }
194
176 #[test]
195 #[test]
177 fn a_lasting_bad_state_shows_after_the_delay() {
196 fn a_lasting_bad_state_shows_after_the_delay() {
178 let mut timing = BannerTiming::default();
197 let mut timing = BannerTiming::default();
crates/app/src/views/conversation.rs +5 −0
@@ -660,6 +660,11 @@ impl ConversationView {
660 660 }
661 661
662 662 #[cfg_attr(not(windows), allow(dead_code))]
663 pub fn opening_title(&self) -> Option<String> {
664 let loading = self.rows.borrow().iter().any(|row| matches!(row, Row::Skeleton(_)));
665 self.current.as_ref().filter(|_| loading).map(|current| current.title.clone())
666 }
667
663 668 pub fn send_in_flight(&self) -> bool {
664 669 self.pending
665 670 .iter()
@@ -660,6 +660,11 @@ impl ConversationView {
660 }
660 }
661
661
662 #[cfg_attr(not(windows), allow(dead_code))]
662 #[cfg_attr(not(windows), allow(dead_code))]
663 pub fn opening_title(&self) -> Option<String> {
664 let loading = self.rows.borrow().iter().any(|row| matches!(row, Row::Skeleton(_)));
665 self.current.as_ref().filter(|_| loading).map(|current| current.title.clone())
666 }
667
663 pub fn send_in_flight(&self) -> bool {
668 pub fn send_in_flight(&self) -> bool {
664 self.pending
669 self.pending
665 .iter()
670 .iter()
crates/app/src/views/mod.rs +1 −0
@@ -91,6 +91,7 @@ pub mod shortcuts_dialog;
91 91 mod chat_menu;
92 92 mod last_views;
93 93 pub mod sidebar;
94 pub mod splash;
94 95 pub mod status_menu;
95 96 pub mod status_message_dialog;
96 97 pub mod switcher;
@@ -91,6 +91,7 @@ pub mod shortcuts_dialog;
91mod chat_menu;
91mod chat_menu;
92mod last_views;
92mod last_views;
93pub mod sidebar;
93pub mod sidebar;
94pub mod splash;
94pub mod status_menu;
95pub mod status_menu;
95pub mod status_message_dialog;
96pub mod status_message_dialog;
96pub mod switcher;
97pub mod switcher;
crates/app/src/views/shell.rs +60 −3
@@ -35,6 +35,7 @@ use super::sidebar::{SidebarEvent, SidebarTab, SidebarView};
35 35 use app_ui_kit::render::hooks::RenderHooks;
36 36 use app_ui_kit::layout::{ISLAND_GAP, SIDEBAR_WIDTH};
37 37 use super::connection_banner::render_connection_banner;
38 use super::splash::{self, Phase, Splash, StartupFacts};
38 39 use super::notice_toast::NoticeToasts;
39 40 use super::status_menu::{own_status_button, settings_more_button};
40 41 use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
@@ -184,6 +185,7 @@ pub struct AppShell {
184 185 focus_handle: FocusHandle,
185 186 open_target: Option<OpenTarget>,
186 187 update: UpdateStatus,
188 splash: Splash,
187 189 toasts: NoticeToasts,
188 190 user_input: Arc<UserInput>,
189 191 _subscription: Subscription,
@@ -408,6 +410,7 @@ impl AppShell {
408 410 focus_handle,
409 411 open_target,
410 412 update: UpdateStatus::UpToDate,
413 splash: Splash::default(),
411 414 toasts: NoticeToasts::default(),
412 415 user_input,
413 416 _subscription: subscription,
@@ -865,13 +868,52 @@ impl AppShell {
865 868 }
866 869
867 870 impl AppShell {
871 fn render_splash(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
872 let phase = if self.splash.is_up() {
873 let opening = self.conversation.read(cx).opening_title();
874 let state = self.state.read(cx);
875 let phase = splash::phase(&StartupFacts {
876 elapsed: self.splash.elapsed(),
877 connection: &state.connection,
878 has_chats: !state.sidebar.chats.is_empty() || !state.sidebar.teams.is_empty(),
879 synced: state.last_sync.is_some(),
880 demo: state.mode.demo,
881 opening,
882 });
883 if phase != Phase::Ready && cx.reduce_motion() && !self.splash.recheck_scheduled {
884 self.splash.recheck_scheduled = true;
885 cx.spawn(async move |this, cx| {
886 cx.background_executor().timer(splash::STILL_RECHECK).await;
887 this.update(cx, |this, cx| {
888 this.splash.recheck_scheduled = false;
889 cx.notify();
890 })
891 .ok();
892 })
893 .detach();
894 }
895 if phase == Phase::Ready {
896 self.splash.hide();
897 cx.spawn(async move |this, cx| {
898 cx.background_executor().timer(splash::CONTENT_RISE).await;
899 this.update(cx, |_, cx| cx.notify()).ok();
900 })
901 .detach();
902 }
903 phase
904 } else {
905 Phase::Ready
906 };
907 self.splash.render(&phase, cx)
908 }
909
868 910 fn islands(
869 911 &self,
870 912 show_sidebar: bool,
871 913 calendar_open: bool,
872 914 quick_view_open: bool,
873 915 calls_open: bool,
874 ) -> impl IntoElement {
916 ) -> Div {
875 917 h_flex()
876 918 .debug_selector(|| "shell/islands".into())
877 919 .flex_1()
@@ -972,12 +1014,13 @@ impl Render for AppShell {
972 1014 let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar;
973 1015 let chats_tab = self.sidebar.read(cx).tab() == SidebarTab::Chats;
974 1016 let calls_tab = self.sidebar.read(cx).tab() == SidebarTab::Calls;
1017 let splash = self.render_splash(cx);
975 1018 let state = self.state.read(cx);
976 1019 let calendar_open = calendar_tab;
977 1020 let quick_view_open = chats_tab && state.quick_view.is_some();
978 1021 let calls_open = calls_tab;
979 1022 let show_sidebar = !calendar_open && !calls_open;
980 let banner = state.connection_banner_text().map(|banner| {
1023 let banner = state.connection_banner_text().filter(|_| !self.splash.is_up()).map(|banner| {
981 1024 render_connection_banner(
982 1025 banner,
983 1026 cx.listener(|this, _, _, cx| {
@@ -1189,8 +1232,9 @@ impl Render for AppShell {
1189 1232 .size_full()
1190 1233 .child(title_bar)
1191 1234 .children(banner)
1192 .child(self.islands(show_sidebar, calendar_open, quick_view_open, calls_open)),
1235 .child(rising_in(self.islands(show_sidebar, calendar_open, quick_view_open, calls_open), &self.splash, cx)),
1193 1236 )
1237 .children(splash)
1194 1238 .children(self.image_viewer.clone())
1195 1239 .children(self.switcher.clone())
1196 1240 .children(render_task_dialog(self.state.read(cx), cx))
@@ -1204,6 +1248,18 @@ impl Render for AppShell {
1204 1248 }
1205 1249 }
1206 1250
1251 fn rising_in(islands: Div, splash: &Splash, cx: &App) -> AnyElement {
1252 if splash.content_rising().is_none() || cx.reduce_motion() {
1253 return islands.into_any_element();
1254 }
1255 islands
1256 .relative()
1257 .with_animation("startup-content-rise", Animation::new(splash::CONTENT_RISE).with_easing(ease_out_quint()), |islands, delta| {
1258 islands.top(px(splash::CONTENT_RISE_OFFSET * (1. - delta))).opacity(delta)
1259 })
1260 .into_any_element()
1261 }
1262
1207 1263 #[cfg(test)]
1208 1264 mod opening_link_tests {
1209 1265 use super::opening_link_text;
@@ -1215,3 +1271,4 @@ mod opening_link_tests {
1215 1271 assert_eq!(opening_link_text(""), "Opening link...");
1216 1272 }
1217 1273 }
1274
@@ -35,6 +35,7 @@ use super::sidebar::{SidebarEvent, SidebarTab, SidebarView};
35use app_ui_kit::render::hooks::RenderHooks;
35use app_ui_kit::render::hooks::RenderHooks;
36use app_ui_kit::layout::{ISLAND_GAP, SIDEBAR_WIDTH};
36use app_ui_kit::layout::{ISLAND_GAP, SIDEBAR_WIDTH};
37use super::connection_banner::render_connection_banner;
37use super::connection_banner::render_connection_banner;
38use super::splash::{self, Phase, Splash, StartupFacts};
38use super::notice_toast::NoticeToasts;
39use super::notice_toast::NoticeToasts;
39use super::status_menu::{own_status_button, settings_more_button};
40use super::status_menu::{own_status_button, settings_more_button};
40use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
41use super::status_message_dialog::{StatusMessageDialog, StatusMessageDialogEvent};
@@ -184,6 +185,7 @@ pub struct AppShell {
184 focus_handle: FocusHandle,
185 focus_handle: FocusHandle,
185 open_target: Option<OpenTarget>,
186 open_target: Option<OpenTarget>,
186 update: UpdateStatus,
187 update: UpdateStatus,
188 splash: Splash,
187 toasts: NoticeToasts,
189 toasts: NoticeToasts,
188 user_input: Arc<UserInput>,
190 user_input: Arc<UserInput>,
189 _subscription: Subscription,
191 _subscription: Subscription,
@@ -408,6 +410,7 @@ impl AppShell {
408 focus_handle,
410 focus_handle,
409 open_target,
411 open_target,
410 update: UpdateStatus::UpToDate,
412 update: UpdateStatus::UpToDate,
413 splash: Splash::default(),
411 toasts: NoticeToasts::default(),
414 toasts: NoticeToasts::default(),
412 user_input,
415 user_input,
413 _subscription: subscription,
416 _subscription: subscription,
@@ -865,13 +868,52 @@ impl AppShell {
865}
868}
866
869
867impl AppShell {
870impl AppShell {
871 fn render_splash(&mut self, cx: &mut Context<Self>) -> Option<AnyElement> {
872 let phase = if self.splash.is_up() {
873 let opening = self.conversation.read(cx).opening_title();
874 let state = self.state.read(cx);
875 let phase = splash::phase(&StartupFacts {
876 elapsed: self.splash.elapsed(),
877 connection: &state.connection,
878 has_chats: !state.sidebar.chats.is_empty() || !state.sidebar.teams.is_empty(),
879 synced: state.last_sync.is_some(),
880 demo: state.mode.demo,
881 opening,
882 });
883 if phase != Phase::Ready && cx.reduce_motion() && !self.splash.recheck_scheduled {
884 self.splash.recheck_scheduled = true;
885 cx.spawn(async move |this, cx| {
886 cx.background_executor().timer(splash::STILL_RECHECK).await;
887 this.update(cx, |this, cx| {
888 this.splash.recheck_scheduled = false;
889 cx.notify();
890 })
891 .ok();
892 })
893 .detach();
894 }
895 if phase == Phase::Ready {
896 self.splash.hide();
897 cx.spawn(async move |this, cx| {
898 cx.background_executor().timer(splash::CONTENT_RISE).await;
899 this.update(cx, |_, cx| cx.notify()).ok();
900 })
901 .detach();
902 }
903 phase
904 } else {
905 Phase::Ready
906 };
907 self.splash.render(&phase, cx)
908 }
909
868 fn islands(
910 fn islands(
869 &self,
911 &self,
870 show_sidebar: bool,
912 show_sidebar: bool,
871 calendar_open: bool,
913 calendar_open: bool,
872 quick_view_open: bool,
914 quick_view_open: bool,
873 calls_open: bool,
915 calls_open: bool,
874 ) -> impl IntoElement {
916 ) -> Div {
875 h_flex()
917 h_flex()
876 .debug_selector(|| "shell/islands".into())
918 .debug_selector(|| "shell/islands".into())
877 .flex_1()
919 .flex_1()
@@ -972,12 +1014,13 @@ impl Render for AppShell {
972 let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar;
1014 let calendar_tab = self.sidebar.read(cx).tab() == SidebarTab::Calendar;
973 let chats_tab = self.sidebar.read(cx).tab() == SidebarTab::Chats;
1015 let chats_tab = self.sidebar.read(cx).tab() == SidebarTab::Chats;
974 let calls_tab = self.sidebar.read(cx).tab() == SidebarTab::Calls;
1016 let calls_tab = self.sidebar.read(cx).tab() == SidebarTab::Calls;
1017 let splash = self.render_splash(cx);
975 let state = self.state.read(cx);
1018 let state = self.state.read(cx);
976 let calendar_open = calendar_tab;
1019 let calendar_open = calendar_tab;
977 let quick_view_open = chats_tab && state.quick_view.is_some();
1020 let quick_view_open = chats_tab && state.quick_view.is_some();
978 let calls_open = calls_tab;
1021 let calls_open = calls_tab;
979 let show_sidebar = !calendar_open && !calls_open;
1022 let show_sidebar = !calendar_open && !calls_open;
980 let banner = state.connection_banner_text().map(|banner| {
1023 let banner = state.connection_banner_text().filter(|_| !self.splash.is_up()).map(|banner| {
981 render_connection_banner(
1024 render_connection_banner(
982 banner,
1025 banner,
983 cx.listener(|this, _, _, cx| {
1026 cx.listener(|this, _, _, cx| {
@@ -1189,8 +1232,9 @@ impl Render for AppShell {
1189 .size_full()
1232 .size_full()
1190 .child(title_bar)
1233 .child(title_bar)
1191 .children(banner)
1234 .children(banner)
1192 .child(self.islands(show_sidebar, calendar_open, quick_view_open, calls_open)),
1235 .child(rising_in(self.islands(show_sidebar, calendar_open, quick_view_open, calls_open), &self.splash, cx)),
1193 )
1236 )
1237 .children(splash)
1194 .children(self.image_viewer.clone())
1238 .children(self.image_viewer.clone())
1195 .children(self.switcher.clone())
1239 .children(self.switcher.clone())
1196 .children(render_task_dialog(self.state.read(cx), cx))
1240 .children(render_task_dialog(self.state.read(cx), cx))
@@ -1204,6 +1248,18 @@ impl Render for AppShell {
1204 }
1248 }
1205}
1249}
1206
1250
1251fn rising_in(islands: Div, splash: &Splash, cx: &App) -> AnyElement {
1252 if splash.content_rising().is_none() || cx.reduce_motion() {
1253 return islands.into_any_element();
1254 }
1255 islands
1256 .relative()
1257 .with_animation("startup-content-rise", Animation::new(splash::CONTENT_RISE).with_easing(ease_out_quint()), |islands, delta| {
1258 islands.top(px(splash::CONTENT_RISE_OFFSET * (1. - delta))).opacity(delta)
1259 })
1260 .into_any_element()
1261}
1262
1207#[cfg(test)]
1263#[cfg(test)]
1208mod opening_link_tests {
1264mod opening_link_tests {
1209 use super::opening_link_text;
1265 use super::opening_link_text;
@@ -1215,3 +1271,4 @@ mod opening_link_tests {
1215 assert_eq!(opening_link_text(""), "Opening link...");
1271 assert_eq!(opening_link_text(""), "Opening link...");
1216 }
1272 }
1217}
1273}
1274
crates/app/src/views/splash.rs added +270 −0
@@ -0,0 +1,270 @@
1 use std::time::{Duration, Instant};
2
3 use gpui_kit::component::v_flex;
4 use gpui_kit::prelude::FluentBuilder as _;
5 use gpui_kit::*;
6
7 use super::title_bar::{TITLE_BAR_HEIGHT, app_icon_image};
8 use crate::backend::ConnectionState;
9 use crate::theme;
10
11 const MIN_VISIBLE: Duration = Duration::from_millis(400);
12 const STARTING_FOR: Duration = Duration::from_millis(300);
13 const HINT_AFTER: Duration = Duration::from_secs(8);
14 const GIVE_UP_AFTER: Duration = Duration::from_secs(30);
15 const FADE_OUT: Duration = Duration::from_millis(220);
16 pub const CONTENT_RISE: Duration = Duration::from_millis(260);
17 pub const CONTENT_RISE_OFFSET: f32 = 8.;
18 const LOGO_SIZE: f32 = 76.;
19 const LOGO_BREATH: f32 = 0.04;
20 const BREATH_PERIOD: Duration = Duration::from_millis(2400);
21 const BAR_WIDTH: f32 = 168.;
22 const BAR_HEIGHT: f32 = 3.;
23 const BAR_TOP_GAP: f32 = 32.;
24 const SWEEP_SHARE: f32 = 0.4;
25 const SWEEP_PERIOD: Duration = Duration::from_millis(1300);
26 const STATUS_TOP_GAP: f32 = 14.;
27 const STATUS_SIZE: f32 = 13.;
28 const STATUS_SWAP: Duration = Duration::from_millis(180);
29 const STATUS_SWAP_OFFSET: f32 = 4.;
30 const HINT_SIZE: f32 = 12.;
31 pub const STILL_RECHECK: Duration = Duration::from_millis(250);
32
33 pub struct StartupFacts<'a> {
34 pub elapsed: Duration,
35 pub connection: &'a ConnectionState,
36 pub has_chats: bool,
37 pub synced: bool,
38 pub demo: bool,
39 pub opening: Option<String>,
40 }
41
42 #[derive(Debug, Clone, PartialEq, Eq)]
43 pub enum Phase {
44 Loading { status: String, running: bool, hint: Option<&'static str> },
45 Ready,
46 }
47
48 pub fn phase(facts: &StartupFacts) -> Phase {
49 let content_ready = facts.has_chats || facts.synced || facts.demo;
50 if facts.elapsed >= MIN_VISIBLE && content_ready && facts.opening.is_none() {
51 return Phase::Ready;
52 }
53 let signing_in = matches!(facts.connection, ConnectionState::LoginRequired);
54 if facts.elapsed >= GIVE_UP_AFTER && !(signing_in && !content_ready) {
55 return Phase::Ready;
56 }
57 let loading = |status: String| Phase::Loading {
58 status,
59 running: true,
60 hint: (facts.elapsed >= HINT_AFTER && !content_ready).then_some("First start: this takes a little longer once"),
61 };
62 if signing_in {
63 return Phase::Loading {
64 status: "Sign in to Teams in the window that opened".to_owned(),
65 running: false,
66 hint: None,
67 };
68 }
69 if facts.elapsed < STARTING_FOR {
70 return loading("Starting Rusty Teams".to_owned());
71 }
72 if content_ready {
73 return loading(facts.opening.as_ref().map_or_else(|| "Syncing new messages".to_owned(), |title| format!("Opening {title}")));
74 }
75 match facts.connection {
76 ConnectionState::Connecting => loading("Signing in".to_owned()),
77 ConnectionState::Online => loading("Loading your chats".to_owned()),
78 _ => loading("Cannot reach Teams, trying again".to_owned()),
79 }
80 }
81
82 pub struct Splash {
83 started: Instant,
84 hidden_at: Option<Instant>,
85 pub recheck_scheduled: bool,
86 }
87
88 impl Default for Splash {
89 fn default() -> Self {
90 Splash { started: Instant::now(), hidden_at: None, recheck_scheduled: false }
91 }
92 }
93
94 impl Splash {
95 pub fn elapsed(&self) -> Duration {
96 self.started.elapsed()
97 }
98
99 pub fn is_up(&self) -> bool {
100 self.hidden_at.is_none()
101 }
102
103 pub fn hide(&mut self) {
104 self.hidden_at.get_or_insert_with(Instant::now);
105 }
106
107 pub fn content_rising(&self) -> Option<Duration> {
108 self.hidden_at.map(|hidden_at| hidden_at.elapsed()).filter(|since| *since < CONTENT_RISE)
109 }
110
111 pub fn render(&self, phase: &Phase, cx: &App) -> Option<AnyElement> {
112 let fading = self.hidden_at.map(|hidden_at| hidden_at.elapsed());
113 if fading.is_some_and(|since| since >= FADE_OUT) {
114 return None;
115 }
116 let still = cx.reduce_motion();
117 let app_icon = crate::active_appearance::current(cx).app_icon;
118 let (status, running, hint) = match phase {
119 Phase::Loading { status, running, hint } => (status.clone(), *running, *hint),
120 Phase::Ready => (String::new(), true, None),
121 };
122 let overlay = v_flex()
123 .id("startup-splash")
124 .debug_selector(|| "shell/splash".into())
125 .occlude()
126 .absolute()
127 .top(px(TITLE_BAR_HEIGHT))
128 .left_0()
129 .right_0()
130 .bottom_0()
131 .items_center()
132 .justify_center()
133 .bg(theme::background())
134 .child(logo(app_icon, still))
135 .child(bar(running, still))
136 .child(status_line(status, still))
137 .child(
138 div()
139 .mt(px(6.))
140 .h(px(16.))
141 .text_size(px(HINT_SIZE))
142 .text_color(theme::text_faint())
143 .children(hint),
144 );
145 Some(match fading {
146 Some(_) if !still => overlay
147 .with_animation("startup-splash-fade", Animation::new(FADE_OUT).with_easing(ease_out_quint()), |overlay, delta| {
148 overlay.opacity(1. - delta)
149 })
150 .into_any_element(),
151 _ => overlay.into_any_element(),
152 })
153 }
154 }
155
156 fn logo(app_icon: crate::appearance::AppIcon, still: bool) -> AnyElement {
157 let image = img(app_icon_image(app_icon)).size(px(LOGO_SIZE));
158 let frame = div().size(px(LOGO_SIZE * (1. + LOGO_BREATH))).flex().items_center().justify_center();
159 if still {
160 return frame.child(image).into_any_element();
161 }
162 frame
163 .child(image.with_animation("startup-splash-logo", Animation::new(BREATH_PERIOD).repeat(), |image, delta| {
164 let wave = (1. - (delta * std::f32::consts::TAU).cos()) / 2.;
165 image.size(px(LOGO_SIZE * (1. + LOGO_BREATH * wave)))
166 }))
167 .into_any_element()
168 }
169
170 fn bar(running: bool, still: bool) -> Div {
171 let sweep_width = BAR_WIDTH * SWEEP_SHARE;
172 let sweep = || div().absolute().top_0().bottom_0().w(px(sweep_width)).rounded(px(BAR_HEIGHT)).bg(theme::accent());
173 div()
174 .relative()
175 .mt(px(BAR_TOP_GAP))
176 .w(px(BAR_WIDTH))
177 .h(px(BAR_HEIGHT))
178 .rounded(px(BAR_HEIGHT))
179 .overflow_hidden()
180 .bg(theme::border_strong())
181 .when(!running, |bar| bar.invisible())
182 .when(running && still, |bar| bar.child(sweep().left(px((BAR_WIDTH - sweep_width) / 2.))))
183 .when(running && !still, |bar| {
184 bar.child(sweep().with_animation(
185 "startup-splash-sweep",
186 Animation::new(SWEEP_PERIOD).repeat().with_easing(ease_in_out),
187 move |sweep, delta| {
188 let head = (BAR_WIDTH + sweep_width) * delta;
189 let start = (head - sweep_width).max(0.);
190 sweep.left(px(start)).w(px(head.min(BAR_WIDTH) - start))
191 },
192 ))
193 })
194 }
195
196 fn status_line(status: String, still: bool) -> AnyElement {
197 let line = div().text_size(px(STATUS_SIZE)).text_color(theme::text_muted()).child(status.clone());
198 let slot = div().mt(px(STATUS_TOP_GAP)).h(px(STATUS_SIZE * 1.4)).relative();
199 if still {
200 return slot.child(line).into_any_element();
201 }
202 slot.child(line.relative().with_animation(
203 ElementId::Name(format!("startup-splash-status-{status}").into()),
204 Animation::new(STATUS_SWAP).with_easing(ease_out_quint()),
205 |line, delta| line.top(px(STATUS_SWAP_OFFSET * (1. - delta))).opacity(delta),
206 ))
207 .into_any_element()
208 }
209
210 #[cfg(test)]
211 mod tests {
212 use std::time::Duration;
213
214 use super::{ConnectionState, Phase, StartupFacts, phase};
215
216 fn facts(elapsed_ms: u64, connection: &ConnectionState) -> StartupFacts<'_> {
217 StartupFacts {
218 elapsed: Duration::from_millis(elapsed_ms),
219 connection,
220 has_chats: false,
221 synced: false,
222 demo: false,
223 opening: None,
224 }
225 }
226
227 fn status(phase: Phase) -> String {
228 match phase {
229 Phase::Loading { status, .. } => status,
230 Phase::Ready => "ready".to_owned(),
231 }
232 }
233
234 #[test]
235 fn a_warm_cache_shows_the_app_after_the_minimum() {
236 let online = ConnectionState::Connecting;
237 let warm = StartupFacts { has_chats: true, ..facts(100, &online) };
238 assert_eq!(status(phase(&warm)), "Starting Rusty Teams");
239 let warm = StartupFacts { has_chats: true, ..facts(450, &online) };
240 assert_eq!(phase(&warm), Phase::Ready);
241 }
242
243 #[test]
244 fn the_open_chat_holds_the_splash_until_its_messages_show() {
245 let online = ConnectionState::Online;
246 let opening = StartupFacts { has_chats: true, opening: Some("Release planning".to_owned()), ..facts(900, &online) };
247 assert_eq!(status(phase(&opening)), "Opening Release planning");
248 }
249
250 #[test]
251 fn a_first_start_walks_through_sign_in_and_chats_with_a_late_hint() {
252 let connecting = ConnectionState::Connecting;
253 assert_eq!(status(phase(&facts(500, &connecting))), "Signing in");
254 let online = ConnectionState::Online;
255 assert_eq!(status(phase(&facts(2000, &online))), "Loading your chats");
256 let Phase::Loading { hint, .. } = phase(&facts(9000, &online)) else { panic!("still loading") };
257 assert!(hint.is_some());
258 let synced = StartupFacts { synced: true, ..facts(9000, &online) };
259 assert_eq!(phase(&synced), Phase::Ready);
260 }
261
262 #[test]
263 fn sign_in_stops_the_bar_and_never_gives_up_without_content() {
264 let login = ConnectionState::LoginRequired;
265 let Phase::Loading { running, .. } = phase(&facts(60_000, &login)) else { panic!("still loading") };
266 assert!(!running);
267 let offline = ConnectionState::Failed("down".to_owned());
268 assert_eq!(phase(&facts(31_000, &offline)), Phase::Ready);
269 }
270 }
@@ -0,0 +1,270 @@
1use std::time::{Duration, Instant};
2
3use gpui_kit::component::v_flex;
4use gpui_kit::prelude::FluentBuilder as _;
5use gpui_kit::*;
6
7use super::title_bar::{TITLE_BAR_HEIGHT, app_icon_image};
8use crate::backend::ConnectionState;
9use crate::theme;
10
11const MIN_VISIBLE: Duration = Duration::from_millis(400);
12const STARTING_FOR: Duration = Duration::from_millis(300);
13const HINT_AFTER: Duration = Duration::from_secs(8);
14const GIVE_UP_AFTER: Duration = Duration::from_secs(30);
15const FADE_OUT: Duration = Duration::from_millis(220);
16pub const CONTENT_RISE: Duration = Duration::from_millis(260);
17pub const CONTENT_RISE_OFFSET: f32 = 8.;
18const LOGO_SIZE: f32 = 76.;
19const LOGO_BREATH: f32 = 0.04;
20const BREATH_PERIOD: Duration = Duration::from_millis(2400);
21const BAR_WIDTH: f32 = 168.;
22const BAR_HEIGHT: f32 = 3.;
23const BAR_TOP_GAP: f32 = 32.;
24const SWEEP_SHARE: f32 = 0.4;
25const SWEEP_PERIOD: Duration = Duration::from_millis(1300);
26const STATUS_TOP_GAP: f32 = 14.;
27const STATUS_SIZE: f32 = 13.;
28const STATUS_SWAP: Duration = Duration::from_millis(180);
29const STATUS_SWAP_OFFSET: f32 = 4.;
30const HINT_SIZE: f32 = 12.;
31pub const STILL_RECHECK: Duration = Duration::from_millis(250);
32
33pub struct StartupFacts<'a> {
34 pub elapsed: Duration,
35 pub connection: &'a ConnectionState,
36 pub has_chats: bool,
37 pub synced: bool,
38 pub demo: bool,
39 pub opening: Option<String>,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub enum Phase {
44 Loading { status: String, running: bool, hint: Option<&'static str> },
45 Ready,
46}
47
48pub fn phase(facts: &StartupFacts) -> Phase {
49 let content_ready = facts.has_chats || facts.synced || facts.demo;
50 if facts.elapsed >= MIN_VISIBLE && content_ready && facts.opening.is_none() {
51 return Phase::Ready;
52 }
53 let signing_in = matches!(facts.connection, ConnectionState::LoginRequired);
54 if facts.elapsed >= GIVE_UP_AFTER && !(signing_in && !content_ready) {
55 return Phase::Ready;
56 }
57 let loading = |status: String| Phase::Loading {
58 status,
59 running: true,
60 hint: (facts.elapsed >= HINT_AFTER && !content_ready).then_some("First start: this takes a little longer once"),
61 };
62 if signing_in {
63 return Phase::Loading {
64 status: "Sign in to Teams in the window that opened".to_owned(),
65 running: false,
66 hint: None,
67 };
68 }
69 if facts.elapsed < STARTING_FOR {
70 return loading("Starting Rusty Teams".to_owned());
71 }
72 if content_ready {
73 return loading(facts.opening.as_ref().map_or_else(|| "Syncing new messages".to_owned(), |title| format!("Opening {title}")));
74 }
75 match facts.connection {
76 ConnectionState::Connecting => loading("Signing in".to_owned()),
77 ConnectionState::Online => loading("Loading your chats".to_owned()),
78 _ => loading("Cannot reach Teams, trying again".to_owned()),
79 }
80}
81
82pub struct Splash {
83 started: Instant,
84 hidden_at: Option<Instant>,
85 pub recheck_scheduled: bool,
86}
87
88impl Default for Splash {
89 fn default() -> Self {
90 Splash { started: Instant::now(), hidden_at: None, recheck_scheduled: false }
91 }
92}
93
94impl Splash {
95 pub fn elapsed(&self) -> Duration {
96 self.started.elapsed()
97 }
98
99 pub fn is_up(&self) -> bool {
100 self.hidden_at.is_none()
101 }
102
103 pub fn hide(&mut self) {
104 self.hidden_at.get_or_insert_with(Instant::now);
105 }
106
107 pub fn content_rising(&self) -> Option<Duration> {
108 self.hidden_at.map(|hidden_at| hidden_at.elapsed()).filter(|since| *since < CONTENT_RISE)
109 }
110
111 pub fn render(&self, phase: &Phase, cx: &App) -> Option<AnyElement> {
112 let fading = self.hidden_at.map(|hidden_at| hidden_at.elapsed());
113 if fading.is_some_and(|since| since >= FADE_OUT) {
114 return None;
115 }
116 let still = cx.reduce_motion();
117 let app_icon = crate::active_appearance::current(cx).app_icon;
118 let (status, running, hint) = match phase {
119 Phase::Loading { status, running, hint } => (status.clone(), *running, *hint),
120 Phase::Ready => (String::new(), true, None),
121 };
122 let overlay = v_flex()
123 .id("startup-splash")
124 .debug_selector(|| "shell/splash".into())
125 .occlude()
126 .absolute()
127 .top(px(TITLE_BAR_HEIGHT))
128 .left_0()
129 .right_0()
130 .bottom_0()
131 .items_center()
132 .justify_center()
133 .bg(theme::background())
134 .child(logo(app_icon, still))
135 .child(bar(running, still))
136 .child(status_line(status, still))
137 .child(
138 div()
139 .mt(px(6.))
140 .h(px(16.))
141 .text_size(px(HINT_SIZE))
142 .text_color(theme::text_faint())
143 .children(hint),
144 );
145 Some(match fading {
146 Some(_) if !still => overlay
147 .with_animation("startup-splash-fade", Animation::new(FADE_OUT).with_easing(ease_out_quint()), |overlay, delta| {
148 overlay.opacity(1. - delta)
149 })
150 .into_any_element(),
151 _ => overlay.into_any_element(),
152 })
153 }
154}
155
156fn logo(app_icon: crate::appearance::AppIcon, still: bool) -> AnyElement {
157 let image = img(app_icon_image(app_icon)).size(px(LOGO_SIZE));
158 let frame = div().size(px(LOGO_SIZE * (1. + LOGO_BREATH))).flex().items_center().justify_center();
159 if still {
160 return frame.child(image).into_any_element();
161 }
162 frame
163 .child(image.with_animation("startup-splash-logo", Animation::new(BREATH_PERIOD).repeat(), |image, delta| {
164 let wave = (1. - (delta * std::f32::consts::TAU).cos()) / 2.;
165 image.size(px(LOGO_SIZE * (1. + LOGO_BREATH * wave)))
166 }))
167 .into_any_element()
168}
169
170fn bar(running: bool, still: bool) -> Div {
171 let sweep_width = BAR_WIDTH * SWEEP_SHARE;
172 let sweep = || div().absolute().top_0().bottom_0().w(px(sweep_width)).rounded(px(BAR_HEIGHT)).bg(theme::accent());
173 div()
174 .relative()
175 .mt(px(BAR_TOP_GAP))
176 .w(px(BAR_WIDTH))
177 .h(px(BAR_HEIGHT))
178 .rounded(px(BAR_HEIGHT))
179 .overflow_hidden()
180 .bg(theme::border_strong())
181 .when(!running, |bar| bar.invisible())
182 .when(running && still, |bar| bar.child(sweep().left(px((BAR_WIDTH - sweep_width) / 2.))))
183 .when(running && !still, |bar| {
184 bar.child(sweep().with_animation(
185 "startup-splash-sweep",
186 Animation::new(SWEEP_PERIOD).repeat().with_easing(ease_in_out),
187 move |sweep, delta| {
188 let head = (BAR_WIDTH + sweep_width) * delta;
189 let start = (head - sweep_width).max(0.);
190 sweep.left(px(start)).w(px(head.min(BAR_WIDTH) - start))
191 },
192 ))
193 })
194}
195
196fn status_line(status: String, still: bool) -> AnyElement {
197 let line = div().text_size(px(STATUS_SIZE)).text_color(theme::text_muted()).child(status.clone());
198 let slot = div().mt(px(STATUS_TOP_GAP)).h(px(STATUS_SIZE * 1.4)).relative();
199 if still {
200 return slot.child(line).into_any_element();
201 }
202 slot.child(line.relative().with_animation(
203 ElementId::Name(format!("startup-splash-status-{status}").into()),
204 Animation::new(STATUS_SWAP).with_easing(ease_out_quint()),
205 |line, delta| line.top(px(STATUS_SWAP_OFFSET * (1. - delta))).opacity(delta),
206 ))
207 .into_any_element()
208}
209
210#[cfg(test)]
211mod tests {
212 use std::time::Duration;
213
214 use super::{ConnectionState, Phase, StartupFacts, phase};
215
216 fn facts(elapsed_ms: u64, connection: &ConnectionState) -> StartupFacts<'_> {
217 StartupFacts {
218 elapsed: Duration::from_millis(elapsed_ms),
219 connection,
220 has_chats: false,
221 synced: false,
222 demo: false,
223 opening: None,
224 }
225 }
226
227 fn status(phase: Phase) -> String {
228 match phase {
229 Phase::Loading { status, .. } => status,
230 Phase::Ready => "ready".to_owned(),
231 }
232 }
233
234 #[test]
235 fn a_warm_cache_shows_the_app_after_the_minimum() {
236 let online = ConnectionState::Connecting;
237 let warm = StartupFacts { has_chats: true, ..facts(100, &online) };
238 assert_eq!(status(phase(&warm)), "Starting Rusty Teams");
239 let warm = StartupFacts { has_chats: true, ..facts(450, &online) };
240 assert_eq!(phase(&warm), Phase::Ready);
241 }
242
243 #[test]
244 fn the_open_chat_holds_the_splash_until_its_messages_show() {
245 let online = ConnectionState::Online;
246 let opening = StartupFacts { has_chats: true, opening: Some("Release planning".to_owned()), ..facts(900, &online) };
247 assert_eq!(status(phase(&opening)), "Opening Release planning");
248 }
249
250 #[test]
251 fn a_first_start_walks_through_sign_in_and_chats_with_a_late_hint() {
252 let connecting = ConnectionState::Connecting;
253 assert_eq!(status(phase(&facts(500, &connecting))), "Signing in");
254 let online = ConnectionState::Online;
255 assert_eq!(status(phase(&facts(2000, &online))), "Loading your chats");
256 let Phase::Loading { hint, .. } = phase(&facts(9000, &online)) else { panic!("still loading") };
257 assert!(hint.is_some());
258 let synced = StartupFacts { synced: true, ..facts(9000, &online) };
259 assert_eq!(phase(&synced), Phase::Ready);
260 }
261
262 #[test]
263 fn sign_in_stops_the_bar_and_never_gives_up_without_content() {
264 let login = ConnectionState::LoginRequired;
265 let Phase::Loading { running, .. } = phase(&facts(60_000, &login)) else { panic!("still loading") };
266 assert!(!running);
267 let offline = ConnectionState::Failed("down".to_owned());
268 assert_eq!(phase(&facts(31_000, &offline)), Phase::Ready);
269 }
270}