Skip to content

Commit

Permalink
Guard APIs in Config that could cause exceptions.
Browse files Browse the repository at this point in the history
Resolves #417 and similar issues.
  • Loading branch information
SpacingBat3 committed May 2, 2024
1 parent 83a912d commit bd078e5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions sources/code/main/modules/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,18 @@ class Config<T> {
#read(): unknown {
const encodedData = readFileSync(this.#path+this.#pathExtension);
let decodedData = encodedData.toString();
if(this.#pathExtension === FileExt.Encrypted)
if(this.#pathExtension === FileExt.Encrypted) try {
decodedData = safeStorage.decryptString(encodedData);
return JSON.parse(decodedData);
return JSON.parse(decodedData);
} catch {}
return {};
}
/**
/**
* Merges the configuration object with the another `object`.
*
*
* To do this, both old and new values are deeply merged,
* where new values can overwite the old ones.
*
*
* @param object A JavaScript object that will be merged with the configuration object.
*/

Expand Down Expand Up @@ -270,7 +272,7 @@ export class WinStateKeeper<T extends string> extends Config<Partial<Record<T, W

/**
* Initializes the EventListeners, usually **after** `window` is defined.
*
*
* @param window A `BrowserWindow` from which current window bounds are picked.
*/

Expand All @@ -283,7 +285,7 @@ export class WinStateKeeper<T extends string> extends Config<Partial<Record<T, W

/**
* Reads the data from the current configuration
*
*
* @param windowName Name of the group in which other properties should be saved.
* @param path Path to application's configuration. Defaults to `app.getPath('userData')+/windowState.json`
* @param spaces Number of spaces that will be used for indentation of the configuration file.
Expand Down

0 comments on commit bd078e5

Please sign in to comment.