Skip to content

Commit

Permalink
Merge pull request #9 from Zuoqiu-Yingyi/dev
Browse files Browse the repository at this point in the history
chore: release v0.1.4
  • Loading branch information
Zuoqiu-Yingyi authored Oct 22, 2023
2 parents e345c67 + f0b9af8 commit 3ff234b
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:

env:
PACKAGE_NAME: keepass
PACKAGE_VERSION: 0.1.3
PACKAGE_VERSION: 0.1.4

jobs:
release-please:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "keepass",
"private": true,
"version": "0.1.3",
"version": "0.1.4",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
8 changes: 7 additions & 1 deletion public/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 7 additions & 1 deletion public/README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,14 @@

* `重置设置选项`

* 重置所有设置选项为默认选项
* 这是一个按钮
* 重置本插件所有设置选项为默认选项
* 重置后将刷新页面
* `删除 KeeWeb 用户配置`

* 这是一个按钮
* 刪除所有 KeeWeb 用户配置
* 若 KeeWeb 应用无法正常加载, 可使用该按钮初始化 KeeWeb 应用
* `KeeWeb 设置`

* `插件设置`
Expand Down
7 changes: 6 additions & 1 deletion public/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion public/i18n/zh_CHT.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
"settings": {
"generalSettings": {
"reset": {
"description": "重置所有設置選項為默認選項(重置後將刷新頁面)",
"description": "重置本插件所有設置選項為默認選項(重置後將刷新頁面)",
"text": "重置",
"title": "重置設置選項"
},
"deleteKeeWebConfig": {
"description": "刪除所有 KeeWeb 用戶配置(初始化 KeeWeb 應用)",
"text": "刪除",
"title": "刪除 KeeWeb 用戶配置"
},
"title": "常規設置"
},
"keewebSettings": {
Expand Down
7 changes: 6 additions & 1 deletion public/i18n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
"settings": {
"generalSettings": {
"reset": {
"description": "重置所有设置选项为默认选项(重置后将刷新页面)",
"description": "重置本插件所有设置选项为默认选项(重置后将刷新页面)",
"text": "重置",
"title": "重置设置选项"
},
"deleteKeeWebConfig": {
"description": "刪除所有 KeeWeb 用户配置(初始化 KeeWeb 应用)",
"text": "删除",
"title": "删除 KeeWeb 用户配置"
},
"title": "常规设置"
},
"keewebSettings": {
Expand Down
2 changes: 1 addition & 1 deletion public/keeweb/plugins/siyuan/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion public/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
26 changes: 25 additions & 1 deletion src/components/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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 设置
Expand Down Expand Up @@ -112,11 +122,25 @@
<Input
slot="input"
type={ItemType.button}
settingKey="Reset"
settingKey="reset"
settingValue={i18n.settings.generalSettings.reset.text}
on:clicked={resetOptions}
/>
</Item>

<!-- 删除 KeeWeb 用户配置 -->
<Item
title={i18n.settings.generalSettings.deleteKeeWebConfig.title}
text={i18n.settings.generalSettings.deleteKeeWebConfig.description}
>
<Input
slot="input"
type={ItemType.button}
settingKey="deleteKeeWebConfig"
settingValue={i18n.settings.generalSettings.deleteKeeWebConfig.text}
on:clicked={deleteKeeWebConfig}
/>
</Item>
</Panel>

<!-- KeeWeb 设置面板 -->
Expand Down
39 changes: 35 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -372,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<void> {
/* 删除 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<void> {
switch (true) {
Expand Down Expand Up @@ -477,7 +497,6 @@ export default class KeepassPlugin extends siyuan.Plugin {

/**
* 获取 KeeWeb 相关的 localStorage 项
* @param prefix 键名前缀
*/
public getLocalStorageItems(): TLocal {
this.local = {};
Expand All @@ -489,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
*/
Expand Down Expand Up @@ -526,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);
Expand Down
3 changes: 1 addition & 2 deletions src/keeweb/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ff234b

Please sign in to comment.