A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
web: add vault lock timer setting Signed-off-by: 01zulfi <[email protected]>
01zulfi2b1cd537e278
diff --git a/apps/web/src/dialogs/settings/vault-settings.tsx b/apps/web/src/dialogs/settings/vault-settings.tsxindex 53d039c2d..d75a71a0a 100644--- a/apps/web/src/dialogs/settings/vault-settings.tsx+++ b/apps/web/src/dialogs/settings/vault-settings.tsx@@ -48,6 +48,36 @@ export const VaultSettings: SettingsGroup[] = [}]},+ {+ key: "lock-vault-after",+ title: strings.lockVaultAfter(),+ description:+ strings.lockVaultAfterDesc(),+ isHidden: () => !useAppStore.getState().isVaultCreated,+ onStateChange: (listener) =>+ useAppStore.subscribe((s) => s.vaultLockAfter, listener),+ components: [+ {+ type: "dropdown",+ options: [+ { title: "1 minute", value: 1000 * 60 * 1 },+ { title: "5 minutes", value: 1000 * 60 * 5 },+ { title: "10 minutes", value: 1000 * 60 * 10 },+ { title: "15 minutes", value: 1000 * 60 * 15 },+ { title: "30 minutes", value: 1000 * 60 * 30 },+ { title: "45 minutes", value: 1000 * 60 * 45 },+ { title: "1 hour", value: 1000 * 60 * 60 },+ { title: "Never", value: -1 }+ ],+ onSelectionChanged: async (value) => {+ await useAppStore.getState().setVaultLockAfter(parseInt(value));+ },+ selectedOption: () => {+ return useAppStore.getState().vaultLockAfter;+ }+ }+ ]+ },{key: "change-vault-password",title: strings.changeVaultPassword(),diff --git a/apps/web/src/stores/app-store.ts b/apps/web/src/stores/app-store.tsindex e0bcd214b..ea800d134 100644--- a/apps/web/src/stores/app-store.ts+++ b/apps/web/src/stores/app-store.ts@@ -68,6 +68,7 @@ class AppStore extends BaseStore<AppStore> {isListPaneVisible = true;isNavPaneCollapsed = false;isVaultCreated = false;+ vaultLockAfter = 1000 * 60 * 30;isAutoSyncEnabled = Config.get("autoSyncEnabled", true);isSyncEnabled = Config.get("syncEnabled", true);isRealtimeSyncEnabled = Config.get("isRealtimeSyncEnabled", true);@@ -88,7 +89,8 @@ class AppStore extends BaseStore<AppStore> {this.refresh();this.set({hiddenColors: db.settings.getSideBarHiddenItems("colors"),- hiddenRoutes: db.settings.getSideBarHiddenItems("routes")+ hiddenRoutes: db.settings.getSideBarHiddenItems("routes"),+ vaultLockAfter: db.settings.getVaultLockAfter()});this.get().sync({ type: "full" });@@ -234,6 +236,12 @@ class AppStore extends BaseStore<AppStore> {this.set((state) => (state.isVaultCreated = toggleState));};+ setVaultLockAfter = async (ms: number) => {+ await db.settings.setVaultLockAfter(ms);+ this.set((state) => (state.vaultLockAfter = ms));+ await db.vault.lock();+ };+setNotices = (...notices: Notice[]) => {this.set((state) => {for (const notice of notices) {diff --git a/packages/core/__tests__/vault.test.js b/packages/core/__tests__/vault.test.jsindex eaac8e847..0073c8d69 100644--- a/packages/core/__tests__/vault.test.js+++ b/packages/core/__tests__/vault.test.js@@ -234,7 +234,7 @@ test("delete vault and delete all locked notes", () =>test("vault password is cleared after specified time", () =>databaseTest().then(async (db) => {await expect(db.vault.create("password")).resolves.toBe(true);- db.vault.eraseTime = 1000;+ await db.settings.setVaultLockAfter(1000);await expect(db.vault.unlock("password")).resolves.toBe(true);expect(db.vault.unlocked).toBe(true);await delay(1500);diff --git a/packages/core/src/api/vault.ts b/packages/core/src/api/vault.tsindex 0489f6e12..55d37f89c 100644--- a/packages/core/src/api/vault.ts+++ b/packages/core/src/api/vault.ts@@ -31,7 +31,6 @@ export const VAULT_ERRORS = {};export default class Vault {- eraseTime = 1000 * 60 * 30;private vaultPassword?: string;private erasureTimeout = 0;private key = "svvaads1212#2123";@@ -50,9 +49,13 @@ export default class Vault {private startEraser() {this.db.eventManager.publish(EVENTS.vaultUnlocked);clearTimeout(this.erasureTimeout);++ const lockAfter = this.db.settings.getVaultLockAfter();+ if (lockAfter < 0) return;+this.erasureTimeout = setTimeout(() => {this.lock();- }, this.eraseTime) as unknown as number;+ }, lockAfter) as unknown as number;}constructor(private readonly db: Database) {diff --git a/packages/core/src/collections/settings.ts b/packages/core/src/collections/settings.tsindex 3e14c11d1..58c97e652 100644--- a/packages/core/src/collections/settings.ts+++ b/packages/core/src/collections/settings.ts@@ -63,6 +63,7 @@ const defaultSettings: SettingItemMap = {defaultTag: undefined,trashCleanupInterval: 7,profile: undefined,+ "vault:lockAfter": 1000 * 60 * 30,"groupOptions:trash": DEFAULT_GROUP_OPTIONS("trash"),"groupOptions:tags": DEFAULT_GROUP_OPTIONS("tags"),@@ -248,4 +249,12 @@ export class Settings implements ICollection {const profile = !partial ? undefined : { ...this.getProfile(), ...partial };return this.set("profile", profile);}++ getVaultLockAfter() {+ return this.get("vault:lockAfter");+ }++ setVaultLockAfter(ms: number) {+ return this.set("vault:lockAfter", ms);+ }}diff --git a/packages/core/src/types.ts b/packages/core/src/types.tsindex cb314589f..cd2427319 100644--- a/packages/core/src/types.ts+++ b/packages/core/src/types.ts@@ -486,6 +486,7 @@ export type SettingItemMap = {defaultNotebook: string | undefined;defaultTag: string | undefined;profile: Profile | undefined;+ "vault:lockAfter": number;} & Record<`groupOptions:${GroupingKey}`, GroupOptions> &Record<`toolbarConfig:${ToolbarConfigPlatforms}`, ToolbarConfig | undefined> &Record<`sideBarOrder:${SideBarSection}`, string[]> &diff --git a/packages/intl/locale/en.po b/packages/intl/locale/en.poindex 84548bbb4..e49a8fcdc 100644--- a/packages/intl/locale/en.po+++ b/packages/intl/locale/en.po@@ -3884,6 +3884,10 @@ msgstr "Lock note"msgid "Lock the app with a password or pin"msgstr "Lock the app with a password or pin"+#: src/strings.ts:2703+msgid "Lock vault after"+msgstr "Lock vault after"+#: src/strings.ts:901msgid "Locked notes cannot be pinned"msgstr "Locked notes cannot be pinned"diff --git a/packages/intl/locale/pseudo-LOCALE.po b/packages/intl/locale/pseudo-LOCALE.poindex 98f291cf1..a3084e4c7 100644--- a/packages/intl/locale/pseudo-LOCALE.po+++ b/packages/intl/locale/pseudo-LOCALE.po@@ -3864,6 +3864,10 @@ msgstr ""msgid "Lock the app with a password or pin"msgstr ""+#: src/strings.ts:2703+msgid "Lock vault after"+msgstr ""+#: src/strings.ts:901msgid "Locked notes cannot be pinned"msgstr ""@@ -6957,7 +6961,7 @@ msgstr ""#: src/strings.ts:888msgid "Unlock note to delete it"-msgstr ""+msgstr "<<<<<<< HEAD"#: src/strings.ts:2640msgid "Unlock note to merge conflicts"diff --git a/packages/intl/src/strings.ts b/packages/intl/src/strings.tsindex f5f18e92a..011a465ae 100644--- a/packages/intl/src/strings.ts+++ b/packages/intl/src/strings.ts@@ -2699,5 +2699,8 @@ Use this if changes from other devices are not appearing on this device. This wiprivateKey: () => t`Private Key:`,invalidPgpKeyPair: () =>t`Invalid PGP key pair. Please check your keys and try again.`,- inboxKeysSaved: () => t`Inbox keys saved`+ inboxKeysSaved: () => t`Inbox keys saved`,+ lockVaultAfter: () => t`Lock vault after`,+ lockVaultAfterDesc: () =>+ `How long should the vault stay unlocked before automatically locking?`};