diff --git a/src/desktop_file.rs b/src/desktop_file.rs index 7df1018..75dfcf0 100644 --- a/src/desktop_file.rs +++ b/src/desktop_file.rs @@ -180,7 +180,7 @@ fn parse_desktop_file(path: &Path) -> Option { .for_each(|(key, value)| { desktop_file .entry(key.to_string()) - .or_insert_with(Vec::new) + .or_default() .push(value.to_string()); }); diff --git a/src/style.rs b/src/style.rs index 668b3dd..9cb15ef 100644 --- a/src/style.rs +++ b/src/style.rs @@ -4,7 +4,7 @@ use glib::Continue; use gtk::ffi::GTK_STYLE_PROVIDER_PRIORITY_USER; use gtk::prelude::CssProviderExt; use gtk::{gdk, gio, CssProvider, StyleContext}; -use notify::event::{DataChange, ModifyKind}; +use notify::event::ModifyKind; use notify::{recommended_watcher, Event, EventKind, RecursiveMode, Result, Watcher}; use std::path::PathBuf; use std::time::Duration; @@ -39,11 +39,17 @@ pub fn load_css(style_path: PathBuf) { let (tx, rx) = glib::MainContext::channel(glib::PRIORITY_DEFAULT); spawn(async move { + let style_path2 = style_path.clone(); let mut watcher = recommended_watcher(move |res: Result| match res { - Ok(event) if event.kind == EventKind::Modify(ModifyKind::Data(DataChange::Any)) => { + Ok(event) if matches!(event.kind, EventKind::Modify(ModifyKind::Data(_))) => { debug!("{event:?}"); - if let Some(path) = event.paths.first() { - send!(tx, path.clone()); + if event + .paths + .first() + .map(|p| p == &style_path2) + .unwrap_or_default() + { + send!(tx, style_path2.clone()); } } Err(e) => error!("Error occurred when watching stylesheet: {:?}", e), @@ -51,8 +57,10 @@ pub fn load_css(style_path: PathBuf) { }) .expect("Failed to create CSS file watcher"); + let dir_path = style_path.parent().expect("to exist"); + watcher - .watch(&style_path, RecursiveMode::NonRecursive) + .watch(dir_path, RecursiveMode::NonRecursive) .expect("Failed to start CSS file watcher"); debug!("Installed CSS file watcher on '{}'", style_path.display());