diff --git a/src/config.ts b/src/config.ts index 9214363..8d3de55 100644 --- a/src/config.ts +++ b/src/config.ts @@ -23,7 +23,7 @@ const generalConfigDefaults = { position_v: "top", /** dismisses notification popup when unhovered after hovering * @default false */ - dismiss_after_unhover: false + dismiss_on_unhover: false }, night_light: { diff --git a/src/modules/config.ts b/src/modules/config.ts index e79fa7b..9635c72 100644 --- a/src/modules/config.ts +++ b/src/modules/config.ts @@ -133,8 +133,7 @@ class Config extends GObject.Object { public bindProperty(path: string, expectType: "number"): Accessor; public bindProperty(path: string, expectType: "string"): Accessor; public bindProperty(path: string, expectType: "object"): Accessor; - public bindProperty(path: string, expectType: "any"): Accessor; - public bindProperty(path: string, expectType: undefined): Accessor; + public bindProperty(path: string, expectType?: "any"): Accessor; public bindProperty(propertyPath: string, expectType?: ValueTypes): Accessor { return new Accessor(() => this.getProperty(propertyPath, expectType as never), (callback: () => void) => { @@ -147,8 +146,7 @@ class Config extends GObject.Object { public getProperty(path: string, expectType: "number"): number; public getProperty(path: string, expectType: "string"): string; public getProperty(path: string, expectType: "object"): object; - public getProperty(path: string, expectType: "any"): any; - public getProperty(path: string, expectType: undefined): any; + public getProperty(path: string, expectType?: "any"): any; public getProperty(path: string, expectType?: ValueTypes): boolean|number|string|object|any { return this._getProperty(path, this.#entries, expectType); @@ -158,8 +156,7 @@ class Config extends GObject.Object { public getPropertyDefault(path: string, expectType: "number"): number; public getPropertyDefault(path: string, expectType: "string"): string; public getPropertyDefault(path: string, expectType: "object"): object; - public getPropertyDefault(path: string, expectType: "any"): any; - public getPropertyDefault(path: string, expectType: undefined): any; + public getPropertyDefault(path: string, expectType?: "any"): any; public getPropertyDefault(path: string, expectType?: ValueTypes): boolean|number|string|object|any { return this._getProperty(path, this.defaults, expectType); diff --git a/src/modules/wallpaper.ts b/src/modules/wallpaper.ts index 4f7feed..b785d64 100644 --- a/src/modules/wallpaper.ts +++ b/src/modules/wallpaper.ts @@ -70,7 +70,7 @@ class Wallpaper extends GObject.Object { @setter(String) set wallpaper(newValue: string) { this.setWallpaper(newValue); } - public get wallpapersPath() { return this.#wallpapersPath; } + get wallpapersPath() { return this.#wallpapersPath; } @property(gtype(String)) positioning: WallpaperPositioning = "cover"; @@ -98,6 +98,10 @@ class Wallpaper extends GObject.Object { generalConfig.bindProperty("wallpaper.color_mode", "string"), () => { const mode = generalConfig.getProperty("wallpaper.color_mode", "string"); + + if(this.colorMode === mode) + return; + if(!mode || (mode !== "darken" && mode !== "lighten")) { Notifications.getDefault().sendNotification({ appName: "colorshell", @@ -118,6 +122,9 @@ class Wallpaper extends GObject.Object { const positioning = generalConfig .getProperty("wallpaper.positioning", "string") as WallpaperPositioning; + if(this.positioning === positioning) + return; + if(!positioning || (positioning !== "contain" && positioning !== "cover" && positioning !== "tile")) { @@ -125,7 +132,7 @@ class Wallpaper extends GObject.Object { Notifications.getDefault().sendNotification({ appName: "colorshell", summary: "Couldn't update wallpaper position", - body: "Invalid position value. Possible values are: \"cover\", \"contain\" or \"tile\"" + body: "Invalid position value. Possible values are: \"cover\"(default), \"contain\" or \"tile\"" }); return; } @@ -165,11 +172,13 @@ class Wallpaper extends GObject.Object { } // success - res.write_bytes_async(encoder.encode(`# This file was automatically generated by color-shell + res.write_bytes_async(encoder.encode(`\ + # This file was automatically generated by colorshell preload = ${this.#wallpaper} splash = ${this.#splash} - wallpaper = , ${this.#wallpaper}`.split('\n').map(str => str.trimStart()).join('\n')), + wallpaper = , ${this.positioning === "cover" ? "" : `${this.positioning}:`}${ + this.#wallpaper}`.split('\n').map(str => str.trimStart()).join('\n')), GLib.PRIORITY_DEFAULT, null, (_, asyncRes) => { if(_!.write_finish(asyncRes)) res.flush(null); res.close(null); @@ -187,18 +196,15 @@ class Wallpaper extends GObject.Object { } public async getWallpaper(): Promise { - return await execAsync("hyprctl hyprpaper listactive").then(stdout => { - const lineSplit = stdout.split('\n'); - stdout = lineSplit[lineSplit.length - 1]; - + return await execAsync("sh -c \"hyprctl hyprpaper listactive | tail -n 1\"").then(stdout => { const loaded = stdout.split('=')[1]?.trim(); if(!loaded) console.warn(`Wallpaper: Couldn't get wallpaper. There is(are) no loaded wallpaper(s)`); return loaded; - }).catch((err: Error) => { - console.error(`Wallpaper: Couldn't get wallpaper. Stderr: \n${err.message}`); + }).catch((e: Error) => { + console.error(`Wallpaper: Couldn't get wallpaper. Stderr: \n${e.message}`); return undefined; }); } @@ -215,29 +221,25 @@ class Wallpaper extends GObject.Object { if(this.wallpaper.trim() === "") return; - await execAsync(`hyprctl hyprpaper wallpaper \", ${this.positioning}:${this.wallpaper}\"`); - this.reloadColors(); + await execAsync(`hyprctl hyprpaper reload \", ${ + this.positioning === "cover" ? "" : `${this.positioning}:` + }${this.wallpaper}\"`); write && this.writeChanges(); } public setWallpaper(path: string|Gio.File, write: boolean = true): void { path = typeof path === "string" ? path : path.peek_path()!; - execAsync("hyprctl hyprpaper unload all").then(() => - execAsync(`hyprctl hyprpaper preload ${path}`).then(() => - execAsync(`hyprctl hyprpaper wallpaper \", ${this.positioning}:${path}\"`).then(() => { - this.#wallpaper = path; - this.reloadColors(); - write && this.writeChanges(); - }).catch((e: Error) => { - console.error(`Wallpaper: Couldn't set wallpaper. Stderr: ${e.message}`); - }) - ).catch((e: Error) => { - console.error(`Wallpaper: Couldn't preload image. Stderr: ${e.message}`); - }) - ).catch((e: Error) => { - console.error(`Wallpaper: Couldn't unload images from memory. Stderr: ${e.message}`); + if(!GLib.file_test(path, GLib.FileTest.EXISTS)) { + console.error("Wallpaper: file does not exist, skipped"); + return; + } + + this.#wallpaper = path; + this.reloadWallpaper(write).catch((e: Error) => { + console.error(`Wallpaper: Couldn't set wallpaper. Stderr: ${e.message}`); }); + this.reloadColors(); } public async pickWallpaper(): Promise {