diff --git a/src/models/settings.ts b/src/models/settings.ts index f40cb2e1..aac7a84b 100644 --- a/src/models/settings.ts +++ b/src/models/settings.ts @@ -67,43 +67,12 @@ export class UserSettings { const settings: UserSettingsData = {}; for (const key in data) { - if ( - [ - "autofill", - "driveEncrypted", - "driveRevoked", - "dropboxEncrypted", - "dropboxRevoked", - "enableContextMenu", - "oneDriveBusiness", - "oneDriveEncrypted", - "oneDriveRevoked", - "smartFilter", - "enableContextMenu", - ].includes(key) - ) { - settings[ - key as - | "autofill" - | "driveEncrypted" - | "driveRevoked" - | "dropboxEncrypted" - | "dropboxRevoked" - | "enableContextMenu" - | "oneDriveBusiness" - | "oneDriveEncrypted" - | "oneDriveRevoked" - | "smartFilter" - | "enableContextMenu" - ] = data[key] === "true"; - } else if ( - ["autolock", "lastRemindingBackupTime", "offset", "zoom"].includes(key) - ) { - settings[ - key as "autolock" | "lastRemindingBackupTime" | "offset" | "zoom" - ] = Number(data[key]); - } else if (["advisorIgnoreList"].includes(key)) { - settings[key as "advisorIgnoreList"] = JSON.parse(data[key]); + if (isBooleanOption(key)) { + settings[key] = data[key] === "true"; + } else if (isNumberOption(key)) { + settings[key] = Number(data[key]); + } else if (isJSONOption(key)) { + settings[key] = JSON.parse(data[key]); } else { settings[key as keyof UserSettingsData] = data[key]; } @@ -204,3 +173,44 @@ export class UserSettings { return { ...syncableSettings, ...localSettings }; } } + +type BooleanOption = + | "autofill" + | "driveEncrypted" + | "driveRevoked" + | "dropboxEncrypted" + | "dropboxRevoked" + | "enableContextMenu" + | "oneDriveBusiness" + | "oneDriveEncrypted" + | "oneDriveRevoked" + | "smartFilter"; + +type NumberOption = "autolock" | "lastRemindingBackupTime" | "offset" | "zoom"; + +type JSONOption = "advisorIgnoreList"; + +function isBooleanOption(key: string): key is BooleanOption { + return [ + "autofill", + "driveEncrypted", + "driveRevoked", + "dropboxEncrypted", + "dropboxRevoked", + "enableContextMenu", + "oneDriveBusiness", + "oneDriveEncrypted", + "oneDriveRevoked", + "smartFilter", + ].includes(key); +} + +function isNumberOption(key: string): key is NumberOption { + return ["autolock", "lastRemindingBackupTime", "offset", "zoom"].includes( + key + ); +} + +function isJSONOption(key: string): key is JSONOption { + return ["advisorIgnoreList"].includes(key); +} diff --git a/src/store/Accounts.ts b/src/store/Accounts.ts index c6e29304..57f6a47e 100644 --- a/src/store/Accounts.ts +++ b/src/store/Accounts.ts @@ -53,7 +53,7 @@ export class Accounts implements Module { getters: { matchedEntries: string[] } ) { return ( - UserSettings.items.smartFilter !== false && + UserSettings.items.smartFilter === true && getters.matchedEntries.length ); }, diff --git a/src/store/Menu.ts b/src/store/Menu.ts index bfe6749c..763b2aae 100644 --- a/src/store/Menu.ts +++ b/src/store/Menu.ts @@ -11,7 +11,7 @@ export class Menu implements Module { version: chrome.runtime.getManifest()?.version || "0.0.0", zoom: Number(UserSettings.items.zoom) || 100, useAutofill: UserSettings.items.autofill === true, - smartFilter: UserSettings.items.smartFilter !== false, + smartFilter: UserSettings.items.smartFilter === true, enableContextMenu: UserSettings.items.enableContextMenu === true, theme: UserSettings.items.theme || (isSafari ? "flat" : "normal"), autolock: Number(UserSettings.items.autolock) || 0,