From ff46acd4b76e1b736531f1c2c7d2fb7fdf3ff238 Mon Sep 17 00:00:00 2001 From: Rusty Pickle Date: Wed, 8 Apr 2026 12:41:34 +0600 Subject: [PATCH 1/2] Prevent blocking the main ui for update check --- tui/src/page_handler/initializer.rs | 20 ++++++++++++++++++-- tui/src/page_handler/ui_handler.rs | 23 +++++++++++++++-------- 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/tui/src/page_handler/initializer.rs b/tui/src/page_handler/initializer.rs index 89c724a..1372dc7 100644 --- a/tui/src/page_handler/initializer.rs +++ b/tui/src/page_handler/initializer.rs @@ -6,6 +6,8 @@ use std::fs::{self, File}; use std::io::prelude::*; use std::path::{Path, PathBuf}; use std::process; +use std::sync::{Arc, Mutex}; +use std::thread::spawn; use crate::config::{Config, migrate_config}; use crate::outputs::HandlingOutput; @@ -50,7 +52,16 @@ pub fn initialize_app( } } - let new_version = check_version().unwrap_or_default(); + let new_update = Arc::new(Mutex::new(None)); + + let update_clone = new_update.clone(); + + spawn(move || { + let new_version = check_version().unwrap_or_default().unwrap_or_default(); + + let mut lock = update_clone.lock().unwrap(); + *lock = Some(new_version); + }); if let Err(e) = migrate_config(old_db_path) { println!("Failed to migrate config. Error: {e:?}"); @@ -79,7 +90,12 @@ pub fn initialize_app( loop { let mut terminal = enter_tui_interface()?; - let result = start_app(&mut terminal, &new_version, &mut config, &mut migrated_conn); + let result = start_app( + &mut terminal, + new_update.clone(), + &mut config, + &mut migrated_conn, + ); exit_tui_interface()?; match result { diff --git a/tui/src/page_handler/ui_handler.rs b/tui/src/page_handler/ui_handler.rs index a9e2d73..30eacff 100644 --- a/tui/src/page_handler/ui_handler.rs +++ b/tui/src/page_handler/ui_handler.rs @@ -4,6 +4,7 @@ use ratatui::backend::Backend; use rex_app::conn::{DbConn, FetchNature}; use rex_app::ui_helper::DateType; use rex_app::views::SearchView; +use std::sync::{Arc, Mutex}; use std::time::Duration; use crate::config::Config; @@ -27,7 +28,7 @@ use crate::utility::LerpState; /// Starts the interface and run the app pub fn start_app( terminal: &mut Terminal, - new_version_data: &Option>, + new_version_data: Arc>>>, config: &mut Config, conn: &mut DbConn, ) -> Result { @@ -83,13 +84,7 @@ pub fn start_app( // The page which is currently selected. Default is the initial page let mut page = CurrentUi::Initial; - // Stores current popup status. If a new version is available, show popup - let mut popup_status = if let Some(data) = new_version_data { - let state = InfoPopupState::NewUpdate(data.to_owned()); - PopupType::new_info(state) - } else { - PopupType::Nothing - }; + let mut popup_status = PopupType::Nothing; // Stores the current selected widget on Add Transaction page let mut add_tx_tab = TxTab::Nothing; @@ -172,6 +167,8 @@ pub fn start_app( let mut lerp_state = LerpState::new(1.0); + let mut version_checked = false; + // How it work: // Default value from above -> Goes to an interface page and render -> Wait for an event key press. // @@ -180,6 +177,16 @@ pub fn start_app( // If key press is detected, send most of the mutable values to InputKeyHandler -> Gets mutated based on keypress // -> loop ends -> start from beginning -> Send the new mutated values to the interface -> Keep up loop { + if !version_checked { + let update_lock = new_version_data.lock().unwrap(); + if let Some(data) = update_lock.as_ref() { + if !data.is_empty() { + let state = InfoPopupState::NewUpdate(data.to_vec()); + popup_status = PopupType::new_info(state); + } + version_checked = true; + } + } // If TX method list is empty, forcefully ask to create a new TX method if conn.is_tx_method_empty() && let PopupType::Nothing = popup_status From 07a7b1bb6202524267518576f43a93c93c932c90 Mon Sep 17 00:00:00 2001 From: Rusty Pickle Date: Wed, 8 Apr 2026 12:41:40 +0600 Subject: [PATCH 2/2] Update deps --- Cargo.lock | 44 +++++++++++++++++++++++++++++++------------- Cargo.toml | 10 +++++----- tui/Cargo.toml | 30 +++++++++++++++--------------- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89d9b56..26e48e3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -439,9 +439,9 @@ dependencies = [ [[package]] name = "diesel" -version = "2.3.6" +version = "2.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b6c2fc184a6fb6ebcf5f9a5e3bbfa84d8fd268cdfcce4ed508979a6259494d" +checksum = "f4ae09a41a4b89f94ec1e053623da8340d996bc32c6517d325a9daad9b239358" dependencies = [ "chrono", "diesel_derives", @@ -1922,7 +1922,7 @@ dependencies = [ "itertools", "kasuari", "lru", - "strum", + "strum 0.27.2", "thiserror 2.0.18", "unicode-segmentation", "unicode-truncate", @@ -1974,7 +1974,7 @@ dependencies = [ "itertools", "line-clipping", "ratatui-core", - "strum", + "strum 0.27.2", "time", "unicode-segmentation", "unicode-width", @@ -2087,8 +2087,8 @@ dependencies = [ "rex-db", "rex-shared", "strsim", - "strum", - "strum_macros", + "strum 0.28.0", + "strum_macros 0.28.0", "thiserror 2.0.18", ] @@ -2102,8 +2102,8 @@ dependencies = [ "diesel_migrations", "libsqlite3-sys", "rex-shared", - "strum", - "strum_macros", + "strum 0.28.0", + "strum_macros 0.28.0", ] [[package]] @@ -2131,8 +2131,8 @@ dependencies = [ "semver", "serde", "serde_json", - "strum", - "strum_macros", + "strum 0.28.0", + "strum_macros 0.28.0", "thousands", ] @@ -2357,9 +2357,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.27" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" [[package]] name = "serde" @@ -2525,9 +2525,15 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af23d6f6c1a224baef9d3f61e287d2761385a5b88fdab4eb4c6f11aeb54c4bcf" dependencies = [ - "strum_macros", + "strum_macros 0.27.2", ] +[[package]] +name = "strum" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd" + [[package]] name = "strum_macros" version = "0.27.2" @@ -2540,6 +2546,18 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "strum_macros" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.117", +] + [[package]] name = "subtle" version = "2.6.1" diff --git a/Cargo.toml b/Cargo.toml index b36c116..fbcaf90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,15 +7,15 @@ resolver = "2" rex-shared = "0.2.5" rex-db = "0.2.5" rex-app = "0.2.5" -chrono = "0.4.42" -diesel = { version = "2.3.5", default-features = false, features = [ +chrono = "0.4.44" +diesel = { version = "2.3.7", default-features = false, features = [ "returning_clauses_for_sqlite_3_35", "sqlite", "chrono", ] } -anyhow = "1.0.100" -strum = "0.27" -strum_macros = "0.27" +anyhow = "1.0.102" +strum = "0.28" +strum_macros = "0.28" # The profile that 'cargo dist' will build with [profile.dist] diff --git a/tui/Cargo.toml b/tui/Cargo.toml index 149a537..2ace683 100644 --- a/tui/Cargo.toml +++ b/tui/Cargo.toml @@ -2,41 +2,41 @@ name = "rex-tui" version = "0.2.5" edition = "2024" -readme = "../README.md" description = """ A TUI app for managing Incomes and Expenses """ +readme = "../README.md" homepage = "https://github.com/TheRustyPickle/Rex" repository = "https://github.com/TheRustyPickle/Rex" license = "MIT" -keywords = ["tui", "terminal", "budget", "finance", "money"] +keywords = ["budget", "finance", "money", "terminal", "tui"] categories = ["command-line-utilities"] -exclude = ["logo.png", ".github", "typos.toml", "codecov.yml"] +exclude = [".github", "codecov.yml", "logo.png", "typos.toml"] [[bin]] +bench = false name = "rex" path = "src/main.rs" test = false -bench = false [dependencies] -rex-app.workspace = true -rex-shared.workspace = true anyhow.workspace = true +atty = "0.2.14" chrono.workspace = true -strum.workspace = true -strum_macros.workspace = true crossterm = "0.29.0" +dirs = "6.0.0" open = "5.3.3" -atty = "0.2.14" -reqwest = { version = "0.13.1", features = ["blocking", "json"] } +ratatui = "0.30.0" +reqwest = { version = "0.13.2", features = ["blocking", "json"] } +rex-app.workspace = true +rex-shared.workspace = true +rfd = "0.17.2" +semver = "1.0.28" serde = { version = "1.0.228", features = ["derive"] } -dirs = "6.0.0" +serde_json = "1.0.149" +strum.workspace = true +strum_macros.workspace = true thousands = "0.2.0" -semver = "1.0.27" -ratatui = "0.30.0" -serde_json = "1.0.148" -rfd = "0.17.1" [lints.clippy] too_many_arguments = { level = "allow" }