diff options
Diffstat (limited to 'src/pomo/mod.rs')
| -rw-r--r-- | src/pomo/mod.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/pomo/mod.rs b/src/pomo/mod.rs index d1043e8..2ccecbb 100644 --- a/src/pomo/mod.rs +++ b/src/pomo/mod.rs @@ -72,6 +72,26 @@ impl Pomo { Ok(()) } + pub fn check_theme_reload(&mut self) { + if let Some(base_dirs) = directories::BaseDirs::new() { + let matugen_path = base_dirs.home_dir().join(".cache/pomoru/colors.json"); + let legacy_path = base_dirs.home_dir().join(".config/noctalia/colors.json"); + + let current_mtime = fs::metadata(&matugen_path) + .or_else(|_| fs::metadata(&legacy_path)) + .and_then(|m| m.modified()) + .ok(); + + if current_mtime.is_some() && current_mtime != self.theme_mtime { + let (new_theme, new_mtime) = state::Theme::load_with_mtime(); + if new_mtime.is_some() { + self.theme = new_theme; + self.theme_mtime = new_mtime; + } + } + } + } + pub fn save(&self) -> Result<(), Box<dyn std::error::Error>> { let config = Config { work_time_mins: self.work_time.as_secs() / 60, @@ -118,6 +138,7 @@ impl Pomo { let mut terminal = Terminal::new(backend)?; let mut second_tick = tokio::time::interval(Duration::from_secs(1)); + let mut theme_tick = tokio::time::interval(Duration::from_millis(100)); let _ = self.export_status(); @@ -130,6 +151,10 @@ impl Pomo { let _ = self.export_status(); } + _ = theme_tick.tick() => { + self.check_theme_reload(); + } + // Tighten poll to 16ms (~60fps feel) for input responsiveness event_res = tokio::task::spawn_blocking(|| event::poll(Duration::from_millis(16))) => { if let Ok(Ok(true)) = event_res |