summaryrefslogtreecommitdiff
path: root/src/services
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-01 19:08:15 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-03-01 19:08:15 +1100
commit31138ffd9348990fc3221352fc40d48dfcd59141 (patch)
tree14083dcd472354762d4e1c738adada9652ff05de /src/services
parentlauncher: change window colour (diff)
downloadcaelestia-shell-31138ffd9348990fc3221352fc40d48dfcd59141.tar.gz
caelestia-shell-31138ffd9348990fc3221352fc40d48dfcd59141.tar.bz2
caelestia-shell-31138ffd9348990fc3221352fc40d48dfcd59141.zip
launcher: scheme autocomplete
Diffstat (limited to 'src/services')
-rw-r--r--src/services/schemes.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/services/schemes.ts b/src/services/schemes.ts
new file mode 100644
index 0000000..07d6ded
--- /dev/null
+++ b/src/services/schemes.ts
@@ -0,0 +1,44 @@
+import { execAsync, GLib, GObject, monitorFile, property, readFileAsync, register } from "astal";
+import type { IPalette } from "./palette";
+
+const DATA = `${GLib.get_user_data_dir()}/caelestia`;
+
+@register({ GTypeName: "Schemes" })
+export default class Schemes extends GObject.Object {
+ static instance: Schemes;
+ static get_default() {
+ if (!this.instance) this.instance = new Schemes();
+
+ return this.instance;
+ }
+
+ #map: { [k: string]: IPalette } = {};
+
+ @property(Object)
+ get map() {
+ return this.#map;
+ }
+
+ #schemePathToName(path: string) {
+ return path.slice(path.lastIndexOf("/") + 1, path.lastIndexOf("."));
+ }
+
+ async parseScheme(path: string) {
+ const schemeColours = (await readFileAsync(path)).split("\n").map(l => l.split(" "));
+ return schemeColours.reduce((acc, [name, hex]) => ({ ...acc, [name]: `#${hex}` }), {} as IPalette);
+ }
+
+ async update() {
+ const schemes = await execAsync(`find ${DATA}/scripts/data/schemes/ -type f`);
+ for (const scheme of schemes.split("\n"))
+ this.#map[this.#schemePathToName(scheme)] = await this.parseScheme(scheme);
+ this.notify("map");
+ }
+
+ constructor() {
+ super();
+
+ this.update().catch(console.error);
+ monitorFile(`${DATA}/scripts/data/schemes`, () => this.update().catch(console.error));
+ }
+}