mirror of
https://github.com/JakeStanger/ironbar.git
synced 2024-11-27 02:54:33 +03:00
Merge pull request #336 from JakeStanger/fix/vim-style-watcher
Fix style hot reloading when editing with Vim
This commit is contained in:
commit
8fc516a85d
@ -180,7 +180,7 @@ fn parse_desktop_file(path: &Path) -> Option<DesktopFile> {
|
||||
.for_each(|(key, value)| {
|
||||
desktop_file
|
||||
.entry(key.to_string())
|
||||
.or_insert_with(Vec::new)
|
||||
.or_default()
|
||||
.push(value.to_string());
|
||||
});
|
||||
|
||||
|
18
src/style.rs
18
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<Event>| 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());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user