feat: add wallpaper state persistence across system restarts via ~/.config/quickshell_user_wallpaper.json

This commit is contained in:
Sho 2026-08-02 00:07:04 +09:00
parent fa24a8848d
commit cb01f3a3ab
4 changed files with 68 additions and 3 deletions

View File

@ -17,6 +17,27 @@ Item {
running: true
}
// Read saved user wallpaper on startup
Process {
id: readWallpaperProc
command: ["python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/read_wallpaper.py"]
running: true
stdout: SplitParser {
onRead: data => {
try {
let parsed = JSON.parse(data.trim())
if (parsed && parsed.wallpaper && parsed.wallpaper !== "") {
root.activeCustomWallpaper = parsed.wallpaper
let fileUrl = parsed.wallpaper.startsWith("file://") ? parsed.wallpaper : "file://" + parsed.wallpaper
Theme.wallpaperPath = fileUrl
let rawPath = parsed.wallpaper.replace("file://", "")
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
}
} catch (e) {}
}
}
}
// Auto-scan wallpapers in ~/Pictures/Wallpapers and ~/.config/quickshell/wallpapers
Process {
id: scanProc
@ -43,6 +64,7 @@ Item {
}
Component.onCompleted: {
readWallpaperProc.running = true
scanProc.running = true
}
@ -53,6 +75,7 @@ Item {
Theme.wallpaperPath = fileUrl
let rawPath = filePath.replace("file://", "")
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
Quickshell.execDetached(["python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/save_wallpaper.py", rawPath])
}
function refresh() {

View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import json
import os
def read_wallpaper():
user_file = os.path.expanduser('~/.config/quickshell_user_wallpaper.json')
if os.path.exists(user_file):
try:
with open(user_file, 'r', encoding='utf-8') as f:
data = json.load(f)
if isinstance(data, dict) and data.get("wallpaper"):
print(json.dumps(data), flush=True)
return
except Exception:
pass
print(json.dumps({"wallpaper": ""}), flush=True)
if __name__ == '__main__':
read_wallpaper()

View File

@ -0,0 +1,19 @@
#!/usr/bin/env python3
import json
import os
import sys
def save_wallpaper():
if len(sys.argv) < 2:
return
wp_path = sys.argv[1]
user_file = os.path.expanduser('~/.config/quickshell_user_wallpaper.json')
data = {"wallpaper": wp_path}
try:
with open(user_file, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2)
except Exception:
pass
if __name__ == '__main__':
save_wallpaper()

View File

@ -165,9 +165,13 @@ Item {
AppLauncherService.reload()
let imgPath = getVariantWallpaper(v.name)
wallpaperPath = imgPath.startsWith("file://") ? imgPath : "file://" + imgPath
let rawPath = imgPath.replace("file://", "")
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
if (WallpaperService) {
WallpaperService.applyWallpaper(imgPath)
} else {
wallpaperPath = imgPath.startsWith("file://") ? imgPath : "file://" + imgPath
let rawPath = imgPath.replace("file://", "")
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
}
Quickshell.execDetached(["sh", "-c", "wallust run '" + rawPath + "' || ~/.cargo/bin/wallust run '" + rawPath + "' 2>/dev/null || true"])
// Persist selected theme variant to disk