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 | |
| 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')
| -rw-r--r-- | src/utils/strings.ts | 6 | ||||
| -rw-r--r-- | src/utils/system.ts | 20 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/utils/strings.ts b/src/utils/strings.ts index 2fd4c76..c2bf71a 100644 --- a/src/utils/strings.ts +++ b/src/utils/strings.ts @@ -1,3 +1,7 @@ export const ellipsize = (str: string, len: number) => (str.length > len ? `${str.slice(0, len - 1)}…` : str); -export const basename = (path: string) => path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf(".")); +export const basename = (path: string) => { + const lastSlash = path.lastIndexOf("/"); + const lastDot = path.lastIndexOf("."); + return path.slice(lastSlash + 1, lastDot > lastSlash ? lastDot : undefined); +}; 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; +}; |