perf(wallpaper): use hyprpaper reload instead of unloading, preloading and then setting wallpaper

this is much fastergit add src/modules src/config.ts
This commit is contained in:
retrozinndev
2025-11-11 18:33:58 -03:00
parent 2f106a527e
commit cd8a39fc9f
3 changed files with 32 additions and 33 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ const generalConfigDefaults = {
position_v: "top", position_v: "top",
/** dismisses notification popup when unhovered after hovering /** dismisses notification popup when unhovered after hovering
* @default false */ * @default false */
dismiss_after_unhover: false dismiss_on_unhover: false
}, },
night_light: { night_light: {
+3 -6
View File
@@ -133,8 +133,7 @@ class Config<K extends string, V = any> extends GObject.Object {
public bindProperty(path: string, expectType: "number"): Accessor<number>; public bindProperty(path: string, expectType: "number"): Accessor<number>;
public bindProperty(path: string, expectType: "string"): Accessor<string>; public bindProperty(path: string, expectType: "string"): Accessor<string>;
public bindProperty(path: string, expectType: "object"): Accessor<object>; public bindProperty(path: string, expectType: "object"): Accessor<object>;
public bindProperty(path: string, expectType: "any"): Accessor<any>; public bindProperty(path: string, expectType?: "any"): Accessor<any>;
public bindProperty(path: string, expectType: undefined): Accessor<any>;
public bindProperty(propertyPath: string, expectType?: ValueTypes): Accessor<boolean|number|string|object|any> { public bindProperty(propertyPath: string, expectType?: ValueTypes): Accessor<boolean|number|string|object|any> {
return new Accessor(() => this.getProperty(propertyPath, expectType as never), (callback: () => void) => { return new Accessor(() => this.getProperty(propertyPath, expectType as never), (callback: () => void) => {
@@ -147,8 +146,7 @@ class Config<K extends string, V = any> extends GObject.Object {
public getProperty(path: string, expectType: "number"): number; public getProperty(path: string, expectType: "number"): number;
public getProperty(path: string, expectType: "string"): string; public getProperty(path: string, expectType: "string"): string;
public getProperty(path: string, expectType: "object"): object; public getProperty(path: string, expectType: "object"): object;
public getProperty(path: string, expectType: "any"): any; public getProperty(path: string, expectType?: "any"): any;
public getProperty(path: string, expectType: undefined): any;
public getProperty(path: string, expectType?: ValueTypes): boolean|number|string|object|any { public getProperty(path: string, expectType?: ValueTypes): boolean|number|string|object|any {
return this._getProperty(path, this.#entries, expectType); return this._getProperty(path, this.#entries, expectType);
@@ -158,8 +156,7 @@ class Config<K extends string, V = any> extends GObject.Object {
public getPropertyDefault(path: string, expectType: "number"): number; public getPropertyDefault(path: string, expectType: "number"): number;
public getPropertyDefault(path: string, expectType: "string"): string; public getPropertyDefault(path: string, expectType: "string"): string;
public getPropertyDefault(path: string, expectType: "object"): object; public getPropertyDefault(path: string, expectType: "object"): object;
public getPropertyDefault(path: string, expectType: "any"): any; public getPropertyDefault(path: string, expectType?: "any"): any;
public getPropertyDefault(path: string, expectType: undefined): any;
public getPropertyDefault(path: string, expectType?: ValueTypes): boolean|number|string|object|any { public getPropertyDefault(path: string, expectType?: ValueTypes): boolean|number|string|object|any {
return this._getProperty(path, this.defaults, expectType); return this._getProperty(path, this.defaults, expectType);
+26 -24
View File
@@ -70,7 +70,7 @@ class Wallpaper extends GObject.Object {
@setter(String) @setter(String)
set wallpaper(newValue: string) { this.setWallpaper(newValue); } set wallpaper(newValue: string) { this.setWallpaper(newValue); }
public get wallpapersPath() { return this.#wallpapersPath; } get wallpapersPath() { return this.#wallpapersPath; }
@property(gtype<WallpaperPositioning>(String)) @property(gtype<WallpaperPositioning>(String))
positioning: WallpaperPositioning = "cover"; positioning: WallpaperPositioning = "cover";
@@ -98,6 +98,10 @@ class Wallpaper extends GObject.Object {
generalConfig.bindProperty("wallpaper.color_mode", "string"), generalConfig.bindProperty("wallpaper.color_mode", "string"),
() => { () => {
const mode = generalConfig.getProperty("wallpaper.color_mode", "string"); const mode = generalConfig.getProperty("wallpaper.color_mode", "string");
if(this.colorMode === mode)
return;
if(!mode || (mode !== "darken" && mode !== "lighten")) { if(!mode || (mode !== "darken" && mode !== "lighten")) {
Notifications.getDefault().sendNotification({ Notifications.getDefault().sendNotification({
appName: "colorshell", appName: "colorshell",
@@ -118,6 +122,9 @@ class Wallpaper extends GObject.Object {
const positioning = generalConfig const positioning = generalConfig
.getProperty("wallpaper.positioning", "string") as WallpaperPositioning; .getProperty("wallpaper.positioning", "string") as WallpaperPositioning;
if(this.positioning === positioning)
return;
if(!positioning || (positioning !== "contain" && if(!positioning || (positioning !== "contain" &&
positioning !== "cover" && positioning !== "cover" &&
positioning !== "tile")) { positioning !== "tile")) {
@@ -125,7 +132,7 @@ class Wallpaper extends GObject.Object {
Notifications.getDefault().sendNotification({ Notifications.getDefault().sendNotification({
appName: "colorshell", appName: "colorshell",
summary: "Couldn't update wallpaper position", 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; return;
} }
@@ -165,11 +172,13 @@ class Wallpaper extends GObject.Object {
} }
// success // 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} preload = ${this.#wallpaper}
splash = ${this.#splash} 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) => { GLib.PRIORITY_DEFAULT, null, (_, asyncRes) => {
if(_!.write_finish(asyncRes)) res.flush(null); if(_!.write_finish(asyncRes)) res.flush(null);
res.close(null); res.close(null);
@@ -187,18 +196,15 @@ class Wallpaper extends GObject.Object {
} }
public async getWallpaper(): Promise<string|undefined> { public async getWallpaper(): Promise<string|undefined> {
return await execAsync("hyprctl hyprpaper listactive").then(stdout => { return await execAsync("sh -c \"hyprctl hyprpaper listactive | tail -n 1\"").then(stdout => {
const lineSplit = stdout.split('\n');
stdout = lineSplit[lineSplit.length - 1];
const loaded = stdout.split('=')[1]?.trim(); const loaded = stdout.split('=')[1]?.trim();
if(!loaded) if(!loaded)
console.warn(`Wallpaper: Couldn't get wallpaper. There is(are) no loaded wallpaper(s)`); console.warn(`Wallpaper: Couldn't get wallpaper. There is(are) no loaded wallpaper(s)`);
return loaded; return loaded;
}).catch((err: Error) => { }).catch((e: Error) => {
console.error(`Wallpaper: Couldn't get wallpaper. Stderr: \n${err.message}`); console.error(`Wallpaper: Couldn't get wallpaper. Stderr: \n${e.message}`);
return undefined; return undefined;
}); });
} }
@@ -215,29 +221,25 @@ class Wallpaper extends GObject.Object {
if(this.wallpaper.trim() === "") if(this.wallpaper.trim() === "")
return; return;
await execAsync(`hyprctl hyprpaper wallpaper \", ${this.positioning}:${this.wallpaper}\"`); await execAsync(`hyprctl hyprpaper reload \", ${
this.reloadColors(); this.positioning === "cover" ? "" : `${this.positioning}:`
}${this.wallpaper}\"`);
write && this.writeChanges(); write && this.writeChanges();
} }
public setWallpaper(path: string|Gio.File, write: boolean = true): void { public setWallpaper(path: string|Gio.File, write: boolean = true): void {
path = typeof path === "string" ? path : path.peek_path()!; path = typeof path === "string" ? path : path.peek_path()!;
execAsync("hyprctl hyprpaper unload all").then(() => if(!GLib.file_test(path, GLib.FileTest.EXISTS)) {
execAsync(`hyprctl hyprpaper preload ${path}`).then(() => console.error("Wallpaper: file does not exist, skipped");
execAsync(`hyprctl hyprpaper wallpaper \", ${this.positioning}:${path}\"`).then(() => { return;
}
this.#wallpaper = path; this.#wallpaper = path;
this.reloadColors(); this.reloadWallpaper(write).catch((e: Error) => {
write && this.writeChanges();
}).catch((e: Error) => {
console.error(`Wallpaper: Couldn't set wallpaper. Stderr: ${e.message}`); 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}`);
}); });
this.reloadColors();
} }
public async pickWallpaper(): Promise<string|undefined> { public async pickWallpaper(): Promise<string|undefined> {