2023-03-03 10:45:30 +08:00
|
|
|
|
import {getWorkspaceName} from "../util/noRelyPCFunction";
|
2023-05-11 09:55:33 +08:00
|
|
|
|
import {setStorageVal, updateHotkeyTip} from "../protyle/util/compatibility";
|
2023-03-03 10:45:30 +08:00
|
|
|
|
import {processSync} from "../dialog/processSystem";
|
|
|
|
|
|
import {goBack, goForward} from "../util/backForward";
|
|
|
|
|
|
import {syncGuide} from "../sync/syncGuide";
|
|
|
|
|
|
import {workspaceMenu} from "../menus/workspace";
|
|
|
|
|
|
import {editor} from "../config/editor";
|
|
|
|
|
|
import {MenuItem} from "../menus/Menu";
|
|
|
|
|
|
import {setMode} from "../util/assets";
|
|
|
|
|
|
import {openSetting} from "../config";
|
|
|
|
|
|
import {openSearch} from "../search/spread";
|
2023-05-08 21:00:41 +08:00
|
|
|
|
import {App} from "../index";
|
2023-05-11 09:55:33 +08:00
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
import {webFrame} from "electron";
|
|
|
|
|
|
/// #endif
|
|
|
|
|
|
import {Constants} from "../constants";
|
|
|
|
|
|
import {isBrowser, isWindow} from "../util/functions";
|
2023-06-11 23:24:26 +08:00
|
|
|
|
import {Menu} from "../plugin/Meun";
|
2023-06-12 11:50:37 +08:00
|
|
|
|
import {fetchPost} from "../util/fetch";
|
|
|
|
|
|
import {escapeAttr} from "../util/escape";
|
|
|
|
|
|
import {needSubscribe} from "../util/needSubscribe";
|
|
|
|
|
|
import * as dayjs from "dayjs";
|
2023-03-03 10:45:30 +08:00
|
|
|
|
|
|
|
|
|
|
export const updateEditModeElement = () => {
|
|
|
|
|
|
const target = document.querySelector("#barReadonly");
|
|
|
|
|
|
if (window.siyuan.config.editor.readOnly) {
|
|
|
|
|
|
target.classList.add("toolbar__item--active");
|
|
|
|
|
|
target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editMode} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}`);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconPreview");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
target.classList.remove("toolbar__item--active");
|
|
|
|
|
|
target.setAttribute("aria-label", `${window.siyuan.languages.use} ${window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}`);
|
|
|
|
|
|
target.querySelector("use").setAttribute("xlink:href", "#iconEdit");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-04-06 22:25:50 +08:00
|
|
|
|
|
2023-05-08 21:00:41 +08:00
|
|
|
|
export const initBar = (app: App) => {
|
2023-03-03 10:45:30 +08:00
|
|
|
|
const toolbarElement = document.getElementById("toolbar");
|
|
|
|
|
|
toolbarElement.innerHTML = `
|
|
|
|
|
|
<div id="barWorkspace" class="toolbar__item">
|
|
|
|
|
|
<span class="toolbar__text">${getWorkspaceName()}</span>
|
|
|
|
|
|
<svg class="toolbar__svg"><use xlink:href="#iconDown"></use></svg>
|
|
|
|
|
|
</div>
|
2023-03-10 10:00:03 +08:00
|
|
|
|
<div id="barSync" class="toolbar__item b3-tooltips b3-tooltips__se${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.config.sync.stat || (window.siyuan.languages.syncNow + " " + updateHotkeyTip(window.siyuan.config.keymap.general.syncNow.custom))}">
|
2023-03-03 10:45:30 +08:00
|
|
|
|
<svg><use xlink:href="#iconCloudSucc"></use></svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<button id="barBack" data-menu="true" class="toolbar__item toolbar__item--disabled b3-tooltips b3-tooltips__se" aria-label="${window.siyuan.languages.goBack} ${updateHotkeyTip(window.siyuan.config.keymap.general.goBack.custom)}">
|
|
|
|
|
|
<svg><use xlink:href="#iconBack"></use></svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button id="barForward" data-menu="true" class="toolbar__item toolbar__item--disabled b3-tooltips b3-tooltips__se" aria-label="${window.siyuan.languages.goForward} ${updateHotkeyTip(window.siyuan.config.keymap.general.goForward.custom)}">
|
|
|
|
|
|
<svg><use xlink:href="#iconForward"></use></svg>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<div class="fn__flex-1 fn__ellipsis" id="drag"><span class="fn__none">开发版,使用前请进行备份 Development version, please backup before use</span></div>
|
2023-03-10 10:00:03 +08:00
|
|
|
|
<div id="toolbarVIP" class="fn__flex${window.siyuan.config.readonly ? " fn__none" : ""}"></div>
|
2023-06-03 17:55:45 +08:00
|
|
|
|
<div id="barPlugins" class="toolbar__item b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.plugin}">
|
|
|
|
|
|
<svg><use xlink:href="#iconPlugin"></use></svg>
|
|
|
|
|
|
</div>
|
2023-03-03 10:45:30 +08:00
|
|
|
|
<div id="barSearch" class="toolbar__item b3-tooltips b3-tooltips__sw" aria-label="${window.siyuan.languages.globalSearch} ${updateHotkeyTip(window.siyuan.config.keymap.general.globalSearch.custom)}">
|
|
|
|
|
|
<svg><use xlink:href="#iconSearch"></use></svg>
|
|
|
|
|
|
</div>
|
2023-05-11 09:55:33 +08:00
|
|
|
|
<div id="barZoom" class="toolbar__item b3-tooltips b3-tooltips__sw${(window.siyuan.storage[Constants.LOCAL_ZOOM] === 1 || isBrowser()) ? " fn__none" : ""}" aria-label="${window.siyuan.languages.zoom}">
|
|
|
|
|
|
<svg><use xlink:href="#iconZoom${window.siyuan.storage[Constants.LOCAL_ZOOM] > 1 ? "In" : "Out"}"></use></svg>
|
|
|
|
|
|
</div>
|
2023-03-10 10:00:03 +08:00
|
|
|
|
<div id="barReadonly" class="toolbar__item b3-tooltips b3-tooltips__sw${window.siyuan.config.readonly ? " fn__none" : ""}${window.siyuan.config.editor.readOnly ? " toolbar__item--active" : ""}" aria-label="${window.siyuan.languages.use} ${window.siyuan.config.editor.readOnly ? window.siyuan.languages.editMode : window.siyuan.languages.editReadonly} ${updateHotkeyTip(window.siyuan.config.keymap.general.editMode.custom)}">
|
2023-03-03 10:45:30 +08:00
|
|
|
|
<svg><use xlink:href="#icon${window.siyuan.config.editor.readOnly ? "Preview" : "Edit"}"></use></svg>
|
|
|
|
|
|
</div>
|
2023-03-10 10:00:03 +08:00
|
|
|
|
<div id="barMode" class="toolbar__item b3-tooltips b3-tooltips__sw${window.siyuan.config.readonly ? " fn__none" : ""}" aria-label="${window.siyuan.languages.appearanceMode}">
|
2023-03-03 10:45:30 +08:00
|
|
|
|
<svg><use xlink:href="#icon${window.siyuan.config.appearance.modeOS ? "Mode" : (window.siyuan.config.appearance.mode === 0 ? "Light" : "Dark")}"></use></svg>
|
|
|
|
|
|
</div>
|
2023-05-27 18:34:39 +08:00
|
|
|
|
<div id="barMore" class="toolbar__item">
|
|
|
|
|
|
<svg><use xlink:href="#iconMore"></use></svg>
|
|
|
|
|
|
</div>
|
2023-03-03 10:45:30 +08:00
|
|
|
|
<div class="fn__flex" id="windowControls"></div>`;
|
|
|
|
|
|
processSync();
|
|
|
|
|
|
toolbarElement.addEventListener("click", (event: MouseEvent) => {
|
|
|
|
|
|
let target = event.target as HTMLElement;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
if (typeof event.detail === "string") {
|
|
|
|
|
|
target = toolbarElement.querySelector("#" + event.detail);
|
|
|
|
|
|
}
|
2023-03-03 10:45:30 +08:00
|
|
|
|
while (!target.classList.contains("toolbar")) {
|
2023-05-27 18:34:39 +08:00
|
|
|
|
const targetId = typeof event.detail === "string" ? event.detail : target.id;
|
|
|
|
|
|
if (targetId === "barBack") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goBack(app);
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barMore") {
|
|
|
|
|
|
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
|
|
|
|
|
window.siyuan.menus.menu.element.getAttribute("data-name") === "barmore") {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
window.siyuan.menus.menu.element.setAttribute("data-name", "barmore");
|
|
|
|
|
|
(target.getAttribute("data-hideids") || "").split(",").forEach((itemId) => {
|
|
|
|
|
|
const hideElement = toolbarElement.querySelector("#" + itemId);
|
2023-06-01 20:50:49 +08:00
|
|
|
|
const useElement = hideElement.querySelector("use");
|
2023-05-31 11:00:07 +08:00
|
|
|
|
const menuOptions: IMenu = {
|
2023-05-27 18:34:39 +08:00
|
|
|
|
label: itemId === "toolbarVIP" ? window.siyuan.languages.account : hideElement.getAttribute("aria-label"),
|
2023-05-31 11:00:07 +08:00
|
|
|
|
icon: itemId === "toolbarVIP" ? "iconAccount" : (useElement ? useElement.getAttribute("xlink:href").substring(1) : undefined),
|
2023-05-27 18:34:39 +08:00
|
|
|
|
click: () => {
|
|
|
|
|
|
if (itemId.startsWith("plugin")) {
|
|
|
|
|
|
hideElement.dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
toolbarElement.dispatchEvent(new CustomEvent("click", {detail: itemId}));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-31 11:00:07 +08:00
|
|
|
|
};
|
|
|
|
|
|
if (!useElement) {
|
2023-06-03 21:45:24 +08:00
|
|
|
|
const svgElement = hideElement.querySelector("svg").cloneNode(true) as HTMLElement;
|
2023-05-31 11:00:07 +08:00
|
|
|
|
svgElement.classList.add("b3-menu__icon");
|
|
|
|
|
|
menuOptions.iconHTML = svgElement.outerHTML;
|
|
|
|
|
|
}
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem(menuOptions).element);
|
2023-05-27 18:34:39 +08:00
|
|
|
|
});
|
|
|
|
|
|
const rect = target.getBoundingClientRect();
|
|
|
|
|
|
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
|
|
|
|
|
} else if (targetId === "barForward") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
goForward(app);
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barSync") {
|
2023-05-15 13:54:30 +08:00
|
|
|
|
syncGuide(app);
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barWorkspace") {
|
2023-05-08 21:00:41 +08:00
|
|
|
|
workspaceMenu(app, target.getBoundingClientRect());
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barReadonly") {
|
2023-03-03 10:45:30 +08:00
|
|
|
|
editor.setReadonly();
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barMode") {
|
2023-03-03 10:45:30 +08:00
|
|
|
|
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
|
|
|
|
|
window.siyuan.menus.menu.element.getAttribute("data-name") === "barmode") {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
window.siyuan.menus.menu.element.setAttribute("data-name", "barmode");
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.themeLight,
|
|
|
|
|
|
icon: "iconLight",
|
|
|
|
|
|
current: window.siyuan.config.appearance.mode === 0 && !window.siyuan.config.appearance.modeOS,
|
|
|
|
|
|
click: () => {
|
|
|
|
|
|
setMode(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.themeDark,
|
|
|
|
|
|
current: window.siyuan.config.appearance.mode === 1 && !window.siyuan.config.appearance.modeOS,
|
|
|
|
|
|
icon: "iconDark",
|
|
|
|
|
|
click: () => {
|
|
|
|
|
|
setMode(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.themeOS,
|
|
|
|
|
|
current: window.siyuan.config.appearance.modeOS,
|
|
|
|
|
|
icon: "iconMode",
|
|
|
|
|
|
click: () => {
|
|
|
|
|
|
setMode(2);
|
|
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
2023-05-27 18:34:39 +08:00
|
|
|
|
let rect = target.getBoundingClientRect();
|
|
|
|
|
|
if (rect.width === 0) {
|
|
|
|
|
|
rect = toolbarElement.querySelector("#barMore").getBoundingClientRect();
|
|
|
|
|
|
}
|
2023-03-03 10:45:30 +08:00
|
|
|
|
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "toolbarVIP") {
|
2023-03-10 10:00:03 +08:00
|
|
|
|
if (!window.siyuan.config.readonly) {
|
2023-05-08 21:00:41 +08:00
|
|
|
|
const dialogSetting = openSetting(app);
|
2023-03-10 10:00:03 +08:00
|
|
|
|
dialogSetting.element.querySelector('.b3-tab-bar [data-name="account"]').dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
}
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barSearch") {
|
2023-05-18 19:27:21 +08:00
|
|
|
|
openSearch({
|
|
|
|
|
|
app,
|
|
|
|
|
|
hotkey: window.siyuan.config.keymap.general.globalSearch.custom
|
|
|
|
|
|
});
|
2023-03-03 10:45:30 +08:00
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-06-03 17:55:45 +08:00
|
|
|
|
} else if (targetId === "barPlugins") {
|
|
|
|
|
|
openPlugin(app, target);
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-05-27 18:34:39 +08:00
|
|
|
|
} else if (targetId === "barZoom") {
|
2023-05-11 09:55:33 +08:00
|
|
|
|
if (!window.siyuan.menus.menu.element.classList.contains("fn__none") &&
|
|
|
|
|
|
window.siyuan.menus.menu.element.getAttribute("data-name") === "barZoom") {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
window.siyuan.menus.menu.element.setAttribute("data-name", "barZoom");
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.zoomIn,
|
|
|
|
|
|
icon: "iconZoomIn",
|
|
|
|
|
|
accelerator: "⌘=",
|
|
|
|
|
|
click: () => {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("zoomIn");
|
2023-05-11 09:55:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.zoomOut,
|
|
|
|
|
|
accelerator: "⌘-",
|
|
|
|
|
|
icon: "iconZoomOut",
|
|
|
|
|
|
click: () => {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("zoomOut");
|
2023-05-11 09:55:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
|
|
|
|
|
window.siyuan.menus.menu.append(new MenuItem({
|
|
|
|
|
|
label: window.siyuan.languages.reset,
|
|
|
|
|
|
accelerator: "⌘0",
|
|
|
|
|
|
click: () => {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
setZoom("restore");
|
2023-05-11 09:55:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
}).element);
|
2023-05-27 18:34:39 +08:00
|
|
|
|
let rect = target.getBoundingClientRect();
|
|
|
|
|
|
if (rect.width === 0) {
|
|
|
|
|
|
rect = toolbarElement.querySelector("#barMore").getBoundingClientRect();
|
|
|
|
|
|
}
|
2023-05-11 09:55:33 +08:00
|
|
|
|
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
break;
|
2023-03-03 10:45:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
target = target.parentElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-06-12 11:50:37 +08:00
|
|
|
|
const barSyncElement = toolbarElement.querySelector("#barSync");
|
|
|
|
|
|
barSyncElement.addEventListener("mouseenter", (event) => {
|
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
fetchPost("/api/sync/getSyncInfo", {}, (response) => {
|
|
|
|
|
|
let html = ""
|
|
|
|
|
|
if (!window.siyuan.config.sync.enabled || (0 === window.siyuan.config.sync.provider && needSubscribe(""))) {
|
|
|
|
|
|
html = response.data.stat;
|
|
|
|
|
|
} else {
|
2023-06-12 12:05:46 +08:00
|
|
|
|
html = window.siyuan.languages._kernel[82].replace("%s", dayjs(response.data.synced).format("YYYY-MM-DD HH:mm")) + " " + response.data.kernel + "\n\n"
|
2023-06-12 11:50:37 +08:00
|
|
|
|
response.data.kernels.forEach((item: {
|
|
|
|
|
|
os: string;
|
|
|
|
|
|
ver: string;
|
|
|
|
|
|
hostname: string;
|
|
|
|
|
|
id: string;
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
html += `${item.os}-${item.ver} ${item.hostname} ${item.id}\n`
|
|
|
|
|
|
})
|
|
|
|
|
|
if (response.data.kernels.length > 0) {
|
|
|
|
|
|
html += "\n"
|
|
|
|
|
|
}
|
|
|
|
|
|
html += response.data.stat;
|
|
|
|
|
|
}
|
|
|
|
|
|
barSyncElement.setAttribute("aria-label", escapeAttr(html));
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2023-03-03 10:45:30 +08:00
|
|
|
|
};
|
2023-05-11 09:55:33 +08:00
|
|
|
|
|
|
|
|
|
|
export const setZoom = (type: "zoomIn" | "zoomOut" | "restore") => {
|
|
|
|
|
|
/// #if !BROWSER
|
|
|
|
|
|
const isTabWindow = isWindow();
|
|
|
|
|
|
let zoom = 1;
|
|
|
|
|
|
if (type === "zoomIn") {
|
|
|
|
|
|
Constants.SIZE_ZOOM.find((item, index) => {
|
|
|
|
|
|
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
|
|
|
|
|
|
zoom = Constants.SIZE_ZOOM[index + 1] || 3;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else if (type === "zoomOut") {
|
|
|
|
|
|
Constants.SIZE_ZOOM.find((item, index) => {
|
|
|
|
|
|
if (item === window.siyuan.storage[Constants.LOCAL_ZOOM]) {
|
|
|
|
|
|
zoom = Constants.SIZE_ZOOM[index - 1] || 0.25;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
webFrame.setZoomFactor(zoom);
|
|
|
|
|
|
window.siyuan.storage[Constants.LOCAL_ZOOM] = zoom;
|
|
|
|
|
|
if (!isTabWindow) {
|
|
|
|
|
|
setStorageVal(Constants.LOCAL_ZOOM, zoom);
|
|
|
|
|
|
}
|
|
|
|
|
|
const barZoomElement = document.getElementById("barZoom");
|
|
|
|
|
|
if (zoom === 1) {
|
|
|
|
|
|
barZoomElement.classList.add("fn__none");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (zoom > 1) {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomIn");
|
2023-05-11 09:55:33 +08:00
|
|
|
|
} else {
|
2023-05-11 09:56:17 +08:00
|
|
|
|
barZoomElement.querySelector("use").setAttribute("xlink:href", "#iconZoomOut");
|
2023-05-11 09:55:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
barZoomElement.classList.remove("fn__none");
|
|
|
|
|
|
}
|
|
|
|
|
|
/// #endif
|
2023-05-11 09:56:17 +08:00
|
|
|
|
};
|
2023-06-03 17:55:45 +08:00
|
|
|
|
|
|
|
|
|
|
const openPlugin = (app: App, target: Element) => {
|
|
|
|
|
|
const menu = new Menu("topBarPlugin");
|
|
|
|
|
|
let hasPlugin = false;
|
|
|
|
|
|
app.plugins.forEach((plugin) => {
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
const hasSetting = plugin.setting || plugin.__proto__.hasOwnProperty("openSetting");
|
|
|
|
|
|
plugin.topBarIcons.forEach(item => {
|
2023-06-03 21:45:24 +08:00
|
|
|
|
const hasUnpin = window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].includes(item.id);
|
|
|
|
|
|
const submenu = [{
|
|
|
|
|
|
icon: "iconPin",
|
|
|
|
|
|
label: hasUnpin ? window.siyuan.languages.pin : window.siyuan.languages.unpin,
|
2023-06-03 17:55:45 +08:00
|
|
|
|
click() {
|
2023-06-03 21:45:24 +08:00
|
|
|
|
if (hasUnpin) {
|
|
|
|
|
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].splice(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].indexOf(item.id), 1);
|
2023-06-04 00:13:54 +08:00
|
|
|
|
item.classList.remove("fn__none");
|
2023-06-03 21:45:24 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN].push(item.id);
|
|
|
|
|
|
window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN] = Array.from(new Set(window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]));
|
2023-06-04 00:13:54 +08:00
|
|
|
|
item.classList.add("fn__none");
|
2023-06-03 17:55:45 +08:00
|
|
|
|
}
|
2023-06-03 21:45:24 +08:00
|
|
|
|
setStorageVal(Constants.LOCAL_PLUGINTOPUNPIN, window.siyuan.storage[Constants.LOCAL_PLUGINTOPUNPIN]);
|
|
|
|
|
|
}
|
|
|
|
|
|
}];
|
|
|
|
|
|
if (hasSetting) {
|
|
|
|
|
|
submenu.push({
|
2023-06-03 17:55:45 +08:00
|
|
|
|
icon: "iconSettings",
|
|
|
|
|
|
label: window.siyuan.languages.config,
|
|
|
|
|
|
click() {
|
|
|
|
|
|
plugin.openSetting();
|
|
|
|
|
|
},
|
2023-06-04 00:13:54 +08:00
|
|
|
|
});
|
2023-06-03 21:45:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
const menuOption: IMenu = {
|
|
|
|
|
|
icon: "iconInfo",
|
|
|
|
|
|
label: item.getAttribute("aria-label"),
|
|
|
|
|
|
click() {
|
2023-06-04 00:13:54 +08:00
|
|
|
|
item.dispatchEvent(new CustomEvent("click"));
|
2023-06-03 21:45:24 +08:00
|
|
|
|
},
|
|
|
|
|
|
type: "submenu",
|
|
|
|
|
|
submenu
|
2023-06-04 00:13:54 +08:00
|
|
|
|
};
|
2023-06-03 17:55:45 +08:00
|
|
|
|
if (item.querySelector("use")) {
|
|
|
|
|
|
menuOption.icon = item.querySelector("use").getAttribute("xlink:href").replace("#", "");
|
|
|
|
|
|
} else {
|
2023-06-03 21:45:24 +08:00
|
|
|
|
const svgElement = item.querySelector("svg").cloneNode(true) as HTMLElement;
|
2023-06-04 00:13:54 +08:00
|
|
|
|
svgElement.classList.add("b3-menu__icon");
|
2023-06-03 17:55:45 +08:00
|
|
|
|
menuOption.iconHTML = svgElement.outerHTML;
|
|
|
|
|
|
}
|
|
|
|
|
|
menu.addItem(menuOption);
|
2023-06-04 00:13:54 +08:00
|
|
|
|
hasPlugin = true;
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2023-06-03 17:55:45 +08:00
|
|
|
|
|
|
|
|
|
|
if (hasPlugin) {
|
2023-06-04 00:13:54 +08:00
|
|
|
|
menu.addSeparator();
|
2023-06-03 17:55:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
menu.addItem({
|
|
|
|
|
|
icon: "iconSettings",
|
|
|
|
|
|
label: window.siyuan.languages.config,
|
|
|
|
|
|
click() {
|
|
|
|
|
|
const dialogSetting = openSetting(app);
|
|
|
|
|
|
dialogSetting.element.querySelector('.b3-tab-bar [data-name="bazaar"]').dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
let rect = target.getBoundingClientRect();
|
|
|
|
|
|
if (rect.width === 0) {
|
|
|
|
|
|
rect = document.querySelector("#barMore").getBoundingClientRect();
|
|
|
|
|
|
}
|
2023-06-04 00:13:54 +08:00
|
|
|
|
menu.open({x: rect.right, y: rect.bottom, isLeft: true});
|
|
|
|
|
|
};
|