diff --git a/app/electron/main.js b/app/electron/main.js index 6ecd667ff..0fd89b9b2 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -82,14 +82,16 @@ try { if (!fs.existsSync(confDir)) { fs.mkdirSync(confDir, {mode: 0o755, recursive: true}) } - const documents = path.join(app.getPath('home'), "Documents") + const documents = path.join(app.getPath('home'), 'Documents') if (!fs.existsSync(documents)) { fs.mkdirSync(documents, {mode: 0o755, recursive: true}) } } catch (e) { console.error(e) - require('electron').dialog.showErrorBox('创建配置目录失败 Failed to create config directory', - '思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.') + require('electron'). + dialog. + showErrorBox('创建配置目录失败 Failed to create config directory', + '思源需要在用户家目录下创建配置文件夹(~/.config/siyuan),请确保该路径具有写入权限。\n\nSiYuan needs to create a configuration folder (~/.config/siyuan) in the user\'s home directory. Please make sure that the path has write permissions.') app.exit() } @@ -125,8 +127,16 @@ const boot = () => { } catch (e) { fs.writeFileSync(windowStatePath, '{}') } - const defaultWidth = screen.getPrimaryDisplay().size.width * 4 / 5 - const defaultHeight = screen.getPrimaryDisplay().workAreaSize.height * 4 / 5 + let defaultWidth + let defaultHeight + let workArea + try { + defaultWidth = screen.getPrimaryDisplay().size.width * 4 / 5 + defaultHeight = screen.getPrimaryDisplay().workAreaSize.height * 4 / 5 + workArea = screen.getPrimaryDisplay().workArea + } catch (e) { + console.error(e) + } const windowState = Object.assign({}, { isMaximized: true, fullscreen: false, @@ -136,26 +146,27 @@ const boot = () => { height: defaultHeight, }, oldWindowState) - // 窗口大小等同于或大于 workArea 时,缩小会隐藏到左下角 - const workArea = screen.getPrimaryDisplay().workArea - if (windowState.width >= workArea.width || windowState.height >= - workArea.height) { - windowState.width = Math.min(defaultWidth, workArea.width) - windowState.height = Math.min(defaultHeight, workArea.height) - } - if (windowState.width < 256) { - windowState.width = Math.min(defaultWidth, workArea.width) - } - if (windowState.height < 256) { - windowState.height = Math.min(defaultHeight, workArea.height) - } - - let x = windowState.x, y = windowState.y - if (x > workArea.width || x < 0) { - x = 0 - } - if (y > workArea.height || y < 0) { - y = 0 + let x = windowState.x + let y = windowState.y + if (workArea) { + // 窗口大小等同于或大于 workArea 时,缩小会隐藏到左下角 + if (windowState.width >= workArea.width || windowState.height >= + workArea.height) { + windowState.width = Math.min(defaultWidth, workArea.width) + windowState.height = Math.min(defaultHeight, workArea.height) + } + if (windowState.width < 256) { + windowState.width = Math.min(defaultWidth, workArea.width) + } + if (windowState.height < 256) { + windowState.height = Math.min(defaultHeight, workArea.height) + } + if (x > workArea.width || x < 0) { + x = 0 + } + if (y > workArea.height || y < 0) { + y = 0 + } } // 创建主窗体 @@ -164,7 +175,8 @@ const boot = () => { backgroundColor: '#FFF', // 桌面端主窗体背景色设置为 `#FFF` Fix https://github.com/siyuan-note/siyuan/issues/4544 width: windowState.width, height: windowState.height, - x: x, y: y, + x, + y, fullscreenable: true, fullscreen: windowState.fullscreen, webPreferences: { @@ -180,7 +192,8 @@ const boot = () => { }) require('@electron/remote/main').enable(mainWindow.webContents) - mainWindow.webContents.userAgent = 'SiYuan/' + appVer + ' https://b3log.org/siyuan Electron' + mainWindow.webContents.userAgent = 'SiYuan/' + appVer + + ' https://b3log.org/siyuan Electron' mainWindow.webContents.on('did-finish-load', () => { if ('win32' === process.platform || 'linux' === process.platform) { siyuanOpenURL = process.argv.find((arg) => arg.startsWith('siyuan://')) @@ -383,19 +396,19 @@ const boot = () => { label: 'Official Website', click: () => { shell.openExternal('https://b3log.org/siyuan/') - } + }, }, { label: 'Open Source', click: () => { shell.openExternal('https://github.com/siyuan-note/siyuan') - } + }, }, { label: '中文反馈', click: () => { shell.openExternal('https://ld246.com/article/1649901726096') - } + }, }, { label: 'Quit', @@ -444,7 +457,8 @@ const initKernel = (initData) => { : 'SiYuan-Kernel' const kernelPath = path.join(appDir, 'kernel', kernelName) if (!fs.existsSync(kernelPath)) { - showErrorWindow('⚠️ 内核文件丢失 Kernel is missing', `
net stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=6806 numberofports=1\nnet start winnatnet stop winnat\nnetsh interface ipv4 add excludedportrange protocol=tcp startport=6806 numberofports=1\nnet start winnat