Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion lib/shared/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export class ConfigManager extends GObject.Object {
const defaultContents = this.loadFileContents(defaultFile);
Logger.trace(defaultContents);
createdStream.write_all(defaultContents, null);
// close it, or the file can stay empty (#415)
createdStream.close(null);
}
}
}
Expand Down Expand Up @@ -137,7 +139,29 @@ export class ConfigManager extends GObject.Object {
if (success) {
const windowConfigContents = imports.byteArray.toString(contents);
Logger.trace(`${windowConfigContents}`);
windowProps = JSON.parse(windowConfigContents);
try {
windowProps = JSON.parse(windowConfigContents);
if (!Array.isArray(windowProps?.overrides)) throw new Error("no overrides list");
} catch (e) {
// An empty or broken file mustn't stop Forge from starting (#415): use the default
// rules. Forge rewrites the file on the next change of the rules (e.g. a window closing),
// so keep a copy of it first.
let backup = "";
if (windowConfigContents.trim()) {
try {
const backupFile = Gio.File.new_for_path(`${windowConfigFile.get_path()}.bak`);
windowConfigFile.copy(backupFile, Gio.FileCopyFlags.OVERWRITE, null, null);
backup = `; it was copied to ${backupFile.get_path()}`;
} catch (copyError) {
backup = `; it couldn't be copied (${copyError.message})`;
}
}
console.warn(
`Forge: ${windowConfigFile.get_path()} is not valid (${e.message}); ` +
`using the default window rules${backup}`
);
windowProps = this.loadDefaultWindowConfigContents();
}
}
return windowProps;
}
Expand Down