summaryrefslogtreecommitdiff
path: root/src/services/wallpapers.ts
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-05 17:37:43 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-05 17:37:43 +1100
commitd46b36860666583cd9645bfb1fa28d807973c324 (patch)
tree97148da2ccf623491f5bdef5e998fb54e4574d52 /src/services/wallpapers.ts
parentapp: init services after timeout (diff)
downloadcaelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.tar.gz
caelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.tar.bz2
caelestia-shell-d46b36860666583cd9645bfb1fa28d807973c324.zip
schemes: update for scripts refactor
Diffstat (limited to 'src/services/wallpapers.ts')
-rw-r--r--src/services/wallpapers.ts27
1 files changed, 6 insertions, 21 deletions
diff --git a/src/services/wallpapers.ts b/src/services/wallpapers.ts
index 7d29a14..39bced4 100644
--- a/src/services/wallpapers.ts
+++ b/src/services/wallpapers.ts
@@ -1,5 +1,6 @@
import { basename } from "@/utils/strings";
-import { execAsync, Gio, GLib, GObject, property, register } from "astal";
+import { monitorDirectory } from "@/utils/system";
+import { execAsync, GLib, GObject, property, register } from "astal";
import { wallpapers as config } from "config";
export interface Wallpaper {
@@ -55,28 +56,12 @@ export default class Wallpapers extends GObject.Object {
this.update().catch(console.error);
- const monitorDir = ({ path, recursive }: { path: string; recursive: boolean }) => {
- const file = Gio.file_new_for_path(path.replace("~", HOME));
- const monitor = file.monitor_directory(null, null);
- monitor.connect("changed", () => this.update().catch(console.error));
-
- 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(...monitorDir({ path: `${path}/${child.get_name()}`, recursive }));
- }
-
- return monitors;
- };
-
- let monitors = config.paths.get().flatMap(monitorDir);
+ let monitors = config.paths
+ .get()
+ .flatMap(p => monitorDirectory(p.path, () => this.update().catch(console.error), p.recursive));
config.paths.subscribe(v => {
for (const m of monitors) m.cancel();
- monitors = v.flatMap(monitorDir);
+ monitors = v.flatMap(p => monitorDirectory(p.path, () => this.update().catch(console.error), p.recursive));
});
}
}