diff options
Diffstat (limited to 'src/utils/system.ts')
| -rw-r--r-- | src/utils/system.ts | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/utils/system.ts b/src/utils/system.ts index 7ae23dd..d0470c7 100644 --- a/src/utils/system.ts +++ b/src/utils/system.ts @@ -1,4 +1,4 @@ -import { bind, execAsync, GLib, Variable, type Binding, type Gio } from "astal"; +import { bind, execAsync, Gio, GLib, Variable, type Binding } from "astal"; import type AstalApps from "gi://AstalApps"; import { osIcons } from "./icons"; @@ -75,3 +75,21 @@ export const bindCurrentTime = ( self?.connect("destroy", () => time.drop()); return bind(time); }; + +export const monitorDirectory = (path: string, callback: (path: string) => void, recursive?: boolean) => { + const file = Gio.file_new_for_path(path.replace("~", HOME)); + const monitor = file.monitor_directory(null, null); + monitor.connect("changed", callback); + + const monitors = [monitor]; + + if (recursive) { + const enumerator = file.enumerate_children("standard::*", null, null); + let child; + while ((child = enumerator.next_file(null))) + if (child.get_file_type() === Gio.FileType.DIRECTORY) + monitors.push(...monitorDirectory(`${path}/${child.get_name()}`, callback, recursive)); + } + + return monitors; +}; |