diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-05 17:37:43 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-03-05 17:37:43 +1100 |
| commit | d46b36860666583cd9645bfb1fa28d807973c324 (patch) | |
| tree | 97148da2ccf623491f5bdef5e998fb54e4574d52 /src/utils/system.ts | |
| parent | app: init services after timeout (diff) | |
| download | caelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.tar.gz caelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.tar.bz2 caelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.zip | |
schemes: update for scripts refactor
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; +}; |