From e210793edf1f7c4d9d9102ddd1a49fd9d92a6076 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Tue, 22 Aug 2023 18:34:40 +0200 Subject: [PATCH] Show Welcome Screen after closing recording even with `--skip-welcome-screen` (#3035) ### What Fixes #3018 https://github.com/rerun-io/rerun/assets/49431240/af2d69e0-921d-4f11-8ca0-b6f6957f7599 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3035) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/3035) - [Docs preview](https://rerun.io/preview/pr%3Aantoine%2Foverride-skip-welcome-screen/docs) - [Examples preview](https://rerun.io/preview/pr%3Aantoine%2Foverride-skip-welcome-screen/examples) --- crates/re_viewer/src/app.rs | 26 +++++++++++++++----------- crates/re_viewer/src/store_hub.rs | 13 +++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/crates/re_viewer/src/app.rs b/crates/re_viewer/src/app.rs index 180445e2a6cd..37357bac2a60 100644 --- a/crates/re_viewer/src/app.rs +++ b/crates/re_viewer/src/app.rs @@ -868,17 +868,23 @@ impl App { /// The welcome screen can be displayed only when a blueprint is available (and no recording is /// loaded). This function implements the heuristic which determines when the welcome screen /// should show up. - fn handle_default_blueprint(&mut self, store_hub: &mut StoreHub) { - if store_hub.current_recording().is_some() - || store_hub.selected_application_id().is_some() - || self.startup_options.skip_welcome_screen + fn should_show_welcome_screen(&mut self, store_hub: &mut StoreHub) -> bool { + // Don't show the welcome screen if we have actual data to display. + if store_hub.current_recording().is_some() || store_hub.selected_application_id().is_some() { - return; + return false; + } + + // Don't show the welcome screen if the `--skip-welcome-screen` flag was used (e.g. by the + // Python SDK), until some data has been loaded and shown. This way, we *still* show the + // welcome screen when the user closes all recordings after, e.g., running a Python example. + if self.startup_options.skip_welcome_screen && !store_hub.was_recording_active() { + return false; } // Here, we use the type of Receiver as a proxy for which kind of workflow the viewer is // being used in. - let welcome = match self.rx.source() { + match self.rx.source() { // These source are typically "finite". We want the loading screen so long as data is // coming in. SmartChannelSource::Files { .. } | SmartChannelSource::RrdHttpStream { .. } => { @@ -894,10 +900,6 @@ impl App { // where it's not the case, including Python/C++ SDKs and possibly other, advanced used, // scenarios. In this cases, `--skip-welcome-screen` should be used. SmartChannelSource::TcpServer { .. } => true, - }; - - if welcome { - store_hub.set_app_id(StoreHub::welcome_screen_app_id()); } } } @@ -1014,7 +1016,9 @@ impl eframe::App for App { // Heuristic to set the app_id to the welcome screen blueprint. // Must be called before `read_context` below. - self.handle_default_blueprint(&mut store_hub); + if self.should_show_welcome_screen(&mut store_hub) { + store_hub.set_app_id(StoreHub::welcome_screen_app_id()); + } let store_context = store_hub.read_context(); diff --git a/crates/re_viewer/src/store_hub.rs b/crates/re_viewer/src/store_hub.rs index 8bf28e001436..848cc71445d9 100644 --- a/crates/re_viewer/src/store_hub.rs +++ b/crates/re_viewer/src/store_hub.rs @@ -28,6 +28,9 @@ pub struct StoreHub { blueprint_by_app_id: HashMap, store_dbs: StoreBundle, + /// Was a recording ever activated? Used by the heuristic controlling the welcome screen. + was_recording_active: bool, + // The [`StoreGeneration`] from when the [`StoreDb`] was last saved #[cfg(not(target_arch = "wasm32"))] blueprint_last_save: HashMap, @@ -69,6 +72,8 @@ impl StoreHub { blueprint_by_app_id: blueprints, store_dbs: Default::default(), + was_recording_active: false, + #[cfg(not(target_arch = "wasm32"))] blueprint_last_save: Default::default(), } @@ -114,6 +119,13 @@ impl StoreHub { }) } + /// Keeps track if a recording was every activated. + /// + /// This useful for the heuristic controlling the welcome screen. + pub fn was_recording_active(&self) -> bool { + self.was_recording_active + } + /// Change the selected/visible recording id. /// This will also change the application-id to match the newly selected recording. pub fn set_recording_id(&mut self, recording_id: StoreId) { @@ -128,6 +140,7 @@ impl StoreHub { } self.selected_rec_id = Some(recording_id); + self.was_recording_active = true; } pub fn remove_recording_id(&mut self, recording_id: &StoreId) {