Skip to content
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

isMaximized does not reflect OS window state on windows #27838

Closed
suedama1756 opened this issue Feb 21, 2021 · 0 comments · Fixed by #28207
Closed

isMaximized does not reflect OS window state on windows #27838

suedama1756 opened this issue Feb 21, 2021 · 0 comments · Fixed by #28207

Comments

@suedama1756
Copy link

suedama1756 commented Feb 21, 2021

Changes to isMaximized implementation recently have made reporting of isMaximized worse as they do not use standard operating system calls to determine the window state. Maximizing a window using the windows system menu, or using WIN + Up Arrow will always return isMaximized() false.

Preflight Checklist

  • [x ] I have read the Contributing Guidelines for this project.
  • [ x] I agree to follow the Code of Conduct that this project adheres to.
  • [ x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    Seen in 10.3.2 and 11.2.3
  • Operating System:
    Windows 10
  • Last Known Working Electron version:
    Not 100% sure as different versions have various issues with isMaximized.

Expected Behavior

Execute

   const { app, BrowserWindow } = require('electron');
  app.on('ready', function() {
     const window = new BrowserWindow({
         frame: false,
         thickFrame: false,
         width: 200,
         height: 200  
     });
     window.show();
     setInterval(() => {
        if (!window.isDestroyed()) {
            console.log(window.isMaximized())
        }
     }, 5000);
  });

Should return true when the window has been maximized by the operating system

Actual Behavior

Returns false

To Reproduce

  1. Enter the code above into a file named main.js and execute with
electron main.js
  1. maximize the window using "alt+space" menu and select maximize, or use "WIN+Up Arrow" shortcut

Additional Information

Replacing the implementations on BrowserWindow with calls to native operating system APIs via a NAPI extension fixes this issue for me. I'd love to understand why electron does not use these standard calls as the code is simpler and should be more reliable (perhaps there were legacy issues, if so do they still apply?)

   isMaximized() { 
       return Native.getWindowPlacement(this.getNativeWindowHandle()).showCmd === 3;
   },
   maximize() {
       Native.showWindow(window.getNativeWindowHandle(), 3);
   }

The NAPI extension is simply a wrapper on the following two windows APIs https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowplacement and https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow

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

Successfully merging a pull request may close this issue.

2 participants