feat: add wallpaper state persistence across system restarts via ~/.config/quickshell_user_wallpaper.json
This commit is contained in:
parent
fa24a8848d
commit
cb01f3a3ab
@ -17,6 +17,27 @@ Item {
|
|||||||
running: true
|
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
|
// Auto-scan wallpapers in ~/Pictures/Wallpapers and ~/.config/quickshell/wallpapers
|
||||||
Process {
|
Process {
|
||||||
id: scanProc
|
id: scanProc
|
||||||
@ -43,6 +64,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
readWallpaperProc.running = true
|
||||||
scanProc.running = true
|
scanProc.running = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +75,7 @@ Item {
|
|||||||
Theme.wallpaperPath = fileUrl
|
Theme.wallpaperPath = fileUrl
|
||||||
let rawPath = filePath.replace("file://", "")
|
let rawPath = filePath.replace("file://", "")
|
||||||
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
|
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
|
||||||
|
Quickshell.execDetached(["python3", Quickshell.env("HOME") + "/.config/quickshell/services/python/save_wallpaper.py", rawPath])
|
||||||
}
|
}
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
|
|||||||
19
quickshell/services/python/read_wallpaper.py
Executable file
19
quickshell/services/python/read_wallpaper.py
Executable 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()
|
||||||
19
quickshell/services/python/save_wallpaper.py
Executable file
19
quickshell/services/python/save_wallpaper.py
Executable 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()
|
||||||
@ -165,9 +165,13 @@ Item {
|
|||||||
AppLauncherService.reload()
|
AppLauncherService.reload()
|
||||||
|
|
||||||
let imgPath = getVariantWallpaper(v.name)
|
let imgPath = getVariantWallpaper(v.name)
|
||||||
wallpaperPath = imgPath.startsWith("file://") ? imgPath : "file://" + imgPath
|
if (WallpaperService) {
|
||||||
let rawPath = imgPath.replace("file://", "")
|
WallpaperService.applyWallpaper(imgPath)
|
||||||
Quickshell.execDetached(["plasma-apply-wallpaperimage", rawPath])
|
} 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"])
|
Quickshell.execDetached(["sh", "-c", "wallust run '" + rawPath + "' || ~/.cargo/bin/wallust run '" + rawPath + "' 2>/dev/null || true"])
|
||||||
|
|
||||||
// Persist selected theme variant to disk
|
// Persist selected theme variant to disk
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user