Skip to content

Commit

Permalink
完善窗口最大化与还原的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
JChehe committed Jun 29, 2017
1 parent ff7e9dc commit 5375ef9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/ipcMainSets.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,20 @@ module.exports = function (mainWindow, backgroundWindow) {
mainWindow.close()
})

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

0 comments on commit 5375ef9

Please sign in to comment.