aboutsummaryrefslogtreecommitdiff
path: root/src/pomo
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-09-11 23:53:29 +0530
committerGitHub <noreply@github.com>2026-09-11 23:53:29 +0530
commit8672d041bec1a3c80da95adbfb5d0f974a97f84b (patch)
tree41c5a0e5e6bcf13b1aa895ab3260a471824d4901 /src/pomo
parent978bdc8d8a1a4dd50e1f539d89764a44d995a2d2 (diff)
parentb885efbf21f2839318a46e484654e706821b716e (diff)
downloadpomoru-1.2.0.tar.xz
pomoru-1.2.0.zip
Merge pull request #9 from RanXom/feat/hot-reload-themev1.2.0
Feat/hot-reload-theme: Noctalia v5 (matugen) theming support & smooth hot-reloading
Diffstat (limited to 'src/pomo')
-rw-r--r--src/pomo/mod.rs25
-rw-r--r--src/pomo/state.rs102
2 files changed, 104 insertions, 23 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
diff --git a/src/pomo/state.rs b/src/pomo/state.rs
index 83e2038..5be19bb 100644
--- a/src/pomo/state.rs
+++ b/src/pomo/state.rs
@@ -12,9 +12,21 @@ pub struct Theme {
pub text: Color,
}
+/// Color format rendered by noctalia v5's matugen template system.
+/// Pomoru reads this from `~/.cache/pomoru/colors.json` when available.
+#[derive(Deserialize)]
+struct MatugenColors {
+ primary: String,
+ on_surface_variant: String,
+ surface_container: String,
+ on_surface: String,
+}
+
+/// Legacy color format from `~/.config/noctalia/colors.json` (noctalia < v5).
+/// Kept for backward compatibility.
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
-struct NoctaliaColors {
+struct LegacyNoctaliaColors {
m_primary: String,
m_on_surface_variant: String,
m_surface_variant: String,
@@ -22,18 +34,20 @@ struct NoctaliaColors {
}
fn parse_hex_color(hex: &str) -> Option<Color> {
- if hex.len() == 7 && hex.starts_with('#') {
- let r = u8::from_str_radix(&hex[1..3], 16).ok()?;
- let g = u8::from_str_radix(&hex[3..5], 16).ok()?;
- let b = u8::from_str_radix(&hex[5..7], 16).ok()?;
+ let hex = hex.trim_start_matches('#');
+ if hex.len() == 6 {
+ let r = u8::from_str_radix(&hex[0..2], 16).ok()?;
+ let g = u8::from_str_radix(&hex[2..4], 16).ok()?;
+ let b = u8::from_str_radix(&hex[4..6], 16).ok()?;
Some(Color::Rgb(r, g, b))
} else {
None
}
}
-impl Default for Theme {
- fn default() -> Self {
+impl Theme {
+ pub fn load_with_mtime() -> (Self, Option<std::time::SystemTime>) {
+ // Catppuccin Mocha defaults — used when no theme file is present.
let mut theme = Self {
primary: Color::Rgb(180, 190, 254),
overlay0: Color::Rgb(108, 112, 134),
@@ -42,25 +56,64 @@ impl Default for Theme {
};
if let Some(base_dirs) = BaseDirs::new() {
- let path = base_dirs.home_dir().join(".config/noctalia/colors.json");
- if let Ok(content) = fs::read_to_string(&path)
- && let Ok(colors) = serde_json::from_str::<NoctaliaColors>(&content)
- {
- if let Some(c) = parse_hex_color(&colors.m_primary) {
- theme.primary = c;
- }
- if let Some(c) = parse_hex_color(&colors.m_on_surface_variant) {
- theme.overlay0 = c;
- }
- if let Some(c) = parse_hex_color(&colors.m_surface_variant) {
- theme.surface0 = c;
+ // --- Priority 1: matugen / noctalia v5 rendered colors ---
+ let matugen_path = base_dirs
+ .home_dir()
+ .join(".cache/pomoru/colors.json");
+
+ if let Ok(metadata) = fs::metadata(&matugen_path) {
+ if let Ok(content) = fs::read_to_string(&matugen_path)
+ && let Ok(colors) = serde_json::from_str::<MatugenColors>(&content)
+ {
+ if let Some(c) = parse_hex_color(&colors.primary) {
+ theme.primary = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.on_surface_variant) {
+ theme.overlay0 = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.surface_container) {
+ theme.surface0 = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.on_surface) {
+ theme.text = c;
+ }
+ return (theme, metadata.modified().ok());
}
- if let Some(c) = parse_hex_color(&colors.m_on_surface) {
- theme.text = c;
+ }
+
+ // --- Priority 2: legacy noctalia colors.json (noctalia < v5) ---
+ let legacy_path = base_dirs
+ .home_dir()
+ .join(".config/noctalia/colors.json");
+
+ if let Ok(metadata) = fs::metadata(&legacy_path) {
+ if let Ok(content) = fs::read_to_string(&legacy_path)
+ && let Ok(colors) = serde_json::from_str::<LegacyNoctaliaColors>(&content)
+ {
+ if let Some(c) = parse_hex_color(&colors.m_primary) {
+ theme.primary = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.m_on_surface_variant) {
+ theme.overlay0 = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.m_surface_variant) {
+ theme.surface0 = c;
+ }
+ if let Some(c) = parse_hex_color(&colors.m_on_surface) {
+ theme.text = c;
+ }
+ return (theme, metadata.modified().ok());
}
}
}
- theme
+
+ (theme, None)
+ }
+}
+
+impl Default for Theme {
+ fn default() -> Self {
+ Theme::load_with_mtime().0
}
}
@@ -130,11 +183,13 @@ pub struct Pomo {
pub input_buffer: String,
pub should_quit: bool,
pub theme: Theme,
+ pub theme_mtime: Option<std::time::SystemTime>,
}
impl Pomo {
pub fn new() -> Self {
let work = Duration::from_secs(25 * 60);
+ let (theme, theme_mtime) = Theme::load_with_mtime();
Self {
screen: AppScreen::Timer,
mode: SessionMode::Work,
@@ -151,7 +206,8 @@ impl Pomo {
task_state: ListState::default(),
input_buffer: String::new(),
should_quit: false,
- theme: Theme::default(),
+ theme,
+ theme_mtime,
}
}