This commit is contained in:
Vanessa 2023-05-31 15:39:42 +08:00
parent 083f20357d
commit ac662902d1
3 changed files with 31 additions and 3 deletions

View file

@ -18,6 +18,7 @@ export class Plugin {
public data: any = {};
public name: string;
public topBarIcons: Element[] = [];
public statusBarIcons: Element[] = [];
public commands: ICommand[] = [];
public models: {
/// #if !MOBILE
@ -68,7 +69,7 @@ export class Plugin {
public addTopBar(options: {
icon: string,
title: string,
position?: "right",
position?: "right" | "left",
callback: (evt: MouseEvent) => void
}) {
const iconElement = document.createElement("div");
@ -84,12 +85,23 @@ export class Plugin {
iconElement.setAttribute("aria-label", options.title);
iconElement.innerHTML = options.icon.startsWith("icon") ? `<svg><use xlink:href="#${options.icon}"></use></svg>` : options.icon;
iconElement.addEventListener("click", options.callback);
iconElement.setAttribute("data-position", options.position);
iconElement.setAttribute("data-position", options.position || "right");
}
this.topBarIcons.push(iconElement);
return iconElement;
}
public addStatusBar(options: {
element: HTMLElement,
position?: "right" | "left",
}) {
/// #if !MOBILE
options.element.setAttribute("data-position", options.position || "right");
this.statusBarIcons.push(options.element);
return options.element;
/// #endif
}
public openSetting() {
// 打开设置
}

View file

@ -114,6 +114,16 @@ export const afterLoadPlugin = (plugin: Plugin) => {
}
});
}
/// #if !MOBILE
plugin.statusBarIcons.forEach(element => {
const statusElement = document.getElementById("status")
if (element.getAttribute("data-position") === "right") {
statusElement.insertAdjacentElement("beforeend", element);
} else {
statusElement.insertAdjacentElement("afterbegin", element);
}
});
/// #endif
if (isWindow()) {
return;
}

View file

@ -20,10 +20,16 @@ export const uninstall = (app: App, name: string) => {
custom.parent.parent.removeTab(custom.parent.id);
}
});
// rm topbar
// rm topBar
plugin.topBarIcons.forEach(item => {
item.remove();
});
// rm statusBar
/// #if !MOBILE
plugin.statusBarIcons.forEach(item => {
item.remove();
});
/// #endif
// rm dock
const docksKeys = Object.keys(plugin.docks);
docksKeys.forEach(key => {