mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
settings: guard saving before load completed
This commit is contained in:
@@ -16,6 +16,7 @@ Singleton {
|
|||||||
readonly property bool isGreeterMode: Quickshell.env("DMS_RUN_GREETER") === "1" || Quickshell.env("DMS_RUN_GREETER") === "true"
|
readonly property bool isGreeterMode: Quickshell.env("DMS_RUN_GREETER") === "1" || Quickshell.env("DMS_RUN_GREETER") === "true"
|
||||||
property bool hasTriedDefaultSession: false
|
property bool hasTriedDefaultSession: false
|
||||||
property bool _parseError: false
|
property bool _parseError: false
|
||||||
|
property bool _hasLoaded: false
|
||||||
readonly property string _stateUrl: StandardPaths.writableLocation(StandardPaths.GenericStateLocation)
|
readonly property string _stateUrl: StandardPaths.writableLocation(StandardPaths.GenericStateLocation)
|
||||||
readonly property string _stateDir: Paths.strip(_stateUrl)
|
readonly property string _stateDir: Paths.strip(_stateUrl)
|
||||||
|
|
||||||
@@ -111,8 +112,10 @@ Singleton {
|
|||||||
function parseSettings(content) {
|
function parseSettings(content) {
|
||||||
_parseError = false;
|
_parseError = false;
|
||||||
try {
|
try {
|
||||||
if (!content || !content.trim())
|
if (!content || !content.trim()) {
|
||||||
|
_parseError = true;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
var settings = JSON.parse(content);
|
var settings = JSON.parse(content);
|
||||||
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false;
|
isLightMode = settings.isLightMode !== undefined ? settings.isLightMode : false;
|
||||||
|
|
||||||
@@ -178,6 +181,7 @@ Singleton {
|
|||||||
includedTransitions = settings.includedTransitions !== undefined ? settings.includedTransitions : availableWallpaperTransitions.filter(t => t !== "none");
|
includedTransitions = settings.includedTransitions !== undefined ? settings.includedTransitions : availableWallpaperTransitions.filter(t => t !== "none");
|
||||||
recentColors = settings.recentColors !== undefined ? settings.recentColors : [];
|
recentColors = settings.recentColors !== undefined ? settings.recentColors : [];
|
||||||
showThirdPartyPlugins = settings.showThirdPartyPlugins !== undefined ? settings.showThirdPartyPlugins : false;
|
showThirdPartyPlugins = settings.showThirdPartyPlugins !== undefined ? settings.showThirdPartyPlugins : false;
|
||||||
|
_hasLoaded = true;
|
||||||
|
|
||||||
if (settings.configVersion === undefined) {
|
if (settings.configVersion === undefined) {
|
||||||
migrateFromUndefinedToV1(settings);
|
migrateFromUndefinedToV1(settings);
|
||||||
@@ -202,7 +206,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveSettings() {
|
function saveSettings() {
|
||||||
if (isGreeterMode || _parseError)
|
if (isGreeterMode || _parseError || !_hasLoaded)
|
||||||
return;
|
return;
|
||||||
settingsFile.setText(JSON.stringify({
|
settingsFile.setText(JSON.stringify({
|
||||||
"isLightMode": isLightMode,
|
"isLightMode": isLightMode,
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ Singleton {
|
|||||||
property bool _pluginSettingsLoading: false
|
property bool _pluginSettingsLoading: false
|
||||||
property bool _parseError: false
|
property bool _parseError: false
|
||||||
property bool _pluginParseError: false
|
property bool _pluginParseError: false
|
||||||
|
property bool _hasLoaded: false
|
||||||
property bool hasTriedDefaultSettings: false
|
property bool hasTriedDefaultSettings: false
|
||||||
property var pluginSettings: ({})
|
property var pluginSettings: ({})
|
||||||
|
|
||||||
@@ -789,6 +790,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Store.parse(root, obj);
|
Store.parse(root, obj);
|
||||||
|
_hasLoaded = true;
|
||||||
applyStoredTheme();
|
applyStoredTheme();
|
||||||
applyStoredIconTheme();
|
applyStoredIconTheme();
|
||||||
Processes.detectQtTools();
|
Processes.detectQtTools();
|
||||||
@@ -832,7 +834,7 @@ Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveSettings() {
|
function saveSettings() {
|
||||||
if (_loading || _parseError)
|
if (_loading || _parseError || !_hasLoaded)
|
||||||
return;
|
return;
|
||||||
settingsFile.setText(JSON.stringify(Store.toJson(root), null, 2));
|
settingsFile.setText(JSON.stringify(Store.toJson(root), null, 2));
|
||||||
}
|
}
|
||||||
@@ -1800,9 +1802,14 @@ Singleton {
|
|||||||
_loading = true;
|
_loading = true;
|
||||||
try {
|
try {
|
||||||
const txt = settingsFile.text();
|
const txt = settingsFile.text();
|
||||||
const obj = (txt && txt.trim()) ? JSON.parse(txt) : null;
|
if (!txt || !txt.trim()) {
|
||||||
|
_parseError = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const obj = JSON.parse(txt);
|
||||||
_parseError = false;
|
_parseError = false;
|
||||||
Store.parse(root, obj);
|
Store.parse(root, obj);
|
||||||
|
_hasLoaded = true;
|
||||||
applyStoredTheme();
|
applyStoredTheme();
|
||||||
applyStoredIconTheme();
|
applyStoredIconTheme();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user