-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
currentWindow.maximize() doesn't truly maximize the window #19934
Comments
Yes, this is a very very old bug, that no one bothered to fix. |
Yeah, I found that bug report as well. It doesn't exactly describe it the same way since it even happens on 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 |
Are you certain that's the cause? Because we added in |
For me it only manifests on using EDIT: actually just setting |
@ZaDarkSide I also have this issue with
Info
To Reproduceconst remote = require('electron').remote
const window = remote.getCurrentWindow()
// unmaximize() inside this function sopped working properly after v4.x => v6.x update
maximizeWindow () {
console.log(this.window.isMaximized()) // Always false
if (this.window.isMaximized()) {
this.window.unmaximize()
} else {
this.window.maximize()
}
} main mainWindow = new BrowserWindow({
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, |
@Z3RoMan yeah, but the weird thing is, for me it worked properly in v4.1.5, the frame: false,
transparent: false |
The bug appears when you use |
@ZaDarkSide ...and also when I use: frame: false,
transparent: false |
Yes, well clearly something changed between 4.x and 6.x |
You must include the above configuration, win.isMaximized() and win.unmaximize() to work properly. electron:6.0.2 |
@wangjikill your suggestion does not fix the problem:
electron: v6.0.7 |
@AlexSHoffman |
@EGo14T no, I couldn't find a solution. But maybe it will get fixed in Electron v7.x |
hmm...all right,thinks :) |
It seems Electron 5.0.x are the latest versions in which this bug is not present. Update: just tried upgrading my Electron app to Electron 8.2.1 and cannot reproduce the bug |
@AlexSHoffman You can use Electron 5.0.12(<6.0.0),and set you body CSS like this |
@EGo14T It's just the use of Electron <6.0.0 that matters, the CSS is irrelevant |
@EGo14T staying on version <6.0 is not really a solution. It has to get fixed |
Guys, today, I try window maximization and cancel maximization again, I found this. This is my initial window configuration
When I switch to the second page, and the new page use the new size, it can also maximize and cancel the maximization. I wrote it like this. win.setResizable(true);//The position of this line of code is above the change size code. Switching window maximization and cancel maximization work. If you put it below, it will not work properly.
The code to switch is like this
electron:6.0.2 Sorry, my English is not very good. |
Have the same problem, it looks like this problem should exist for a long time, isn't the author planning to fix it? |
I have the same issue on Mac OS Catalina with Electron 7.1.2. |
The issue is fixed for me in |
The issue still exists in Electron 7.1.3 on Windows 10! |
@TheKiLLerDz I just updated from Man this is such an inconsistent bug. |
The issue still exists in Electron 7.1.3 on Windows 7 |
the bug is only when u use "transparent: true", when you don't use it it works perfect |
@TheKiLLerDz nope, I had this issue with |
@AlexSHoffman the css added to body seems not to work for my case , only making "transparent: false" that makes Maximize really do it's job |
The issue still exists in Electron 7.1.4 on Windows 7 |
I wrote a plug-in to fix this problem. See electron-frameless-window-plugin. In fact, I rewrote several methods of BrowserWindow instance, including Code: if (win.webContents.browserWindowOptions.transparent) {
// rewrite getNormalBounds, maximize, unmaximize and isMaximized API for the transparent window
let resizable = win.isResizable()
let normalBounds = 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)
}
}
return normalBounds
}.bind(win)
win.maximize = function () {
normalBounds = this.getNormalBounds() // store the bounds of normal window
resizable = this.isResizable() // store resizable value
BrowserWindow.prototype.maximize.call(this)
if (!BrowserWindow.prototype.isMaximized.call(this)) {
// while isMaximized() was returning false, it will not emit 'maximize' event
this.emit('maximize', { sender: this, preventDefault: () => {} })
}
this.setResizable(false) // disable resize when the window is maximized
}.bind(win)
win.unmaximize = function () {
const fromMaximized = BrowserWindow.prototype.isMaximized.call(this)
BrowserWindow.prototype.unmaximize.call(this)
if (!fromMaximized) {
// isMaximized() returned false before unmaximize was called, it will not emit 'unmaximize' event
this.emit('unmaximize', { sender: this, preventDefault: () => {} })
}
this.setResizable(resizable) // restore resizable
}.bind(win)
win.isMaximized = function () {
const nativeIsMaximized = BrowserWindow.prototype.isMaximized.call(this)
if (!nativeIsMaximized) {
// determine whether the window is full of the screen work area
const bounds = this.getBounds()
const workArea = electron.screen.getDisplayMatching(bounds).workArea
if (bounds.x <= workArea.x && bounds.y <= workArea.y && bounds.width >= workArea.width && bounds.height >= workArea.height) {
return true
}
}
return nativeIsMaximized
}.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. |
I found that too!!!!!!!! version7.1.8 |
Fixed with #26586. |
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: mainWindow = new BrowserWindow({
resizable: true,
frame: false,
width: 400,
height: 400,
minHeight: 400,
minWidth: 400,
maxHeight: 400,
maxWidth: 400,
.
.
.
}); Next time: const { width, height } = screen.getPrimaryDisplay().workAreaSize;
mainWindow.setMaximumSize(width, height);
mainWindow.setSize(1024, 728);
mainWindow.center(); above code worked very good for me . |
Seems that the |
Add below line in index.js setTimeout(function(){ You can adjust delay in setTimeout function. |
const { remote } = require("electron"); |
// HANDLE WINDOW MAXIMIZE OR RESTORE
|
1 similar comment
// HANDLE WINDOW MAXIMIZE OR RESTORE
|
use setFullScreen(true) instead of maximize()
|
Preflight Checklist
Issue Details
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
andtransparent: false
.Additional Information
The general concept of the custom titlebar with buttons is taken from a repository found here:
https://github.com/maxchaor/electron-title-bar-tutorial
The repository in question uses Electron 2.0.0 to run it.
This issue isn't present on every device. It's been tested on three of my own systems and it works fine on there.
The text was updated successfully, but these errors were encountered: