File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff 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 ( )
You can’t perform that action at this time.
0 commit comments