Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 15 additions & 15 deletions tui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
20 changes: 18 additions & 2 deletions tui/src/page_handler/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:?}");
Expand Down Expand Up @@ -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 {
Expand Down
23 changes: 15 additions & 8 deletions tui/src/page_handler/ui_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +28,7 @@ use crate::utility::LerpState;
/// Starts the interface and run the app
pub fn start_app<B: Backend>(
terminal: &mut Terminal<B>,
new_version_data: &Option<Vec<String>>,
new_version_data: Arc<Mutex<Option<Vec<String>>>>,
config: &mut Config,
conn: &mut DbConn,
) -> Result<HandlingOutput, UiHandlingError> {
Expand Down Expand Up @@ -83,13 +84,7 @@ pub fn start_app<B: Backend>(
// 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;
Expand Down Expand Up @@ -172,6 +167,8 @@ pub fn start_app<B: Backend>(

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.
//
Expand All @@ -180,6 +177,16 @@ pub fn start_app<B: Backend>(
// 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
Expand Down
Loading