Wallpapers: moved persistent data to their own file in ~/.cache/noctalia/wallpapers.json !! no migration path, user will have to set their wallpaper at least once !!

This commit is contained in:
ItsLemmy
2025-11-29 11:22:53 -05:00
parent 993b6bc422
commit 30db679207
4 changed files with 59 additions and 55 deletions

View File

@@ -154,9 +154,7 @@
"wallhavenPurity": "100", "wallhavenPurity": "100",
"wallhavenResolutionMode": "atleast", "wallhavenResolutionMode": "atleast",
"wallhavenResolutionWidth": "", "wallhavenResolutionWidth": "",
"wallhavenResolutionHeight": "", "wallhavenResolutionHeight": ""
"defaultWallpaper": "",
"monitors": []
}, },
"appLauncher": { "appLauncher": {
"enableClipboardHistory": false, "enableClipboardHistory": false,

View File

@@ -34,7 +34,6 @@ Singleton {
readonly property string defaultAvatar: Quickshell.env("HOME") + "/.face" readonly property string defaultAvatar: Quickshell.env("HOME") + "/.face"
readonly property string defaultVideosDirectory: Quickshell.env("HOME") + "/Videos" readonly property string defaultVideosDirectory: Quickshell.env("HOME") + "/Videos"
readonly property string defaultWallpapersDirectory: Quickshell.env("HOME") + "/Pictures/Wallpapers" readonly property string defaultWallpapersDirectory: Quickshell.env("HOME") + "/Pictures/Wallpapers"
readonly property string defaultWallpaper: Quickshell.shellDir + "/Assets/Wallpaper/noctalia.png"
// Signal emitted when settings are loaded after startupcale changes // Signal emitted when settings are loaded after startupcale changes
signal settingsLoaded signal settingsLoaded
@@ -77,7 +76,7 @@ Singleton {
Timer { Timer {
id: saveTimer id: saveTimer
running: false running: false
interval: 1000 interval: 500
onTriggered: { onTriggered: {
root.saveImmediate(); root.saveImmediate();
} }

View File

@@ -61,9 +61,6 @@ Singleton {
schemes: [], schemes: [],
timestamp: 0 timestamp: 0
}) })
// WallpaperService: current wallpapers per screen
property var wallpapers: ({})
} }
onLoaded: { onLoaded: {
@@ -86,7 +83,7 @@ Singleton {
// Debounced save timer // Debounced save timer
Timer { Timer {
id: saveTimer id: saveTimer
interval: 300 interval: 500
onTriggered: performSave() onTriggered: performSave()
} }
@@ -174,16 +171,6 @@ Singleton {
}; };
} }
// Wallpapers (WallpaperService)
function setWallpapers(wallpapersData) {
adapter.wallpapers = wallpapersData;
save();
}
function getWallpapers() {
return adapter.wallpapers || {};
}
// ----------------------------------------------------- // -----------------------------------------------------
function buildStateSnapshot() { function buildStateSnapshot() {
try { try {
@@ -196,8 +183,9 @@ Singleton {
doNotDisturb: NotificationService.doNotDisturb, doNotDisturb: NotificationService.doNotDisturb,
noctaliaPerformanceMode: PowerProfileService.noctaliaPerformanceMode, noctaliaPerformanceMode: PowerProfileService.noctaliaPerformanceMode,
barVisible: BarService.isVisible, barVisible: BarService.isVisible,
wallpapers: WallpaperService.currentWallpapers || {},
// -------------
display: shellStateData.display || {}, display: shellStateData.display || {},
wallpapers: shellStateData.wallpapers || {},
notificationsState: shellStateData.notificationsState || {}, notificationsState: shellStateData.notificationsState || {},
changelogState: shellStateData.changelogState || {}, changelogState: shellStateData.changelogState || {},
colorSchemesList: shellStateData.colorSchemesList || {} colorSchemesList: shellStateData.colorSchemesList || {}

View File

@@ -22,12 +22,15 @@ Singleton {
property var wallpaperLists: ({}) property var wallpaperLists: ({})
property int scanningCount: 0 property int scanningCount: 0
readonly property bool scanning: (scanningCount > 0)
// Cache for current wallpapers - can be updated directly since we use signals for notifications // Cache for current wallpapers - can be updated directly since we use signals for notifications
property var currentWallpapers: ({}) property var currentWallpapers: ({})
property bool isInitialized: false property bool isInitialized: false
property string wallpaperCacheFile: ""
readonly property bool scanning: (scanningCount > 0)
readonly property string defaultWallpaper: Quickshell.shellDir + "/Assets/Wallpaper/noctalia.png"
// Signals for reactive UI updates // Signals for reactive UI updates
signal wallpaperChanged(string screenName, string path) signal wallpaperChanged(string screenName, string path)
@@ -83,40 +86,19 @@ Singleton {
translateModels(); translateModels();
// Load wallpapers from ShellState first (faster), then fall back to Settings // Initialize cache file path
currentWallpapers = ({}); Qt.callLater(() => {
if (typeof Settings !== 'undefined' && Settings.cacheDir) {
wallpaperCacheFile = Settings.cacheDir + "wallpapers.json";
wallpaperCacheView.path = wallpaperCacheFile;
}
});
if (typeof ShellState !== 'undefined' && ShellState.isLoaded) { // Note: isInitialized will be set to true in wallpaperCacheView.onLoaded
var cachedWallpapers = ShellState.getWallpapers();
if (cachedWallpapers && Object.keys(cachedWallpapers).length > 0) {
currentWallpapers = cachedWallpapers;
Logger.d("Wallpaper", "Loaded wallpapers from ShellState");
} else {
// Fall back to Settings if ShellState is empty
loadFromSettings();
}
} else {
// ShellState not ready yet, load from Settings
loadFromSettings();
}
isInitialized = true;
Logger.d("Wallpaper", "Triggering initial wallpaper scan"); Logger.d("Wallpaper", "Triggering initial wallpaper scan");
Qt.callLater(refreshWallpapersList); Qt.callLater(refreshWallpapersList);
} }
function loadFromSettings() {
var monitors = Settings.data.wallpaper.monitors || [];
for (var i = 0; i < monitors.length; i++) {
if (monitors[i].name && monitors[i].wallpaper) {
currentWallpapers[monitors[i].name] = monitors[i].wallpaper;
}
}
Logger.d("Wallpaper", "Loaded wallpapers from Settings");
// Migration is now handled in Settings.qml
}
// ------------------------------------------------- // -------------------------------------------------
function translateModels() { function translateModels() {
// Wait for i18n to be ready by retrying every time // Wait for i18n to be ready by retrying every time
@@ -250,7 +232,7 @@ Singleton {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// Get specific monitor wallpaper - now from cache // Get specific monitor wallpaper - now from cache
function getWallpaper(screenName) { function getWallpaper(screenName) {
return currentWallpapers[screenName] || Settings.defaultWallpaper; return currentWallpapers[screenName] || root.defaultWallpaper;
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@@ -290,10 +272,8 @@ Singleton {
// Update cache directly // Update cache directly
currentWallpapers[screenName] = path; currentWallpapers[screenName] = path;
// Save to ShellState (wallpaper paths now only stored here, not in Settings) // Save to cache file with debounce
if (typeof ShellState !== 'undefined' && ShellState.isLoaded) { saveTimer.restart();
ShellState.setWallpapers(currentWallpapers);
}
// Emit signal for this specific wallpaper change // Emit signal for this specific wallpaper change
root.wallpaperChanged(screenName, path); root.wallpaperChanged(screenName, path);
@@ -529,4 +509,43 @@ Singleton {
} }
} }
} }
// -------------------------------------------------------------------
// Cache file persistence
// -------------------------------------------------------------------
FileView {
id: wallpaperCacheView
printErrors: false
watchChanges: false
adapter: JsonAdapter {
id: wallpaperCacheAdapter
property var wallpapers: ({})
}
onLoaded: {
// Load wallpapers from cache file
root.currentWallpapers = wallpaperCacheAdapter.wallpapers || {};
Logger.d("Wallpaper", "Loaded wallpapers from cache file:", Object.keys(root.currentWallpapers).length, "screens");
root.isInitialized = true;
}
onLoadFailed: error => {
// File doesn't exist yet or failed to load - initialize with empty state
root.currentWallpapers = {};
Logger.d("Wallpaper", "Cache file doesn't exist or failed to load, starting with empty wallpapers");
root.isInitialized = true;
}
}
Timer {
id: saveTimer
interval: 500
repeat: false
onTriggered: {
wallpaperCacheAdapter.wallpapers = root.currentWallpapers;
wallpaperCacheView.writeAdapter();
Logger.d("Wallpaper", "Saved wallpapers to cache file");
}
}
} }