Vanessa 2025-08-12 18:20:33 +08:00
parent e103b5c2f0
commit 98a9635dd3
2 changed files with 29 additions and 4 deletions

View file

@ -6,7 +6,7 @@ import {isMobile, isWindow} from "../util/functions";
import {Custom} from "../layout/dock/Custom";
import {getAllModels} from "../layout/getAll";
import {Tab} from "../layout/Tab";
import {setPanelFocus} from "../layout/util";
import {resizeTopBar, setPanelFocus} from "../layout/util";
import {getDockByType} from "../layout/tabUtil";
///#else
import {MobileCustom} from "../mobile/dock/MobileCustom";
@ -194,6 +194,17 @@ export class Plugin {
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
iconElement.addEventListener("click", options.callback);
iconElement.setAttribute("data-location", options.position || "right");
resizeTopBar();
}
if (isMobile()) {
if (!window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(iconElement.id)) {
document.querySelector("#menuAbout")?.after(iconElement);
}
} else if (!isWindow()) {
if (window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(iconElement.id)) {
iconElement.classList.add("fn__none");
}
document.querySelector("#" + (iconElement.getAttribute("data-location") === "right" ? "barPlugins" : "drag"))?.before(iconElement);
}
this.topBarIcons.push(iconElement);
return iconElement;
@ -206,6 +217,14 @@ export class Plugin {
/// #if !MOBILE
options.element.setAttribute("data-location", options.position || "right");
this.statusBarIcons.push(options.element);
const statusElement = document.getElementById("status");
if (statusElement) {
if (options.element.getAttribute("data-location") === "right") {
statusElement.insertAdjacentElement("beforeend", options.element);
} else {
statusElement.insertAdjacentElement("afterbegin", options.element);
}
}
return options.element;
/// #endif
}

View file

@ -9,7 +9,7 @@ import {getFrontend, isMobile, isWindow} from "../util/functions";
import {Constants} from "../constants";
import {uninstall} from "./uninstall";
import {setStorageVal} from "../protyle/util/compatibility";
import { getAllEditor } from "../layout/getAll";
import {getAllEditor} from "../layout/getAll";
const requireFunc = (key: string) => {
const modules = {
@ -92,7 +92,7 @@ export const loadPlugin = async (app: App, item: IPluginData) => {
afterLoadPlugin(plugin);
saveLayout();
getAllEditor().forEach(editor => {
editor.protyle.toolbar.update(editor.protyle);
editor.protyle.toolbar.update(editor.protyle);
});
return plugin;
};
@ -129,6 +129,9 @@ export const afterLoadPlugin = (plugin: Plugin) => {
if (!isWindow() || isMobile()) {
plugin.topBarIcons.forEach(element => {
if (document.contains(element)) {
return;
}
if (isMobile()) {
if (!window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(element.id)) {
document.querySelector("#menuAbout").after(element);
@ -144,6 +147,9 @@ export const afterLoadPlugin = (plugin: Plugin) => {
/// #if !MOBILE
resizeTopBar();
plugin.statusBarIcons.forEach(element => {
if (document.contains(element)) {
return;
}
const statusElement = document.getElementById("status");
if (element.getAttribute("data-location") === "right") {
statusElement.insertAdjacentElement("beforeend", element);
@ -167,7 +173,7 @@ export const afterLoadPlugin = (plugin: Plugin) => {
updateDock(dockItem, index, plugin, "Bottom");
});
Object.keys(plugin.docks).forEach(key => {
if (window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] && window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key]) {
if (window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name] && window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key]) {
plugin.docks[key].config = window.siyuan.storage[Constants.LOCAL_PLUGIN_DOCKS][plugin.name][key];
}
const dock = plugin.docks[key];