You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
currentWindow.maximize() doesn't truly maximize the window #19934
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
Electron Version: Electron 6.0.4
Operating System: Windows 10 (1903)
Expected Behavior
The maximize() function maximizes the window as it would any other window.
Actual Behavior
The maximize() function "maximizes" the window, but doesn't give it the maximized property. The window is still resizable via the edges of the app.
To Reproduce
Have an app with a custom title bar emit the maximize() function on a custom placed maximize button. The properties of the window should be frame: false and transparent: false.
Yes, this is a very very old bug, that no one bothered to fix. #12854
Yeah, I found that bug report as well. It doesn't exactly describe it the same way since it even happens on transparent: false (and frame: false), but I'm guessing the result is the same, or rather lack thereof.
What I'm wondering is how other apps fixed this particular issue. Discord for example utilises a custom title bar and maximises just fine.
Well they don't use transparent: false and frame: false at the same time to avoid the bug like everybody else.
Are you certain that's the cause? Because we added in transparent: false after the bug was found to test it further, without result. In both true and false cases, the resizing glitch still occurs.
@ZaDarkSide I also have this issue with transparent: false now, after upgrading from v4.x to 6.x.
I can resize the window in maximized state
And the remote.getCurrentWindow().maximize() function always returns false now, which caused the shown below maximizeWindow() function in my app to stop working properly as well (the unmaximize() in particular):
Info
Electron Version: 6.0.5
6.0.5
Operating System:
Win10 (1903) x64
Last Known Working Electron version:
4.x (not sure about 5.x)
To Reproduce
constremote=require('electron').remoteconstwindow=remote.getCurrentWindow()// unmaximize() inside this function sopped working properly after v4.x => v6.x updatemaximizeWindow(){console.log(this.window.isMaximized())// Always false if(this.window.isMaximized()){this.window.unmaximize()}else{this.window.maximize()}}
main
mainWindow=newBrowserWindow({width: 1280,height: 720,minHeight: 300,minWidth: 500,frame: false,webPreferences: {nodeIntegration: true,webSecurity: process.env.NODE_ENV!=='development',// to make image loading from local drive possible}})
@AlexSHoffman Your problem is indeed directly related to ours. Whenever a window gets maximised on certain systems (all Windows 10), it does stretch it out accordingly, but doesn't give itself the correct state. Because of that, isMaximized() always returns false.
@Z3RoMan yeah, but the weird thing is, for me it worked properly in v4.1.5, the isMaximized() function has been returning true in the maximized state, with the same config:
frame: false,transparent: false
Reacted by Roberto Silva Zuñiga and Alexander Rakhmaev
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including getNormalBounds(), maximize(), unmaximize() and isMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.
Code:
if(win.webContents.browserWindowOptions.transparent){// rewrite getNormalBounds, maximize, unmaximize and isMaximized API for the transparent windowletresizable=win.isResizable()letnormalBounds=win.getNormalBounds ? win.getNormalBounds() : win.getBounds()win.getNormalBounds=function(){if(!this.isMaximized()){if(BrowserWindow.prototype.getNormalBounds){normalBounds=BrowserWindow.prototype.getNormalBounds.call(this)}else{normalBounds=BrowserWindow.prototype.getBounds.call(this)}}returnnormalBounds}.bind(win)win.maximize=function(){normalBounds=this.getNormalBounds()// store the bounds of normal windowresizable=this.isResizable()// store resizable valueBrowserWindow.prototype.maximize.call(this)if(!BrowserWindow.prototype.isMaximized.call(this)){// while isMaximized() was returning false, it will not emit 'maximize' eventthis.emit('maximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(false)// disable resize when the window is maximized}.bind(win)win.unmaximize=function(){constfromMaximized=BrowserWindow.prototype.isMaximized.call(this)BrowserWindow.prototype.unmaximize.call(this)if(!fromMaximized){// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' eventthis.emit('unmaximize',{sender: this,preventDefault: ()=>{}})}this.setResizable(resizable)// restore resizable}.bind(win)win.isMaximized=function(){constnativeIsMaximized=BrowserWindow.prototype.isMaximized.call(this)if(!nativeIsMaximized){// determine whether the window is full of the screen work areaconstbounds=this.getBounds()constworkArea=electron.screen.getDisplayMatching(bounds).workAreaif(bounds.x<=workArea.x&&bounds.y<=workArea.y&&bounds.width>=workArea.width&&bounds.height>=workArea.height){returntrue}}returnnativeIsMaximized}.bind(win)}
Guys,I found this, after you "setResizable(false)" or "new BrowserWindow({resizable: false})",then "isMaximized()" will always return "false",even if you execute "setResizable(true)".
So if you want "isMaximized()" to return the result correctly, make sure "resizable" is true always.
Reacted by Vedat Furkan Erkul, kkgg123 and Salif Dianda
Guys,I found this, after you "setResizable(false)" or "new BrowserWindow({resizable: false})",then "isMaximized()" will always return "false",even if you execute "setResizable(true)".
So if you want "isMaximized()" to return the result correctly, make sure "resizable" is true always.
Seems that the window.maximize() function still doesn't work on Linux. We experience issues with automation testing, because the window still has 800x600 default size after maximize(). On Windows it's fine, and on Mac too, but we are using latest Ubuntu, and ubuntu 18.04 for testing too. For the moment we solved the issue by creating a window of minimal valid size for acceptance testing.
Activity
ZaDarkSide commentedon Aug 28, 2019
Yes, this is a very very old bug, that no one bothered to fix.
#12854
Z3RoMan commentedon Aug 28, 2019
Yeah, I found that bug report as well. It doesn't exactly describe it the same way since it even happens on
transparent: false(andframe: false), but I'm guessing the result is the same, or rather lack thereof.What I'm wondering is how other apps fixed this particular issue. Discord for example utilises a custom title bar and maximises just fine.
ZaDarkSide commentedon Aug 28, 2019
Well they don't use
transparent: trueandframe: falseat the same time to avoid the bug like everybody else.Z3RoMan commentedon Aug 28, 2019
Are you certain that's the cause? Because we added in
transparent: falseafter the bug was found to test it further, without result. In bothtrueandfalsecases, the resizing glitch still occurs.ZaDarkSide commentedon Aug 28, 2019
For me it only manifests on using
transparent: trueandframe: falseat the same time.EDIT: actually just setting
transparent: truenow triggers the bug, so it doesn't depends onframe: true/falseanymore.alexhx5 commentedon Aug 28, 2019
@ZaDarkSide I also have this issue with
transparent: falsenow, after upgrading from v4.x to 6.x.I can resize the window in maximized state
And the
remote.getCurrentWindow().maximize()function always returnsfalsenow, which caused the shown belowmaximizeWindow()function in my app to stop working properly as well (theunmaximize()in particular):Info
To Reproduce
main
Z3RoMan commentedon Aug 28, 2019
@AlexSHoffman Your problem is indeed directly related to ours. Whenever a window gets maximised on certain systems (all Windows 10), it does stretch it out accordingly, but doesn't give itself the correct state. Because of that,
isMaximized()always returns false.alexhx5 commentedon Aug 28, 2019
@Z3RoMan yeah, but the weird thing is, for me it worked properly in v4.1.5, the
isMaximized()function has been returningtruein the maximized state, with the same config:ZaDarkSide commentedon Aug 28, 2019
The bug appears when you use
transparent: truealexhx5 commentedon Aug 28, 2019
@ZaDarkSide ...and also when I use:
ZaDarkSide commentedon Aug 28, 2019
Yes, well clearly something changed between 4.x and 6.x
x-tiantian commentedon Sep 18, 2019
You must include the above configuration, win.isMaximized() and win.unmaximize() to work properly.
electron:6.0.2
system:win10
18 remaining items
Liupeng8 commentedon Dec 11, 2019
The issue still exists in Electron 7.1.4 on Windows 7
chenjietao commentedon Mar 21, 2020
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including
getNormalBounds(),maximize(),unmaximize()andisMaximzed(). And I've added some features to make frameless windows work better. Such as disable the menu when right clicking the drag region.Code:
x-tiantian commentedon Mar 27, 2020
Guys,I found this, after you "setResizable(false)" or "new BrowserWindow({resizable: false})",then "isMaximized()" will always return "false",even if you execute "setResizable(true)".
So if you want "isMaximized()" to return the result correctly, make sure "resizable" is true always.
kkgg123 commentedon Jun 17, 2020
I found that too!!!!!!!! version7.1.8
zcbenz commentedon Dec 10, 2020
Fixed with #26586.
morteza-jamali commentedon Dec 11, 2020
If you want to first use setResizable(false) and next time change it to setResizable(true) , you can use following code as replacement :
First time:
Next time:
above code worked very good for me .
olga-climova-2 commentedon Jun 9, 2022
Seems that the
window.maximize()function still doesn't work on Linux. We experience issues with automation testing, because the window still has 800x600 default size aftermaximize(). On Windows it's fine, and on Mac too, but we are using latest Ubuntu, and ubuntu 18.04 for testing too. For the moment we solved the issue by creating a window of minimal valid size for acceptance testing.mangeshsirkare commentedon Jun 27, 2022
Add below line in index.js
It will maximized your window after splashScreen. You guys must try this
setTimeout(function(){
mainWindow.maximize();
},8000);
You can adjust delay in setTimeout function.
mahmutatmaca commentedon Feb 8, 2023
const { remote } = require("electron");
const win = remote.getCurrentWindow();
let isFullScreen = false
document.querySelector(".minimize").addEventListener("click", () => {
win.hide();
});
document.querySelector(".maximize").addEventListener("click", () => {
isFullScreen ? win.unmaximize() : win.maximize();
isFullScreen=!isFullScreen
})
document.querySelector(".close").addEventListener("click", () => {
win.hide();
win.setSkipTaskbar(true);
return false;
})
abbatyya commentedon May 11, 2023
// HANDLE WINDOW MAXIMIZE OR RESTORE
abbatyya commentedon May 11, 2023
// HANDLE WINDOW MAXIMIZE OR RESTORE
OmBayus commentedon Jan 3, 2024
use setFullScreen(true) instead of maximize()