Skip to content

Commit

Permalink
Merge pull request #416 from JakeStanger/fix/style-watcher
Browse files Browse the repository at this point in the history
fix(style): file watcher not working for relative paths
  • Loading branch information
JakeStanger authored Jan 24, 2024
2 parents 5daeb29 + 976dd6c commit a2a7e2e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit a2a7e2e

Please sign in to comment.