Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions app/src/config/bazaar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,6 @@ export const bazaar = {
}, response => {
this._genMyHTML(bazaarType, app);
bazaar._onBazaar(response, bazaarType, ["themes", "icons"].includes(bazaarType));
if (bazaarType === "plugins") {
uninstall(app, packageName, true);
}
Comment on lines -841 to -843
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内核推送,前端不再需要处理

});
});
}
Expand Down Expand Up @@ -923,7 +920,7 @@ export const bazaar = {
if (window.siyuan.config.bazaar.petalDisabled) {
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
item.classList.add("b3-card--disabled");
uninstall(app, JSON.parse(item.getAttribute("data-obj")).name);
uninstall(app, JSON.parse(item.getAttribute("data-obj")).name, false);
});
} else {
bazaar.element.querySelectorAll("#configBazaarDownloaded .b3-card").forEach(item => {
Expand Down Expand Up @@ -961,7 +958,7 @@ export const bazaar = {
}
});
} else {
uninstall(app, dataObj.name);
uninstall(app, dataObj.name, false);
target.parentElement.querySelector('[data-type="setting"]').classList.add("fn__none");
}
});
Expand Down
7 changes: 5 additions & 2 deletions app/src/plugin/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@ export const afterLoadPlugin = (plugin: Plugin) => {
};

export const reloadPlugin = async (app: App, data: { upsertPlugins: string[], removePlugins: string[] }) => {
data.removePlugins.concat(data.upsertPlugins).forEach((item) => {
uninstall(app, item);
data.removePlugins.forEach((item) => {
uninstall(app, item, true);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

之前缺少 true 参数,导致没有执行插件的 uninstall() 方法

});
data.upsertPlugins.forEach((item) => {
uninstall(app, item, false);
});
loadPlugins(app, data.upsertPlugins).then(() => {
app.plugins.forEach(item => {
Expand Down
19 changes: 11 additions & 8 deletions app/src/plugin/uninstall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {App} from "../index";
import {Plugin} from "../plugin";
import {Plugin} from "./index";
/// #if !MOBILE
import {getAllModels} from "../layout/getAll";
import {resizeTopBar} from "../layout/util";
Expand All @@ -8,20 +8,23 @@ import {Constants} from "../constants";
import {setStorageVal} from "../protyle/util/compatibility";
import {getAllEditor} from "../layout/getAll";

export const uninstall = (app: App, name: string, isUninstall = false) => {
export const uninstall = (app: App, name: string, isUninstall: boolean) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uninstall() 函数之前默认是不执行 uninstall 的,太迷惑人了,改成必选参数以避免以后使用时混淆用途

app.plugins.find((plugin: Plugin, index) => {
if (plugin.name === name) {
// rm command
try {
plugin.onunload();
if (isUninstall) {
plugin.uninstall();
window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {};
setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
}
} catch (e) {
console.error(`plugin ${plugin.name} onunload error:`, e);
}
if (isUninstall) {
try {
plugin.uninstall();
} catch (e) {
console.error(`plugin ${plugin.name} uninstall error:`, e);
}
window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] = {};
setStorageVal(Constants.LOCAL_PLUGIN_DOCKS, window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS]);
}
Comment on lines -14 to +27
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改进卸载流程

// rm tab
/// #if !MOBILE
const modelsKeys = Object.keys(plugin.models);
Expand Down