⚡ 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:
+28
-26
@@ -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<WallpaperPositioning>(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<string|undefined> {
|
||||
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<string|undefined> {
|
||||
|
||||
Reference in New Issue
Block a user