From 55b6327d423012f6d23dd6e0bd03a28706c2e48e Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Mon, 19 Feb 2024 16:27:11 -0500 Subject: [PATCH] Open the welcome screen if the database is not available --- fitnesstrax/app/src/app.rs | 14 ++------------ fitnesstrax/app/src/app_window.rs | 11 +++++++---- fitnesstrax/app/src/views/mod.rs | 1 - 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/fitnesstrax/app/src/app.rs b/fitnesstrax/app/src/app.rs index 94c83b8..546cecb 100644 --- a/fitnesstrax/app/src/app.rs +++ b/fitnesstrax/app/src/app.rs @@ -96,18 +96,8 @@ impl App { .unwrap() } - pub async fn get_record(&self, id: RecordId) -> Result>, AppError> { - let db = self.database.clone(); - self.runtime - .spawn_blocking(move || { - if let Some(ref db) = *db.read().unwrap() { - Ok(db.get(&id)) - } else { - Err(AppError::NoDatabase) - } - }) - .await - .unwrap() + pub fn database_is_open(&self) -> bool { + self.database.read().unwrap().is_some() } } diff --git a/fitnesstrax/app/src/app_window.rs b/fitnesstrax/app/src/app_window.rs index 31a05c3..3bdd4a4 100644 --- a/fitnesstrax/app/src/app_window.rs +++ b/fitnesstrax/app/src/app_window.rs @@ -136,7 +136,6 @@ impl AppWindow { s } - #[allow(unused)] fn show_welcome_view(&self) { let view = View::Welcome(WelcomeView::new({ let s = self.clone(); @@ -177,9 +176,13 @@ impl AppWindow { glib::spawn_future_local({ let s = self.clone(); async move { - let end = Local::now().date_naive(); - let start = end - Duration::days(7); - s.show_historical_view(DayInterval { start, end }); + if s.app.database_is_open() { + let end = Local::now().date_naive(); + let start = end - Duration::days(7); + s.show_historical_view(DayInterval { start, end }); + } else { + s.show_welcome_view(); + } } }); } diff --git a/fitnesstrax/app/src/views/mod.rs b/fitnesstrax/app/src/views/mod.rs index a8c7360..9957823 100644 --- a/fitnesstrax/app/src/views/mod.rs +++ b/fitnesstrax/app/src/views/mod.rs @@ -30,7 +30,6 @@ pub use welcome_view::WelcomeView; pub enum View { Placeholder(PlaceholderView), - #[allow(unused)] Welcome(WelcomeView), Historical(HistoricalView), }