Skip to content

Commit

Permalink
turn auto filter off by default and use type guards in UserSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
mymindstorm committed Jul 28, 2024
1 parent 3ea0d9b commit 7e24b4b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 39 deletions.
84 changes: 47 additions & 37 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/store/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Accounts implements Module {
getters: { matchedEntries: string[] }
) {
return (
UserSettings.items.smartFilter !== false &&
UserSettings.items.smartFilter === true &&
getters.matchedEntries.length
);
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/Menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7e24b4b

Please sign in to comment.