Files
dotfiles/quickshell/services/Wallpapers.qml
T
2026-11-17 18:15:16 +07:00

45 lines
1.6 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import "WallpaperPolicy.js" as Policy
Singleton {
id: root
property var states: ({})
property string error: ""
Connections {
target: Quickshell
function onScreensChanged() {
const names = Quickshell.screens.map(s => s.name);
Object.keys(root.states).filter(name => !names.includes(name)).forEach(name => root.forget(name));
}
}
function sourceFor(output) { return Policy.sourceFor(Preferences.data.wallpapers, output); }
function set(output, path) {
if (!Preferences.writable) { error = Preferences.error || "Настройки пока недоступны"; return false; }
try {
const next = Object.assign({}, Preferences.data.wallpapers || {});
next[output] = Policy.localUrl(path);
Policy.validate(next);
Preferences.setValue("wallpapers", next);
error = "";
return true;
} catch (e) { error = String(e); return false; }
}
function inherit(output) {
const next = Object.assign({}, Preferences.data.wallpapers || {});
delete next[output];
Preferences.setValue("wallpapers", next);
}
function report(output, source, state, displayed) {
const next = Object.assign({}, states);
next[output] = {source: source, state: state, displayed: displayed};
states = next;
}
function forget(output) {
const next = Object.assign({}, states);
delete next[output];
states = next;
}
}