Skip to content

Commit ca751de

Browse files
committed
1 parent e039af5 commit ca751de

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.4.6 2026
4+
5+
* [Improve error handling and security for plugin data storage methods](https://github.com/siyuan-note/siyuan/pull/16717)
6+
37
## v0.4.5 2025-12-27
48

59
* [Improve minimum version requirements for marketplace packages](https://github.com/siyuan-note/siyuan/issues/16688)

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ export default class PluginSample extends Plugin {
148148
const textareaElement = document.createElement("textarea");
149149
this.setting = new Setting({
150150
confirmCallback: () => {
151-
this.saveData(STORAGE_NAME, {readonlyText: textareaElement.value});
151+
this.saveData(STORAGE_NAME, {readonlyText: textareaElement.value}).catch(e => {
152+
showMessage(`[${this.name}] save data [${STORAGE_NAME}] fail: `, e);
153+
});
152154
}
153155
});
154156
this.setting.addItem({
@@ -240,25 +242,30 @@ export default class PluginSample extends Plugin {
240242
this.removeData(STORAGE_NAME).then(() => {
241243
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
242244
showMessage(`[${this.name}]: ${this.i18n.removedData}`);
245+
}).catch(e => {
246+
showMessage(`[${this.name}] remove data [${STORAGE_NAME}] fail: `, e);
243247
});
244248
});
245249
});
246250
this.addStatusBar({
247251
element: statusIconTemp.content.firstElementChild as HTMLElement,
248252
});
249-
this.loadData(STORAGE_NAME);
253+
this.loadData(STORAGE_NAME).catch(e => {
254+
console.log(`[${this.name}] load data [${STORAGE_NAME}] fail: `, e);
255+
});
250256
console.log(`frontend: ${getFrontend()}; backend: ${getBackend()}`);
251257
}
252258

253259
onunload() {
254260
console.log(this.i18n.byePlugin);
255261
}
256262

257-
async uninstall() {
263+
uninstall() {
258264
// 卸载插件时删除插件数据
259265
// Delete plugin data when uninstalling the plugin
260-
await this.removeData(STORAGE_NAME);
261-
console.log("uninstall");
266+
this.removeData(STORAGE_NAME).catch(e => {
267+
showMessage(`uninstall [${this.name}] remove data [${STORAGE_NAME}] fail: ${e.msg}`);
268+
});
262269
}
263270

264271
// 使用 saveData() 存储的数据发生变更时触发,注释掉则自动禁用插件再重新启用

0 commit comments

Comments
 (0)