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

[Bug]: Window resizes incrementally on win.show #41675

Closed
3 tasks done
doods-irl opened this issue Mar 23, 2024 · 2 comments
Closed
3 tasks done

[Bug]: Window resizes incrementally on win.show #41675

doods-irl opened this issue Mar 23, 2024 · 2 comments
Labels
blocked/need-repro Needs a test case to reproduce the bug bug 🪲

Comments

@doods-irl
Copy link

Preflight Checklist

Electron Version

29.1.2

What operating system are you using?

Windows

Operating System Version

Windows 11 22H2 22621.3296

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Window should stick to the bounds that are set for it during initialisation.

Actual Behavior

I've discovered that when I use some shortcuts to display the window, that repeatedly pushing the shortcuts incrementally expands the window beyond the parameters that the window should abide by.

Below, I am pretty explicitly telling the window which size it should be:

function registerShortcuts() {
  const editorShortcut = "CommandOrControl+Alt+L";
  const bigEditorShortcut = "CommandOrControl+Alt+K";
  const escapeShortcut = "Escape";

  globalShortcut.register(editorShortcut, () => {
    if (!win.isVisible()) {
      showMiniEditor();
    } else {
      showBigEditor();
    }
  });

  globalShortcut.register(bigEditorShortcut, showBigEditor);
  globalShortcut.register(escapeShortcut, () => win.blur());
}

function prepareEditor() {
  serveLogs();
  const { width } = screen.getPrimaryDisplay().workAreaSize;
  win.setPosition(width - 820, 20);
  win.webContents.executeJavaScript("clearText()");
  win.show();
  win.webContents.executeJavaScript("focusText()");
}

function showMiniEditor() {
  prepareEditor();
  win.setSize(800, miniHeight);
}

function showBigEditor() {
  prepareEditor();
  console.log(bigHeight);
  win.setSize(800, bigHeight);
}

The bigHeight console log repeats "800, 800, 800..." every time the shortcut is pressed.

So I added some extra bells and whistles to try reign it in...

win = new BrowserWindow({
    width: 800,
    height: miniHeight,
    minWidth: 800,
    maxWidth: 800,
    x: width - 820,
    y: 20,
    frame: false,
    resizable: false,
    webPreferences: {
      preload: path.join(__dirname, "preload.js"),
      contextIsolation: true,
      devTools: true,
    },
    skipTaskbar: true,
  });

  win.setMaximumSize(800, bigHeight);
  win.on('resize', () => {
    const [width, height] = win.getSize();
    console.log(`Window resized to: ${width}x${height}`);
  });

The height eventually caps at 1004px, but the width will go on forever:

...
Window resized to: 1684x1004
Window resized to: 1685x1004
Window resized to: 1687x1004
Window resized to: 1686x1004
Window resized to: 1688x1004
Window resized to: 1689x1004
Window resized to: 1691x1004
Window resized to: 1690x1004
Window resized to: 1692x1004
...

I disabled the setPosition in prepareEditor(), set up a few more logs and found that it was never hitting the size target:

Window blurred, explicitly setting 800, 70!
Window resized to: 802x71
Showing mini editor!
Window resized to: 802x91
Mini becomes big editor!
Window resized to: 802x801
Window blurred, explicitly setting 800, 70!
Window resized to: 801x71
Big editor, str8 up!
Window resized to: 802x801

Of interest though, removing setPosition did stop the window growing, just strange that even with the boundaries set that the window is always bigger than I've defined. (And I would still like to explicitly set the location! Changes in resolution without setPosition to catch it will cause the window to appear in the wrong spot!)

2024-03-23.17-23-56.mp4

Testcase Gist URL

No response

Additional Information

No response

@codebytere codebytere added the blocked/need-repro Needs a test case to reproduce the bug label Mar 23, 2024
@electron-issue-triage
Copy link

Hello @doods-irl. Thanks for reporting this and helping to make Electron better!

Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

Now adding the blocked/need-repro Needs a test case to reproduce the bug label for this reason. After you make a test case, please link to it in a followup comment. This issue will be closed in 10 days if the above is not addressed.

@electron-issue-triage
Copy link

Unfortunately, without a way to reproduce this issue, we're unable to continue investigation. This issue has been closed and will not be monitored further. If you're able to provide a minimal test case that reproduces this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

@electron-issue-triage electron-issue-triage bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked/need-repro Needs a test case to reproduce the bug bug 🪲
Projects
None yet
Development

No branches or pull requests

2 participants