Vanessa 2023-01-26 18:55:17 +08:00
parent bf99eb6833
commit 12a4b35506
5 changed files with 299 additions and 20 deletions

57
app/src/window/init.ts Normal file
View file

@ -0,0 +1,57 @@
import {Constants} from "../constants";
import {webFrame} from "electron";
import {globalShortcut} from "../util/globalShortcut";
import {fetchPost} from "../util/fetch";
import {JSONToCenter, resizeTabs} from "../layout/util";
import {initStatus} from "../layout/status";
import {appearance} from "../config/appearance";
import {initAssets, setInlineStyle} from "../util/assets";
import {renderSnippet} from "../config/util/snippets";
import {getSearch} from "../util/functions";
import {Layout} from "../layout";
import {initWindow} from "../util/onGetConfig";
export const init = () => {
webFrame.setZoomFactor(window.siyuan.storage[Constants.LOCAL_ZOOM]);
globalShortcut();
fetchPost("/api/system/getEmojiConf", {}, response => {
window.siyuan.emojis = response.data as IEmoji[];
const id = getSearch("id");
JSONToCenter({
"direction": "lr",
"resize": "lr",
"size": "auto",
"type": "center",
"instance": "Layout",
"children": [{
"instance": "Wnd",
"children": [{
"instance": "Tab",
active: true,
docIcon: "1f389",
title: "请从这里开始",
"children": [{
rootId: id,
blockId: id,
instance: "Editor",
mode: "wysiwyg"
}]
}]
}]
});
window.siyuan.layout.centerLayout = window.siyuan.layout.layout;
});
initStatus(true);
initWindow();
appearance.onSetappearance(window.siyuan.config.appearance);
initAssets();
renderSnippet();
setInlineStyle();
let resizeTimeout = 0;
window.addEventListener("resize", () => {
window.clearTimeout(resizeTimeout);
resizeTimeout = window.setTimeout(() => {
resizeTabs();
}, 200);
});
}

View file

@ -0,0 +1,48 @@
import {isWindow} from "../util/functions";
import {Wnd} from "../layout/Wnd";
import {Layout} from "../layout";
import {getCurrentWindow} from "@electron/remote";
const getAllWnds = (layout: Layout, wnds: Wnd[]) => {
for (let i = 0; i < layout.children.length; i++) {
const item = layout.children[i];
if (item instanceof Wnd) {
wnds.push(item);
} else if (item instanceof Layout) {
getAllWnds(item, wnds);
}
}
}
export const setTabPosition = () => {
if (!isWindow()) {
return;
}
const wndsTemp: Wnd[] = []
getAllWnds(window.siyuan.layout.layout, wndsTemp);
wndsTemp.forEach(item => {
const headerElement = item.headersElement.parentElement;
const rect = headerElement.getBoundingClientRect()
const dragElement = headerElement.querySelector('.item--readonly .fn__flex-1') as HTMLElement
if (rect.top === 0) {
dragElement.style.height = dragElement.parentElement.clientHeight + "px"
// @ts-ignore
dragElement.style.WebkitAppRegion = "drag";
} else {
// @ts-ignore
dragElement.style.WebkitAppRegion = "";
}
if ("darwin" === window.siyuan.config.system.os) {
if (rect.top <= 0 && rect.left <= 0 && !getCurrentWindow().isFullScreen()) {
item.headersElement.style.paddingLeft = "69px";
} else {
item.headersElement.style.paddingLeft = "";
}
} else {
if (rect.top <= 0 && rect.right >= window.innerWidth) {
(headerElement.lastElementChild as HTMLElement).style.paddingRight = (42 * 3) + "px";
} else {
(headerElement.lastElementChild as HTMLElement).style.paddingRight = "";
}
}
})
}