From 436c99927e8fea087eec1775d78cddaa92ff4094 Mon Sep 17 00:00:00 2001 From: bbedward Date: Sat, 3 Jan 2026 20:34:36 -0500 Subject: [PATCH] settings: detect read-only on save attempts --- quickshell/Common/SessionData.qml | 24 +++++++++++++++++------- quickshell/Common/SettingsData.qml | 24 +++++++++++++++++------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/quickshell/Common/SessionData.qml b/quickshell/Common/SessionData.qml index 685f3bdc..7fe54ad0 100644 --- a/quickshell/Common/SessionData.qml +++ b/quickshell/Common/SessionData.qml @@ -127,11 +127,19 @@ Singleton { } function _onWritableCheckComplete(writable) { + const wasReadOnly = _isReadOnly; _isReadOnly = !writable; if (_isReadOnly) { - console.info("SessionData: session.json is read-only (NixOS home-manager mode)"); - } else if (_pendingMigration) { - settingsFile.setText(JSON.stringify(_pendingMigration, null, 2)); + _hasUnsavedChanges = _checkForUnsavedChanges(); + if (!wasReadOnly) + console.info("SessionData: session.json is now read-only"); + } else { + _loadedSessionSnapshot = getCurrentSessionJson(); + _hasUnsavedChanges = false; + if (wasReadOnly) + console.info("SessionData: session.json is now writable"); + if (_pendingMigration) + settingsFile.setText(JSON.stringify(_pendingMigration, null, 2)); } _pendingMigration = null; } @@ -215,11 +223,9 @@ Singleton { function saveSettings() { if (isGreeterMode || _parseError || !_hasLoaded) return; - if (_isReadOnly) { - _hasUnsavedChanges = _checkForUnsavedChanges(); - return; - } settingsFile.setText(getCurrentSessionJson()); + if (_isReadOnly) + _checkSessionWritable(); } function migrateFromUndefinedToV1(settings) { @@ -953,6 +959,10 @@ Singleton { parseSettings(settingsFile.text()); } } + onSaveFailed: error => { + root._isReadOnly = true; + root._hasUnsavedChanges = root._checkForUnsavedChanges(); + } } FileView { diff --git a/quickshell/Common/SettingsData.qml b/quickshell/Common/SettingsData.qml index 321cd0b7..46340931 100644 --- a/quickshell/Common/SettingsData.qml +++ b/quickshell/Common/SettingsData.qml @@ -840,11 +840,19 @@ Singleton { } function _onWritableCheckComplete(writable) { + const wasReadOnly = _isReadOnly; _isReadOnly = !writable; if (_isReadOnly) { - console.info("SettingsData: settings.json is read-only (NixOS home-manager mode)"); - } else if (_pendingMigration) { - settingsFile.setText(JSON.stringify(_pendingMigration, null, 2)); + _hasUnsavedChanges = _checkForUnsavedChanges(); + if (!wasReadOnly) + console.info("SettingsData: settings.json is now read-only"); + } else { + _loadedSettingsSnapshot = JSON.stringify(Store.toJson(root)); + _hasUnsavedChanges = false; + if (wasReadOnly) + console.info("SettingsData: settings.json is now writable"); + if (_pendingMigration) + settingsFile.setText(JSON.stringify(_pendingMigration, null, 2)); } _pendingMigration = null; } @@ -889,11 +897,9 @@ Singleton { function saveSettings() { if (_loading || _parseError || !_hasLoaded) return; - if (_isReadOnly) { - _hasUnsavedChanges = _checkForUnsavedChanges(); - return; - } settingsFile.setText(JSON.stringify(Store.toJson(root), null, 2)); + if (_isReadOnly) + _checkSettingsWritable(); } function savePluginSettings() { @@ -1889,6 +1895,10 @@ Singleton { applyStoredTheme(); } } + onSaveFailed: error => { + root._isReadOnly = true; + root._hasUnsavedChanges = root._checkForUnsavedChanges(); + } } FileView {