From 431918b75253292e03fda49afcdb1c555af9e086 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 23 Mar 2025 20:00:27 +1100 Subject: schemes: fix updating taking ages Cause it was being called for every file change So instead of updating all, just update changed Also async update all --- src/utils/system.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/utils/system.ts') diff --git a/src/utils/system.ts b/src/utils/system.ts index 518fb9a..2e9fa4a 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -76,10 +76,21 @@ export const bindCurrentTime = ( return bind(time); }; -export const monitorDirectory = (path: string, callback: (path: string) => void, recursive?: boolean) => { +export const monitorDirectory = ( + path: string, + callback: ( + source: Gio.FileMonitor, + file: Gio.File, + other_file: Gio.File | null, + type: Gio.FileMonitorEvent + ) => void, + recursive: boolean = true +) => { const file = Gio.file_new_for_path(path.replace("~", HOME)); - const monitor = file.monitor_directory(Gio.FileMonitorFlags.WATCH_MOUNTS | Gio.FileMonitorFlags.WATCH_MOVES, null); - monitor.connect("changed", callback); + const monitor = file.monitor_directory(null, null); + monitor.connect("changed", (m, f1, f2, t) => { + if (t === Gio.FileMonitorEvent.CHANGES_DONE_HINT || t === Gio.FileMonitorEvent.DELETED) callback(m, f1, f2, t); + }); if (recursive) { const enumerator = file.enumerate_children("standard::*", null, null); -- cgit v1.2.3-freya