Skip to content

Commit 5375ef9

Browse files
committed
完善窗口最大化与还原的逻辑
1 parent ff7e9dc commit 5375ef9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

app/ipcMainSets.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,20 @@ module.exports = function (mainWindow, backgroundWindow) {
223223
mainWindow.close()
224224
})
225225

226-
// 默认窗口大小,当不指定 x,y 时,则为居中。
226+
// 与 new BrowserWindow 初始化时不同(忽略x、y时会自动居中),而 setBounds 则不可省略 x、y
227+
// electron.screen 需要在 app.ready 后获取
227228
let windowBounds = {
228229
width: 1280,
229230
height: 850
230231
}
231232
ipcMain.on('sync-maximize', (event, arg) => {
232233
if (mainWindow.isMaximized()) {
234+
// 默认全屏时,需要计算居中时的 x、y
235+
if (typeof windowBounds.x === 'undefined') {
236+
const workAreaSize = electron.screen.getPrimaryDisplay().workAreaSize
237+
windowBounds.x = (workAreaSize.width - 1280) / 2
238+
windowBounds.y = (workAreaSize.height - 850) / 2
239+
}
233240
mainWindow.setBounds(windowBounds, true)
234241
} else {
235242
windowBounds = mainWindow.getBounds()

0 commit comments

Comments
 (0)