From 61fbce2ef7e2235ef9c96557d1cfc4a0ffe67874 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:47:54 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix(keepass):=20=E4=BF=AE=E5=A4=8D=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E6=97=B6=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=20|=20Fix=20the=20issue=20that=20ca?= =?UTF-8?q?nnot=20be=20displayed=20when=20initializing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c967898..a1d0220 100644 --- a/src/index.ts +++ b/src/index.ts @@ -251,7 +251,6 @@ export default class KeepassPlugin extends siyuan.Plugin { } else { this.config = mergeIgnoreArray(DEFAULT_CONFIG); - this.updateConfig(); } }) .catch(error => this.logger.error(error)) From b2cf34c8652e78e1ba244c4f26b1350872156e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:29:14 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(keepass):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B9=20`=E5=88=A0=E9=99=A4=20KeeWeb=20?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE`=20|=20Add=20setting=20ite?= =?UTF-8?q?m=20`Delete=20KeeWeb=20User=20Configuration`.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/README.md | 8 ++++++- public/README_zh_CN.md | 8 ++++++- public/i18n/en_US.json | 7 ++++++- public/i18n/zh_CHT.json | 7 ++++++- public/i18n/zh_CN.json | 7 ++++++- src/components/Settings.svelte | 26 ++++++++++++++++++++++- src/index.ts | 38 +++++++++++++++++++++++++++++++--- src/keeweb/locale.ts | 3 +-- 8 files changed, 93 insertions(+), 11 deletions(-) diff --git a/public/README.md b/public/README.md index d438df7..59363f2 100644 --- a/public/README.md +++ b/public/README.md @@ -111,8 +111,14 @@ This is a plugin for [SiYuan](https://github.com/siyuan-note/siyuan), developed * `Reset Settings` - * Resets all settings options to their default values. + * This is a button. + * Resets all settings options of this plugin to their default values. * Refreshes the page after resetting. + * `Delete KeeWeb User Configuration` + + * This is a button. + * Delete all KeeWeb user configurations. + * If the KeeWeb app does not load properly, you can use this button to initialize the Keeweb app. * `KeeWeb Settings` * `Plugins` diff --git a/public/README_zh_CN.md b/public/README_zh_CN.md index ee062b8..3c6ffaa 100644 --- a/public/README_zh_CN.md +++ b/public/README_zh_CN.md @@ -111,8 +111,14 @@ * `重置设置选项` - * 重置所有设置选项为默认选项 + * 这是一个按钮 + * 重置本插件所有设置选项为默认选项 * 重置后将刷新页面 + * `删除 KeeWeb 用户配置` + + * 这是一个按钮 + * 刪除所有 KeeWeb 用户配置 + * 若 KeeWeb 应用无法正常加载, 可使用该按钮初始化 KeeWeb 应用 * `KeeWeb 设置` * `插件设置` diff --git a/public/i18n/en_US.json b/public/i18n/en_US.json index f27ed94..0d377ef 100644 --- a/public/i18n/en_US.json +++ b/public/i18n/en_US.json @@ -15,10 +15,15 @@ "settings": { "generalSettings": { "reset": { - "description": "Reset all settings options to default (page will refresh after reset)", + "description": "Reset all settings options of this plugin to default (page will refresh after reset)", "text": "Reset", "title": "Reset Settings" }, + "deleteKeeWebConfig": { + "description": "Delete all KeeWeb user configurations (initialize KeeWeb app)", + "text": "Deletem", + "title": "Delete KeeWeb User Configuration" + }, "title": "General Settings" }, "keewebSettings": { diff --git a/public/i18n/zh_CHT.json b/public/i18n/zh_CHT.json index c8937c7..b34c448 100644 --- a/public/i18n/zh_CHT.json +++ b/public/i18n/zh_CHT.json @@ -15,10 +15,15 @@ "settings": { "generalSettings": { "reset": { - "description": "重置所有設置選項為默認選項(重置後將刷新頁面)", + "description": "重置本插件所有設置選項為默認選項(重置後將刷新頁面)", "text": "重置", "title": "重置設置選項" }, + "deleteKeeWebConfig": { + "description": "刪除所有 KeeWeb 用戶配置(初始化 KeeWeb 應用)", + "text": "刪除", + "title": "刪除 KeeWeb 用戶配置" + }, "title": "常規設置" }, "keewebSettings": { diff --git a/public/i18n/zh_CN.json b/public/i18n/zh_CN.json index 837a81d..150479b 100644 --- a/public/i18n/zh_CN.json +++ b/public/i18n/zh_CN.json @@ -15,10 +15,15 @@ "settings": { "generalSettings": { "reset": { - "description": "重置所有设置选项为默认选项(重置后将刷新页面)", + "description": "重置本插件所有设置选项为默认选项(重置后将刷新页面)", "text": "重置", "title": "重置设置选项" }, + "deleteKeeWebConfig": { + "description": "刪除所有 KeeWeb 用户配置(初始化 KeeWeb 应用)", + "text": "删除", + "title": "删除 KeeWeb 用户配置" + }, "title": "常规设置" }, "keewebSettings": { diff --git a/src/components/Settings.svelte b/src/components/Settings.svelte index 1f70cfa..b554d97 100644 --- a/src/components/Settings.svelte +++ b/src/components/Settings.svelte @@ -52,6 +52,16 @@ ); } + function deleteKeeWebConfig() { + plugin.siyuan.confirm( + i18n.settings.generalSettings.deleteKeeWebConfig.title, // 标题 + i18n.settings.generalSettings.deleteKeeWebConfig.description, // 文本 + async () => { + await plugin.deleteKeeWebUserConfig(); // 删除 KeeWeb 用户配置 + }, // 确认按钮回调 + ); + } + enum PanelKey { general, // 常规设置 keeweb, // KeeWeb 设置 @@ -112,11 +122,25 @@ + + + + + diff --git a/src/index.ts b/src/index.ts index a1d0220..5118106 100644 --- a/src/index.ts +++ b/src/index.ts @@ -371,6 +371,27 @@ export default class KeepassPlugin extends siyuan.Plugin { return this.saveData(KeepassPlugin.GLOBAL_CONFIG_NAME, JSON.stringify(this.config, undefined, 4)); } + /* 删除 KeeWeb 用户配置 */ + public async deleteKeeWebUserConfig(): Promise { + /* 删除 localStorage 相关的内容 */ + this.removeLocalStorageItems(); + + await Promise.allSettled([ + /* 删除 indexedDB 文件 */ + this.idb.FilesCache.clear(KeepassPlugin.IDB_SCHEMA.FilesCache.stores.files.name), + this.idb.PluginFiles.clear(KeepassPlugin.IDB_SCHEMA.PluginFiles.stores.files.name), + ]); + + /* 同步删除插件对应的数据 */ + await Promise.allSettled([ + this.saveLocalStorage(), + this.saveIDB(), + ]); + + /* 更新 KeeWeb 插件状态 */ + await this.updateKeeWebPluginStatus(); + } + /* 更新 keeweb 插件状态 */ public async updateKeeWebPluginStatus(): Promise { switch (true) { @@ -476,7 +497,6 @@ export default class KeepassPlugin extends siyuan.Plugin { /** * 获取 KeeWeb 相关的 localStorage 项 - * @param prefix 键名前缀 */ public getLocalStorageItems(): TLocal { this.local = {}; @@ -488,6 +508,17 @@ export default class KeepassPlugin extends siyuan.Plugin { return this.local; } + /** + * 删除 KeeWeb 相关的 localStorage 项 + */ + public removeLocalStorageItems(): void { + for (const key of Object.keys(globalThis.localStorage)) { + if (this.isLocalStorageKey(key)) { + globalThis.localStorage.removeItem(key); + } + } + } + /** * 加载 indexedDB */ @@ -525,8 +556,9 @@ export default class KeepassPlugin extends siyuan.Plugin { } /** - * 保存 indexedDB - * @param names 需要保存的数据库名, 默认保存所有数据库 + * 保存 indexedDB 中 KeeWeb 相关的数据 + * 完整同步 `indexedDB` -> `data/storage/petal/keepass/idb` + * @param names 需要保存的数据库名列表, 默认保存所有数据库 */ public async saveIDB(...names: TDBDatabaseName[]) { const db_name_set = new Set(names); diff --git a/src/keeweb/locale.ts b/src/keeweb/locale.ts index 2860a1f..bc55bb0 100644 --- a/src/keeweb/locale.ts +++ b/src/keeweb/locale.ts @@ -36,8 +36,7 @@ export function install(context: IContext) { // this._logger.debug("plugin:siyuan:locale-install"); const lang = mapLang( - getLocalStorage(LocalStorageKey.app_settings)?.locale - ?? globalThis.navigator.language + getLocalStorage(LocalStorageKey.app_settings)?.locale ?? "en" ); var i18n: I18N; From f0b9af871d1abaa971c5c477d929834beef2f137 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:07:44 +0800 Subject: [PATCH 3/3] chore(keepass): release v0.1.4 --- .github/workflows/release-please.yml | 2 +- package.json | 2 +- public/keeweb/plugins/siyuan/manifest.json | 2 +- public/plugin.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 1056fb0..7c451e7 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -14,7 +14,7 @@ permissions: env: PACKAGE_NAME: keepass - PACKAGE_VERSION: 0.1.3 + PACKAGE_VERSION: 0.1.4 jobs: release-please: diff --git a/package.json b/package.json index 7b76340..86be290 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "keepass", "private": true, - "version": "0.1.3", + "version": "0.1.4", "type": "module", "scripts": { "dev": "vite", diff --git a/public/keeweb/plugins/siyuan/manifest.json b/public/keeweb/plugins/siyuan/manifest.json index 781c6cb..f594c0d 100644 --- a/public/keeweb/plugins/siyuan/manifest.json +++ b/public/keeweb/plugins/siyuan/manifest.json @@ -1,5 +1,5 @@ { - "version": "0.1.3", + "version": "0.1.4", "manifestVersion": "0.1.0", "name": "siyuan", "description": "Establish a connection between KeeWeb and SiYuan", diff --git a/public/plugin.json b/public/plugin.json index d93f531..b4118ca 100644 --- a/public/plugin.json +++ b/public/plugin.json @@ -2,7 +2,7 @@ "name": "keepass", "author": "Zuoqiu Yingyi", "url": "https://github.com/Zuoqiu-Yingyi/siyuan-plugin-keepass", - "version": "0.1.3", + "version": "0.1.4", "minAppVersion": "2.10.3", "backends": [ "all"