From cf938216e2f031f50843fbdfa74a2dddda573abf Mon Sep 17 00:00:00 2001 From: mrduck Date: Fri, 11 Sep 2026 21:25:50 +0300 Subject: [PATCH] fix(settings): handle empty or invalid windows.json configuration gracefully --- lib/shared/settings.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/shared/settings.js b/lib/shared/settings.js index f0932107..4c585415 100644 --- a/lib/shared/settings.js +++ b/lib/shared/settings.js @@ -105,12 +105,19 @@ export class ConfigManager extends GObject.Object { } else { const profileCustomSettingDir = Gio.File.new_for_path(path); if (!profileCustomSettingDir.query_exists(null)) { - if (profileCustomSettingDir.make_directory_with_parents(null)) { - const createdStream = customSettingFile.create(Gio.FileCreateFlags.NONE, null); - const defaultContents = this.loadFileContents(defaultFile); - Logger.trace(defaultContents); + profileCustomSettingDir.make_directory_with_parents(null); + } + try { + const createdStream = customSettingFile.create(Gio.FileCreateFlags.NONE, null); + const defaultContents = this.loadFileContents(defaultFile); + Logger.trace(defaultContents); + if (defaultContents) { createdStream.write_all(defaultContents, null); } + createdStream.close(null); + return customSettingFile; + } catch (e) { + Logger.error(`Failed to create custom setting file: ${e}`); } } @@ -137,7 +144,16 @@ export class ConfigManager extends GObject.Object { if (success) { const windowConfigContents = imports.byteArray.toString(contents); Logger.trace(`${windowConfigContents}`); - windowProps = JSON.parse(windowConfigContents); + try { + if (windowConfigContents && windowConfigContents.trim().length > 0) { + windowProps = JSON.parse(windowConfigContents); + } else { + windowProps = this.loadDefaultWindowConfigContents(); + } + } catch (err) { + Logger.error(`Failed to parse windowProps: ${err}`); + windowProps = this.loadDefaultWindowConfigContents(); + } } return windowProps; }