Protect live state during restore and reset

This commit is contained in:
Gabriel Brown
2026-08-18 03:10:31 -04:00
parent c2cd79b547
commit 6d3f888784
10 changed files with 212 additions and 17 deletions
+8 -9
View File
@@ -33,6 +33,7 @@ Singleton {
property bool scanning: false
readonly property string configured: DesktopPreferences.get("wallpaperPath")
readonly property string shippedPath: `${Quickshell.env("HOME")}/Pictures/Wallpapers/faroe_islands.jpg`
// Directories searched for wallpapers, in order. Screenshots are
// deliberately excluded: a folder of 300 screenshots is not a wallpaper
@@ -85,6 +86,7 @@ Singleton {
id: apply
property string requested: ""
property string storedValue: ""
property var remaining: []
onExited: (exitCode, exitStatus) => {
@@ -100,7 +102,7 @@ Singleton {
return;
}
root.lastError = "";
DesktopPreferences.set("wallpaperPath", apply.requested);
DesktopPreferences.set("wallpaperPath", apply.storedValue);
root.refreshActive();
}
}
@@ -140,19 +142,16 @@ Singleton {
// Applies to every connected output. Returns false when the path is not one
// the schema will accept, so a caller can report the refusal.
function set(path: string): bool {
if (PreferenceSchema.coerce("wallpaperPath", path) === undefined) {
const effectivePath = path === "" ? root.shippedPath : path;
if (PreferenceSchema.coerce("wallpaperPath", effectivePath) === undefined) {
root.lastError = "That file path cannot be used as a wallpaper.";
return false;
}
if (apply.running)
return false;
apply.requested = path;
// "" clears the preference without touching what is on screen.
if (path === "") {
DesktopPreferences.set("wallpaperPath", "");
return true;
}
apply.requested = effectivePath;
apply.storedValue = path;
const outputs = Quickshell.screens.map(screen => screen.name).filter(name => !!name);
if (outputs.length === 0) {
@@ -161,7 +160,7 @@ Singleton {
}
apply.remaining = outputs.slice(1);
apply.exec(["hyprctl", "hyprpaper", "wallpaper", `${outputs[0]},${path}`]);
apply.exec(["hyprctl", "hyprpaper", "wallpaper", `${outputs[0]},${effectivePath}`]);
return true;
}