summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2020-09-07 10:36:09 +0200
committerOskar Nyberg <oskar@mullvad.net>2020-09-09 19:54:39 +0200
commit2398580398f268ff4e7cf13f4e867eb64fdb2f92 (patch)
treedf384a2ce944b199349f09719ab6478fc5a40983 /gui/src/main
parentc840a15588db413c6cc4d39cce70fe6962f89a56 (diff)
downloadmullvadvpn-2398580398f268ff4e7cf13f4e867eb64fdb2f92.tar.xz
mullvadvpn-2398580398f268ff4e7cf13f4e867eb64fdb2f92.zip
Remove dependency on validated
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/gui-settings.ts30
1 files changed, 20 insertions, 10 deletions
diff --git a/gui/src/main/gui-settings.ts b/gui/src/main/gui-settings.ts
index c860bfe490..d1d620ba54 100644
--- a/gui/src/main/gui-settings.ts
+++ b/gui/src/main/gui-settings.ts
@@ -2,17 +2,15 @@ import { app } from 'electron';
import log from 'electron-log';
import * as fs from 'fs';
import * as path from 'path';
-import { validate } from 'validated/object';
-import { boolean, partialObject, string } from 'validated/schema';
import { IGuiSettingsState, SYSTEM_PREFERRED_LOCALE_KEY } from '../shared/gui-settings-state';
-const settingsSchema = partialObject({
- preferredLocale: string,
- autoConnect: boolean,
- enableSystemNotifications: boolean,
- monochromaticIcon: boolean,
- startMinimized: boolean,
-});
+const settingsSchema = {
+ preferredLocale: 'string',
+ autoConnect: 'boolean',
+ enableSystemNotifications: 'boolean',
+ monochromaticIcon: 'boolean',
+ startMinimized: 'boolean',
+};
const defaultSettings: IGuiSettingsState = {
preferredLocale: SYSTEM_PREFERRED_LOCALE_KEY,
@@ -79,7 +77,7 @@ export default class GuiSettings {
this.stateValue = {
...defaultSettings,
- ...(validate(settingsSchema, rawJson) as Partial<IGuiSettingsState>),
+ ...this.validateSettings(rawJson),
};
} catch (error) {
log.error(`Failed to read GUI settings file: ${error}`);
@@ -96,6 +94,18 @@ export default class GuiSettings {
}
}
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ private validateSettings(settings: any) {
+ Object.entries(settingsSchema).forEach(([key, expectedType]) => {
+ const actualType = typeof settings[key];
+ if (key in settings && actualType !== expectedType) {
+ throw new Error(`Expected ${key} to be of type ${expectedType} but was ${actualType}`);
+ }
+ });
+
+ return settings as Partial<IGuiSettingsState>;
+ }
+
private filePath() {
return path.join(app.getPath('userData'), 'gui_settings.json');
}