mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
fix(config): handle nix-style atomic config replacements for settings and colors
This commit is contained in:
+33
-5
@@ -20,6 +20,28 @@ Singleton {
|
|||||||
|
|
||||||
property bool reloadColors: false
|
property bool reloadColors: false
|
||||||
|
|
||||||
|
// Debounce external reload requests (file watcher + directory watcher)
|
||||||
|
// so atomic replacements only trigger one reload.
|
||||||
|
Timer {
|
||||||
|
id: externalColorReloadTimer
|
||||||
|
running: false
|
||||||
|
interval: 200
|
||||||
|
onTriggered: {
|
||||||
|
if (customColorsFile.path !== undefined) {
|
||||||
|
Logger.d("Color", "Reloading colors from disk");
|
||||||
|
reloadColors = true;
|
||||||
|
customColorsFile.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleExternalColorReload() {
|
||||||
|
if (!Settings.directoriesCreated || customColorsFile.path === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
externalColorReloadTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
// Suppress transition animations until the first colors.json load completes
|
// Suppress transition animations until the first colors.json load completes
|
||||||
property bool skipTransition: true
|
property bool skipTransition: true
|
||||||
|
|
||||||
@@ -400,11 +422,7 @@ Singleton {
|
|||||||
path: Settings.directoriesCreated ? (Settings.configDir + "colors.json") : undefined
|
path: Settings.directoriesCreated ? (Settings.configDir + "colors.json") : undefined
|
||||||
printErrors: false
|
printErrors: false
|
||||||
watchChanges: true
|
watchChanges: true
|
||||||
onFileChanged: {
|
onFileChanged: scheduleExternalColorReload()
|
||||||
Logger.d("Color", "Reloading colors from disk");
|
|
||||||
reloadColors = true;
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
onAdapterUpdated: {
|
onAdapterUpdated: {
|
||||||
Logger.d("Color", "Writing colors to disk");
|
Logger.d("Color", "Writing colors to disk");
|
||||||
writeAdapter();
|
writeAdapter();
|
||||||
@@ -470,4 +488,14 @@ Singleton {
|
|||||||
property color mOnHover: defaultColors.mOnHover
|
property color mOnHover: defaultColors.mOnHover
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch parent config directory as a fallback for declarative setups where
|
||||||
|
// colors.json may be replaced atomically (e.g., symlink/store-path swap).
|
||||||
|
FileView {
|
||||||
|
id: colorsDirWatcher
|
||||||
|
path: Settings.directoriesCreated ? Settings.configDir : undefined
|
||||||
|
printErrors: false
|
||||||
|
watchChanges: true
|
||||||
|
onFileChanged: scheduleExternalColorReload()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+33
-4
@@ -40,6 +40,28 @@ Singleton {
|
|||||||
signal settingsSaved
|
signal settingsSaved
|
||||||
signal settingsReloaded
|
signal settingsReloaded
|
||||||
|
|
||||||
|
// Debounce external reload requests (file watcher + directory watcher)
|
||||||
|
// so atomic replacements only trigger one reload.
|
||||||
|
Timer {
|
||||||
|
id: externalReloadTimer
|
||||||
|
running: false
|
||||||
|
interval: 200
|
||||||
|
onTriggered: {
|
||||||
|
if (settingsFileView.path !== undefined) {
|
||||||
|
Logger.d("Settings", "Reloading settings after external change detection");
|
||||||
|
reloadSettings = true;
|
||||||
|
settingsFileView.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleExternalReload() {
|
||||||
|
if (!directoriesCreated || settingsFileView.path === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
externalReloadTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
// Ensure directories exist before FileView tries to read files
|
// Ensure directories exist before FileView tries to read files
|
||||||
@@ -87,10 +109,7 @@ Singleton {
|
|||||||
watchChanges: true
|
watchChanges: true
|
||||||
onAdapterUpdated: saveTimer.start()
|
onAdapterUpdated: saveTimer.start()
|
||||||
|
|
||||||
onFileChanged: {
|
onFileChanged: scheduleExternalReload()
|
||||||
reloadSettings = true;
|
|
||||||
reload();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger initial load when path changes from empty to actual path
|
// Trigger initial load when path changes from empty to actual path
|
||||||
onPathChanged: {
|
onPathChanged: {
|
||||||
@@ -142,6 +161,16 @@ Singleton {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch parent config directory as a fallback for declarative setups where
|
||||||
|
// settings.json may be replaced atomically (e.g., symlink/store-path swap).
|
||||||
|
FileView {
|
||||||
|
id: settingsDirWatcher
|
||||||
|
path: directoriesCreated ? configDir : undefined
|
||||||
|
printErrors: false
|
||||||
|
watchChanges: true
|
||||||
|
onFileChanged: scheduleExternalReload()
|
||||||
|
}
|
||||||
|
|
||||||
// FileView to load default settings for comparison
|
// FileView to load default settings for comparison
|
||||||
FileView {
|
FileView {
|
||||||
id: defaultSettingsFileView
|
id: defaultSettingsFileView
|
||||||
|
|||||||
Reference in New Issue
Block a user