🎨 Improve the position and size of the main window after desktop initialization Fix https://github.com/siyuan-note/siyuan/issues/8326

This commit is contained in:
Daniel 2023-05-22 20:27:26 +08:00
parent 46f68f9f65
commit 3f5614c0c0
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -134,8 +134,8 @@ const showErrorWindow = (title, content) => {
errorHTMLPath = path.join(appDir, "electron", "error.html"); errorHTMLPath = path.join(appDir, "electron", "error.html");
} }
const errWindow = new BrowserWindow({ const errWindow = new BrowserWindow({
width: screen.getPrimaryDisplay().size.width / 2, width: Math.floor(screen.getPrimaryDisplay().size.width / 2),
height: screen.getPrimaryDisplay().workAreaSize.height / 2, height: Math.floor(screen.getPrimaryDisplay().workAreaSize.height / 2),
frame: false, frame: false,
icon: path.join(appDir, "stage", "icon-large.png"), icon: path.join(appDir, "stage", "icon-large.png"),
webPreferences: { webPreferences: {
@ -179,25 +179,30 @@ const writeLog = (out) => {
}; };
const boot = () => { const boot = () => {
let windowStateInitialized = true;
// 恢复主窗体状态 // 恢复主窗体状态
let oldWindowState = {}; let oldWindowState = {};
try { try {
oldWindowState = JSON.parse(fs.readFileSync(windowStatePath, "utf8")); oldWindowState = JSON.parse(fs.readFileSync(windowStatePath, "utf8"));
if (!oldWindowState.x) {
windowStateInitialized = false;
}
} catch (e) { } catch (e) {
fs.writeFileSync(windowStatePath, "{}"); fs.writeFileSync(windowStatePath, "{}");
windowStateInitialized = false;
} }
let defaultWidth; let defaultWidth;
let defaultHeight; let defaultHeight;
let workArea; let workArea;
try { try {
defaultWidth = screen.getPrimaryDisplay().size.width; defaultWidth = Math.floor(screen.getPrimaryDisplay().size.width * 0.8);
defaultHeight = screen.getPrimaryDisplay().workAreaSize.height; defaultHeight = Math.floor(screen.getPrimaryDisplay().workAreaSize.height * 0.8);
workArea = screen.getPrimaryDisplay().workArea; workArea = screen.getPrimaryDisplay().workArea;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
const windowState = Object.assign({}, { const windowState = Object.assign({}, {
isMaximized: true, isMaximized: false,
fullscreen: false, fullscreen: false,
isDevToolsOpened: false, isDevToolsOpened: false,
x: 0, x: 0,
@ -244,8 +249,6 @@ const boot = () => {
height: windowState.height, height: windowState.height,
minWidth: 493, minWidth: 493,
minHeight: 376, minHeight: 376,
x,
y,
fullscreenable: true, fullscreenable: true,
fullscreen: windowState.fullscreen, fullscreen: windowState.fullscreen,
trafficLightPosition: {x: 8, y: 8}, trafficLightPosition: {x: 8, y: 8},
@ -260,6 +263,7 @@ const boot = () => {
titleBarStyle: "hidden", titleBarStyle: "hidden",
icon: path.join(appDir, "stage", "icon-large.png"), icon: path.join(appDir, "stage", "icon-large.png"),
}); });
windowStateInitialized? currentWindow.setPosition(x, y): currentWindow.center();
require("@electron/remote/main").enable(currentWindow.webContents); require("@electron/remote/main").enable(currentWindow.webContents);
currentWindow.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron"; currentWindow.webContents.userAgent = "SiYuan/" + appVer + " https://b3log.org/siyuan Electron";
@ -396,8 +400,8 @@ const showWindow = (wnd) => {
const initKernel = (workspace, port, lang) => { const initKernel = (workspace, port, lang) => {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
bootWindow = new BrowserWindow({ bootWindow = new BrowserWindow({
width: screen.getPrimaryDisplay().size.width / 2, width: Math.floor(screen.getPrimaryDisplay().size.width / 2),
height: screen.getPrimaryDisplay().workAreaSize.height / 2, height: Math.floor(screen.getPrimaryDisplay().workAreaSize.height / 2),
frame: false, frame: false,
icon: path.join(appDir, "stage", "icon-large.png"), icon: path.join(appDir, "stage", "icon-large.png"),
transparent: "linux" !== process.platform, transparent: "linux" !== process.platform,
@ -799,8 +803,8 @@ app.whenReady().then(() => {
if (firstOpen) { if (firstOpen) {
const firstOpenWindow = new BrowserWindow({ const firstOpenWindow = new BrowserWindow({
width: screen.getPrimaryDisplay().size.width * 0.6, width: Math.floor(screen.getPrimaryDisplay().size.width * 0.6),
height: screen.getPrimaryDisplay().workAreaSize.height * 0.8, height: Math.floor(screen.getPrimaryDisplay().workAreaSize.height * 0.8),
frame: false, frame: false,
icon: path.join(appDir, "stage", "icon-large.png"), icon: path.join(appDir, "stage", "icon-large.png"),
transparent: "linux" !== process.platform, transparent: "linux" !== process.platform,