Skip to content

Commit 33d6312

Browse files
authored
🐛 The plugin was not executed uninstall() when being uninstalled (#16243)
fix #16156
1 parent a156dc9 commit 33d6312

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

app/src/config/bazaar.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,9 +838,6 @@ export const bazaar = {
838838
}, response => {
839839
this._genMyHTML(bazaarType, app);
840840
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
841-
if (bazaarType === "plugins") {
842-
uninstall(app, packageName, true);
843-
}
844841
});
845842
});
846843
}
@@ -923,7 +920,7 @@ export const bazaar = {
923920
if (window.siyuan.config.bazaar.petalDisabled) {
924921
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
925922
item.classList.add("b3-card--disabled");
926-
uninstall(app, JSON.parse(item.getAttribute("data-obj")).name);
923+
uninstall(app, JSON.parse(item.getAttribute("data-obj")).name, false);
927924
});
928925
} else {
929926
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
@@ -961,7 +958,7 @@ export const bazaar = {
961958
}
962959
});
963960
} else {
964-
uninstall(app, dataObj.name);
961+
uninstall(app, dataObj.name, false);
965962
target.parentElement.querySelector('[data-type="setting"]').classList.add("fn__none");
966963
}
967964
});

app/src/plugin/loader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,11 @@ export const afterLoadPlugin = (plugin: Plugin) => {
211211
};
212212

213213
export const reloadPlugin = async (app: App, data: { upsertPlugins: string[], removePlugins: string[] }) => {
214-
data.removePlugins.concat(data.upsertPlugins).forEach((item) => {
215-
uninstall(app, item);
214+
data.removePlugins.forEach((item) => {
215+
uninstall(app, item, true);
216+
});
217+
data.upsertPlugins.forEach((item) => {
218+
uninstall(app, item, false);
216219
});
217220
loadPlugins(app, data.upsertPlugins).then(() => {
218221
app.plugins.forEach(item => {

app/src/plugin/uninstall.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {App} from "../index";
2-
import {Plugin} from "../plugin";
2+
import {Plugin} from "./index";
33
/// #if !MOBILE
44
import {getAllModels} from "../layout/getAll";
55
import {resizeTopBar} from "../layout/util";
@@ -8,20 +8,23 @@ import {Constants} from "../constants";
88
import {setStorageVal} from "../protyle/util/compatibility";
99
import {getAllEditor} from "../layout/getAll";
1010

11-
export const uninstall = (app: App, name: string, isUninstall = false) => {
11+
export const uninstall = (app: App, name: string, isUninstall: boolean) => {
1212
app.plugins.find((plugin: Plugin, index) => {
1313
if (plugin.name === name) {
14-
// rm command
1514
try {
1615
plugin.onunload();
17-
if (isUninstall) {
18-
plugin.uninstall();
19-
window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {};
20-
setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
21-
}
2216
} catch (e) {
2317
console.error(`plugin ${plugin.name} onunload error:`, e);
2418
}
19+
if (isUninstall) {
20+
try {
21+
plugin.uninstall();
22+
} catch (e) {
23+
console.error(`plugin ${plugin.name} uninstall error:`, e);
24+
}
25+
window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {};
26+
setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
27+
}
2528
// rm tab
2629
/// #if !MOBILE
2730
const modelsKeys = Object.keys(plugin.models);

0 commit comments

Comments
 (0)