💥 fix(modules/wallpaper): add module-specific scope

This commit is contained in:
retrozinndev
2025-11-11 16:47:50 -03:00
parent b0956e24c5
commit 2f106a527e
+54 -44
View File
@@ -7,6 +7,7 @@ import GLib from "gi://GLib?version=2.0";
import { createSubscription, encoder } from "./utils"; import { createSubscription, encoder } from "./utils";
import { Notifications } from "./notifications"; import { Notifications } from "./notifications";
import { generalConfig } from "../config"; import { generalConfig } from "../config";
import { createRoot, getScope, Scope } from "ags";
export { Wallpaper }; export { Wallpaper };
@@ -50,6 +51,7 @@ export type WallpaperPositioning = "contain"|"tile"|"cover";
class Wallpaper extends GObject.Object { class Wallpaper extends GObject.Object {
private static instance: Wallpaper; private static instance: Wallpaper;
#wallpaper: (string|undefined); #wallpaper: (string|undefined);
#scope!: Scope;
#splash: boolean = true; #splash: boolean = true;
#hyprpaperFile: Gio.File; #hyprpaperFile: Gio.File;
#wallpapersPath: string; #wallpapersPath: string;
@@ -70,8 +72,8 @@ class Wallpaper extends GObject.Object {
public get wallpapersPath() { return this.#wallpapersPath; } public get wallpapersPath() { return this.#wallpapersPath; }
@property(gtype<WallpaperMode>(String)) @property(gtype<WallpaperPositioning>(String))
positioning: WallpaperMode = "cover"; positioning: WallpaperPositioning = "cover";
@property(gtype<WalMode>(String)) @property(gtype<WalMode>(String))
colorMode: WalMode = "darken"; colorMode: WalMode = "darken";
@@ -89,52 +91,60 @@ class Wallpaper extends GObject.Object {
if(wall?.trim()) this.#wallpaper = wall.trim(); if(wall?.trim()) this.#wallpaper = wall.trim();
}); });
createSubscription( createRoot(() => {
generalConfig.bindProperty("wallpaper.color_mode", "string"), this.#scope = getScope();
() => {
const mode = generalConfig.getProperty("wallpaper.color_mode", "string");
if(!mode || (mode !== "darken" && mode !== "lighten")) {
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't update color mode",
body: "Invalid mode. Possible values are: \"darken\" or \"lighten\""
});
return;
};
this.colorMode = mode as WalMode; createSubscription(
this.reloadColors(); generalConfig.bindProperty("wallpaper.color_mode", "string"),
} () => {
); const mode = generalConfig.getProperty("wallpaper.color_mode", "string");
if(!mode || (mode !== "darken" && mode !== "lighten")) {
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't update color mode",
body: "Invalid mode. Possible values are: \"darken\" or \"lighten\""
});
return;
};
createSubscription( this.colorMode = mode as WalMode;
generalConfig.bindProperty("wallpaper.positioning", "string"), this.reloadColors();
() => {
const positioning = generalConfig
.getProperty("wallpaper.positioning", "string") as WallpaperPositioning;
if(!positioning || (positioning !== "contain" &&
positioning !== "cover" &&
positioning !== "tile")) {
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't update wallpaper position",
body: "Invalid position value. Possible values are: \"cover\", \"contain\" or \"tile\""
});
return;
} }
);
this.positioning = positioning; createSubscription(
this.reloadWallpaper().catch((e: Error) => generalConfig.bindProperty("wallpaper.positioning", "string"),
Notifications.getDefault().sendNotification({ () => {
appName: "colorshell", const positioning = generalConfig
summary: "Couldn't update wallpaper position", .getProperty("wallpaper.positioning", "string") as WallpaperPositioning;
body: `An error occurred while updating wallpaper's position: ${e.message}`
}) if(!positioning || (positioning !== "contain" &&
); positioning !== "cover" &&
} positioning !== "tile")) {
);
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't update wallpaper position",
body: "Invalid position value. Possible values are: \"cover\", \"contain\" or \"tile\""
});
return;
}
this.positioning = positioning;
this.reloadWallpaper().catch((e: Error) =>
Notifications.getDefault().sendNotification({
appName: "colorshell",
summary: "Couldn't update wallpaper position",
body: `An error occurred while updating wallpaper's position: ${e.message}`
})
);
}
);
});
}
vfunc_dispose(): void {
this.#scope?.dispose();
} }
public static getDefault(): Wallpaper { public static getDefault(): Wallpaper {