Skip to content

.isMaximized() always returns false even when window is maximized. #9092

Closed

Description

@FullstackDevsYT
  • Electron version: v1.6.2
  • Operating system: win 10

Expected behavior

.isMaximized(); should return true

Actual behavior

.isMaximized(); returns false;

How to reproduce

const $ = require('jquery');
const {remote} = require('electron');
var win = remote.getCurrentWindow();

$('body').dblclick(function(){
  console.log('double clicked!');
});

$('#minimize').click(function(){
  win.minimize();
});

$('#close').click(function(){
  win.close();
});

$('#maximize').click(function() {
  if(win.isMaximized()){
      win.unmaximize();
      console.log('unmaximized');
  }else{
      win.maximize();
      console.log('maximized');
  }
  console.log(win.isMaximized());
});

Activity

  1. FullstackDevsYT commented on Apr 7, 2017

    @FullstackDevsYT
    Author

    it seems to be working now

  2. yjlintw commented on May 5, 2017

    @yjlintw

    I still have the same problem on Win10.
    electron version: v1.6.8
    I'm using frameless window. Is that the issue?

  3. stanleyxu2005 commented on Jul 12, 2017

    @stanleyxu2005

    I believe transparent=true is the root cause. Once the window is maximized, it will never unmaiximzed. I set my HTML window to be draggable, so that I can show the Window's context menu, which is usually available by right clicking the original Window titlebar. Now I can see that the menu item "Maximize" (in the Window's context menu) is by default bold. It is expected to be disabled.

    (I'm using 1.7.4 beta)

  4. kerwin612 commented on Sep 3, 2017

    @kerwin612

    @stanleyxu2005 +1,frameless window set transparent=true -> .isMaximized(); always returns false;
    electron: v1.7.5

  5. ErickRodrCodes commented on Nov 21, 2017

    @ErickRodrCodes

    @stanleyxu2005 +1: if frameless window is set to transparent:true, win.isMaximized() will return always false. Electron 1.7.0

  6. AndreColli commented on Nov 29, 2017

    @AndreColli

    @stanleyxu2005 +1
    Same issue here.
    w10 | electron v1.7.9

  7. itsezc commented on Dec 20, 2017

    @itsezc

    @stanleyxu2005 @FullstackDevsYT Same issue

    Windows 10 | Electron 1.7.x and 1.8.x


    Work around:

    var TMP = { maximized: true }
    
    const remote = require('electron').remote,
          window = remote.getCurrentWindow()
    
    if(TMP.maximized == true) {
        TMP.maximized = false
        window.unmaximize()
      } else {
        TMP.maximized = true
        window.maximize()
      }
    

    Basic... but that's all I needed.
    P.S. this expects your application to be maximized, if its not maximized by default be sure to have this instead:

    var TMP = { maximized: false }

  8. DannyFeliz commented on Mar 27, 2018

    @DannyFeliz

    I ended with a similar solution as @MeinLieblingsmensch I hope someone fix this.

  9. stanleyxu2005 commented on Mar 27, 2018

    @stanleyxu2005

    @FullstackDevsYT please reopen this ticket, as it is actually not working.

  10. Trackhe commented on May 13, 2018

    @Trackhe

    I have the same issue too. it sucks. and your Workaround is not complete. What is when you max the windows and you resize it from the border?! than you have a non maxi window with TMP = true. but that is wrong! We need a fixed function please.

    @MeinLieblingsmensch Yes, I've already thought of that. nevertheless only a transitional solution.

  11. itsezc commented on May 13, 2018

    @itsezc

    I agree with @Trackhe there needs to be a fix to this

    However, you can determine the maximum resolution size of the application and let that determine if your window needs to be maximized or minimized/unmaximized.

  12. abalad commented on May 30, 2018

    @abalad

    In the previous version I used the following code:

      ipcMain.on('APPLICATION-MAXIMIZE', () => {
        mainWindow.isMaximized() ? mainWindow.unmaximize() : mainWindow.maximize()
      });

    But in the current version it does not work anymore :(
    The code mainWindow.isMaximized() always returns FALSE

  13. ititchuan commented on Apr 16, 2019

    @ititchuan

    electorn:4.0.0+win10,new BrowserWindow({ width: 800, height: 600,frame: false,titleBarStyle: 'hidden',titleBarStyle: 'customButtonsOnHover',
    transparent:true,hasShadow:false}).Still having problems.

  14. Kyza commented on Apr 24, 2019

    @Kyza

    It has been over 2 years and this issue has still not been fixed. Hopefully, we will get one by 5.0.

  15. 2 remaining items

  16. Feuerhamster commented on Sep 13, 2019

    @Feuerhamster

    Same issue here:
    new BrowserWindow({width:1240, height: 820,icon: 'favicon.ico', frame: false, webPreferences: {nodeIntegration: true, webviewTag: true}});

    But additionally the functions win.unmaximize() is not working.
    So i can maximize the window but can not unmaximize it.
    I do not have this problem in the electron version 4.1.3.
    But on every following version i have this issue.

  17. JustGogoing commented on Sep 21, 2019

    @JustGogoing

    version 6.0.0
    Still issue in my app

  18. JohnGagliardi commented on Sep 25, 2019

    @JohnGagliardi

    Broken for me as well. The IsMaximixed() issue is causing unmaximize to not run from what I can tell;

    I have a static window size so I have the following work around:

    NOTE: I am working in React which is where the state comes from

       if (this.state.WindowMaximized)
       {
         remote.getCurrentWindow().setBounds(this.state.SmallBounds);
    
         this.setState({
           WindowMaximized: false
         });
       }
       else
       {
         var bounds: DOMRect = remote.getCurrentWindow().getBounds();
    
         remote.getCurrentWindow().maximize();
    
         this.setState({
           WindowMaximized: true,
           SmallBounds: bounds
         });
       }
    
  19. Kyza commented on Sep 30, 2019

    @Kyza

    One of the problems with this not being fixed might be because of this issue being closed. The issue is definitely not resolved. I'd say that this issue should be reopened.

  20. zouye commented on Oct 15, 2019

    @zouye

    Electron: 6.0.10
    这个是是我的版本,依旧没有解决。但是在4.x版本中是好的。官方什么时候修复

    Electron: 6.0.10 This is my version and it still doesn't work. But it is good in the 4.x version. When does the official fix it?

  21. Darkzarich commented on Aug 13, 2020

    @Darkzarich

    The problem still persists

  22. Nerlin commented on Aug 17, 2020

    @Nerlin

    Found the same problem with Electron 9.2.0 -- after you specify the transparent flag to true, isMaximized method starts to return false for every call.

  23. Darkzarich commented on Aug 17, 2020

    @Darkzarich

    This is what I ended up with for my case, I only needed to know if it's minimized right now or not:

      mainWindow.minimizedState = false;
    
      mainWindow.on('minimize',event => {
        event.preventDefault();
        mainWindow.minimizedState = true;
        mainWindow.minimize();
      });
    
      mainWindow.on('restore',event => {
        event.preventDefault();
        mainWindow.minimizedState = false;
        mainWindow.restore();
      });

    I defined my own property which I placed in mainWindow object (BrowserWindow class object), it gets changed on needed events which works pretty good

    and I access it like that in my app:

    remote.BrowserWindow.getAllWindows()[0].minimizedState
  24. DannyFeliz commented on Aug 17, 2020

    @DannyFeliz
  25. zhangxuelian commented on Oct 22, 2020

    @zhangxuelian

    version 10.1.1
    Still issue in my app

  26. snowInCloudy commented on Mar 30, 2022

    @snowInCloudy

    version 10.1.3
    The problem still persists

  27. codebytere commented on Mar 30, 2022

    @codebytere
    Member

    Yes, correct. version 10 is not supported any longer and does not have this fix.

  28. OldManMeta commented on Apr 23, 2023

    @OldManMeta

    This is still and issue.

  29. DannyFeliz commented on Apr 24, 2023

    @DannyFeliz

    It has been over 2 years and this issue has still not been fixed. Hopefully, we will get one by 5.0.

    Your comment just turned 4 years old and this is still a problem 😄

  30. OldManMeta commented on Apr 24, 2023

    @OldManMeta

    I'm still having issues getting a reliable value back in terms of maximised state, but I found that creating a stored local state can get around this, instead of relying on the function returning something correct.

    From there, I just call the window.setSize and window.setPosition functions to actually restore a window - spent way too long messing around with something that should be so simple and built in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions