From 312ff9ec5a2bfa443f19e2a2083be3bf22386c35 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Wed, 25 Jun 2025 16:09:01 -0300 Subject: [PATCH] :boom: fix(scripts/config): can't assign values because entries are frozen --- ags/scripts/config.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/ags/scripts/config.ts b/ags/scripts/config.ts index ec7dd50..80ff6d4 100644 --- a/ags/scripts/config.ts +++ b/ags/scripts/config.ts @@ -48,7 +48,7 @@ class Config extends GObject.Object implements Subscribable { private readonly defaultFile = Gio.File.new_for_path( `${GLib.get_user_config_dir()}/colorshell/config.json`); - /** Frozen-object(immutable) with default entries. User-values are stored + /** unmodified object with default entries. User-values are stored * in the `entries` field */ public readonly defaults: ConfigEntries = { notifications: { @@ -82,8 +82,6 @@ class Config extends GObject.Object implements Subscribable { constructor(filePath?: (Gio.File|string)) { super(); - Object.freeze(this.defaults); - this.#file = (typeof filePath === "string") ? Gio.File.new_for_path(filePath) : (filePath ?? this.defaultFile); @@ -173,6 +171,14 @@ class Config extends GObject.Object implements Subscribable { } this.notifySubs(); + }).catch((e: Gio.IOErrorEnum) => { + Notifications.getDefault().sendNotification({ + urgency: AstalNotifd.Urgency.NORMAL, + appName: "colorshell", + summary: "Config read error", + body: `An error occurred while reading colorshell's config file: \nFile: ${`${ + this.#file.get_path()!}\n${e.message ? `${e.message}\n` : ""}${e.stack}`.replace(/[<>]/g, "\\&")}` + }); }); } @@ -195,35 +201,26 @@ class Config extends GObject.Object implements Subscribable { return this._getProperty(path, this.defaults, expectType); } - private _getProperty(propertyPath: string, entries: ConfigEntries, expectType?: ValueTypes): (any|undefined) { + private _getProperty(path: string, entries: ConfigEntries, expectType?: ValueTypes): (any|undefined) { let property: any = entries; - const pathArray = propertyPath.split('.').filter(str => str); + const pathArray = path.split('.').filter(str => str); for(let i = 0; i < pathArray.length; i++) { - const path = propertyPath[i]; + const currentPath = pathArray[i]; - if(i < pathArray.length-2 && property?.[path] === undefined) { - console.error(`Config: property with path \`${ - pathArray.filter((_, idx) => idx <= i).join('.') - }\` either could not be found in config entries or its value is \`undefined\`, returning default value`); - - property = undefined; - break; - } - - property = property[path as keyof typeof property]; + property = property[currentPath as keyof typeof property]; } if(expectType !== "any" && typeof property !== expectType) { - console.error(`Config: property with path \`${propertyPath + console.error(`Config: property with path \`${path }\` is either \`undefined\` or not in the expected value type \`${expectType }\`, returning default value`); - property = this.getPropertyDefault(propertyPath); + property = this.getPropertyDefault(path); } if(expectType !== "any" && typeof property !== expectType) { - console.error(`Config: property with path \`${propertyPath}\` not found in defaults/user-entries, returning \`undefined\``); + console.error(`Config: property with path \`${path}\` not found in defaults/user-entries, returning \`undefined\``); property = undefined; }