summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-23 20:00:27 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-23 20:00:27 +1100
commit431918b75253292e03fda49afcdb1c555af9e086 (patch)
tree36b1dc7c76d69067f9c43b15ca6e95a9391d359d
parentschemes: fix previews not updating (diff)
downloadcaelestia-shell-431918b75253292e03fda49afcdb1c555af9e086.tar.gz
caelestia-shell-431918b75253292e03fda49afcdb1c555af9e086.tar.bz2
caelestia-shell-431918b75253292e03fda49afcdb1c555af9e086.zip
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
-rw-r--r--src/services/schemes.ts29
-rw-r--r--src/utils/system.ts17
2 files changed, 37 insertions, 9 deletions
diff --git a/src/services/schemes.ts b/src/services/schemes.ts
index 7daef5b..548975c 100644
--- a/src/services/schemes.ts
+++ b/src/services/schemes.ts
@@ -1,6 +1,6 @@
import { basename } from "@/utils/strings";
import { monitorDirectory } from "@/utils/system";
-import { execAsync, GLib, GObject, property, readFileAsync, register } from "astal";
+import { execAsync, Gio, GLib, GObject, property, readFileAsync, register } from "astal";
import type { IPalette } from "./palette";
export interface Colours {
@@ -80,10 +80,25 @@ export default class Schemes extends GObject.Object {
async update() {
const schemes = await execAsync(`find ${this.#schemeDir}/ -mindepth 1 -maxdepth 1 -type d`);
- for (const scheme of schemes.split("\n")) {
- const name = basename(scheme);
- this.#map[name] = await this.parseScheme(name);
- }
+ (await Promise.all(schemes.split("\n").map(s => this.parseScheme(basename(s))))).forEach(
+ s => (this.#map[s.name] = s)
+ );
+ this.notify("map");
+ }
+
+ async updateFile(file: Gio.File) {
+ if (file.get_basename() !== "light.txt" && file.get_basename() !== "dark.txt") return;
+
+ const mode = file.get_basename()!.slice(0, -4) as "light" | "dark";
+ const parent = file.get_parent()!;
+ const parentParent = parent.get_parent()!;
+
+ if (parentParent.get_basename() === "schemes")
+ this.#map[parent.get_basename()!].colours![mode] = await this.parseMode(file.get_path()!);
+ else
+ this.#map[parentParent.get_basename()!].flavours![parent.get_basename()!].colours![mode] =
+ await this.parseMode(file.get_path()!);
+
this.notify("map");
}
@@ -91,6 +106,8 @@ export default class Schemes extends GObject.Object {
super();
this.update().catch(console.error);
- this.#monitor = monitorDirectory(this.#schemeDir, () => this.update().catch(console.error), true);
+ this.#monitor = monitorDirectory(this.#schemeDir, (_m, file, _f, type) => {
+ if (type !== Gio.FileMonitorEvent.DELETED) this.updateFile(file).catch(console.error);
+ });
}
}
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);