mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-15 03:28:07 +01:00
This commit is contained in:
parent
da0afd39a8
commit
a556716dcc
7 changed files with 35 additions and 22 deletions
|
|
@ -63,19 +63,16 @@ export class Plugin {
|
|||
const iconElement = document.createElement("div");
|
||||
if (isMobile()) {
|
||||
iconElement.className = "b3-menu__item";
|
||||
iconElement.setAttribute("aria-label", options.title);
|
||||
iconElement.setAttribute("data-menu", "true");
|
||||
iconElement.innerHTML = (options.icon.startsWith("icon") ? `<svg class="b3-menu__icon"><use xlink:href="#${options.icon}"></use></svg>` : options.icon) +
|
||||
`<span class="b3-menu__label">${options.title}</span>`;
|
||||
iconElement.addEventListener("click", options.callback);
|
||||
document.querySelector("#menuAbout").after(iconElement);
|
||||
} else if (!isWindow()) {
|
||||
iconElement.className = "toolbar__item b3-tooltips b3-tooltips__sw";
|
||||
iconElement.setAttribute("aria-label", options.title);
|
||||
iconElement.setAttribute("data-menu", "true");
|
||||
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
|
||||
iconElement.addEventListener("click", options.callback);
|
||||
document.querySelector("#" + (options.position === "right" ? "barSearch" : "drag")).before(iconElement);
|
||||
iconElement.setAttribute("data-position", options.position );
|
||||
}
|
||||
this.topBarIcons.push(iconElement);
|
||||
return iconElement;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import {fetchPost} from "../util/fetch";
|
||||
import {fetchPost, fetchSyncPost} from "../util/fetch";
|
||||
import {App} from "../index";
|
||||
import {Plugin} from "./index";
|
||||
/// #if !MOBILE
|
||||
|
|
@ -18,17 +18,16 @@ const runCode = (code: string, sourceURL: string) => {
|
|||
return window.eval("(function anonymous(require, module, exports){".concat(code, "\n})\n//# sourceURL=").concat(sourceURL, "\n"));
|
||||
};
|
||||
|
||||
export const loadPlugins = (app: App) => {
|
||||
fetchPost("/api/petal/loadPetals", {}, response => {
|
||||
let css = "";
|
||||
response.data.forEach((item: IPluginData) => {
|
||||
loadPluginJS(app, item);
|
||||
css += item.css || "" + "\n";
|
||||
});
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.textContent = css;
|
||||
document.head.append(styleElement);
|
||||
export const loadPlugins = async (app: App) => {
|
||||
const response = await fetchSyncPost("/api/petal/loadPetals");
|
||||
let css = "";
|
||||
response.data.forEach((item: IPluginData) => {
|
||||
loadPluginJS(app, item);
|
||||
css += item.css || "" + "\n";
|
||||
});
|
||||
const styleElement = document.createElement("style");
|
||||
styleElement.textContent = css;
|
||||
document.head.append(styleElement);
|
||||
};
|
||||
|
||||
const loadPluginJS = (app: App, item: IPluginData) => {
|
||||
|
|
@ -58,7 +57,7 @@ const loadPluginJS = (app: App, item: IPluginData) => {
|
|||
try {
|
||||
plugin.onload();
|
||||
} catch (e) {
|
||||
console.error(`plugin ${item.name} load error:`, e);
|
||||
console.error(`plugin ${item.name} onload error:`, e);
|
||||
}
|
||||
return plugin;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,7 +7,11 @@ export const uninstall = (app: App, name: string) => {
|
|||
app.plugins.find((plugin: Plugin, index) => {
|
||||
if (plugin.name === name) {
|
||||
// rm command
|
||||
plugin.onunload();
|
||||
try {
|
||||
plugin.onunload();
|
||||
} catch (e) {
|
||||
console.error(`plugin ${plugin.name} onunload error:`, e);
|
||||
}
|
||||
// rm tab
|
||||
const modelsKeys = Object.keys(plugin.models);
|
||||
getAllModels().custom.forEach(custom => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue