From 976dd6c55a5881b2b3c60c6d7e13b0e7d4301599 Mon Sep 17 00:00:00 2001 From: Jake Stanger Date: Wed, 24 Jan 2024 22:40:10 +0000 Subject: [PATCH] fix(style): file watcher not working for relative paths Fixes that changes were not hot-loaded when overriding the default style path with `IRONBAR_CSS` and providing a relative file path. --- src/style.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/style.rs b/src/style.rs index 39b7a1f5..2f9f4976 100644 --- a/src/style.rs +++ b/src/style.rs @@ -5,6 +5,7 @@ use gtk::prelude::CssProviderExt; use gtk::{gdk, gio, CssProvider, StyleContext}; use notify::event::ModifyKind; use notify::{recommended_watcher, Event, EventKind, RecursiveMode, Result, Watcher}; +use std::env; use std::path::PathBuf; use std::time::Duration; use tokio::sync::mpsc; @@ -17,6 +18,13 @@ use tracing::{debug, error, info}; /// Installs a file watcher and reloads CSS when /// write changes are detected on the file. pub fn load_css(style_path: PathBuf) { + // file watcher requires absolute path + let style_path = if style_path.is_absolute() { + style_path + } else { + env::current_dir().expect("to exist").join(style_path) + }; + let provider = CssProvider::new(); match provider.load_from_file(&gio::File::for_path(&style_path)) {