From 503a3ef94cf15ace5484281597dec5e278489d79 Mon Sep 17 00:00:00 2001 From: "s0wlz (Matthias Puchstein)" Date: Thu, 26 Feb 2026 12:32:52 +0100 Subject: [PATCH] [refactor] simplify app state to a single countdown service - replace AppState.countdowns vector with countdown_service - add CountdownService::new(id, label, duration) for configurable initialization - add CountdownService::default() with default countdown values - remove unused next_id field and note TODO for multi-countdown support --- src-tauri/src/app_state.rs | 6 +++--- src-tauri/src/countdown/service.rs | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src-tauri/src/app_state.rs b/src-tauri/src/app_state.rs index 2b4104b..ce49395 100644 --- a/src-tauri/src/app_state.rs +++ b/src-tauri/src/app_state.rs @@ -20,18 +20,18 @@ impl ClockAnchor { instant.duration_since(self.boot_instant).as_millis() + self.boot_epoch_ms } } - +//TODO: implement the handling of multiple countdowns #[derive(Debug)] pub struct AppState { pub clock_anchor: ClockAnchor, - pub countdowns: Vec, + pub countdown_service: CountdownService, } impl AppState { pub fn new() -> Self { Self { clock_anchor: ClockAnchor::new(), - countdowns: vec![CountdownService::new()], + countdown_service: CountdownService::default(), } } } diff --git a/src-tauri/src/countdown/service.rs b/src-tauri/src/countdown/service.rs index 1adb186..6f0ff27 100644 --- a/src-tauri/src/countdown/service.rs +++ b/src-tauri/src/countdown/service.rs @@ -7,14 +7,16 @@ use crate::countdown::model::{Countdown, CountdownError}; #[derive(Debug)] pub struct CountdownService { countdown: Mutex, - next_id: u64, } impl CountdownService { - pub fn new() -> Self { + pub fn default() -> Self { + Self::new(0, "Countdown0", Duration::new(600, 0)) + } + + pub fn new(id: u64, label: &str, duration: Duration) -> Self { Self { - countdown: Mutex::new(Countdown::new(0, "Countdown0", Duration::new(600, 0))), - next_id: 1, + countdown: Mutex::new(Countdown::new(id, label, duration)), } }