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

fix: on macOS show BrowserWindow on maximize if not currently shown #33537

Merged
merged 1 commit into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion shell/browser/native_window_mac.mm
Expand Up @@ -602,13 +602,23 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

void NativeWindowMac::Maximize() {
if (IsMaximized())
const bool is_visible = [window_ isVisible];

if (IsMaximized()) {
if (!is_visible)
ShowInactive();
return;
}

// Take note of the current window size
if (IsNormal())
original_frame_ = [window_ frame];
[window_ zoom:nil];

if (!is_visible) {
ShowInactive();
NotifyWindowMaximize();
}
}

void NativeWindowMac::Unmaximize() {
Expand Down
10 changes: 6 additions & 4 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -3578,22 +3578,24 @@ describe('BrowserWindow module', () => {
// TODO(dsanders11): Enable once maximize event works on Linux again on CI
ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => {
afterEach(closeAllWindows);
// TODO(dsanders11): Disabled on macOS, see https://github.com/electron/electron/issues/32947
ifit(process.platform !== 'darwin')('should show the window if it is not currently shown', async () => {
it('should show the window if it is not currently shown', async () => {
const w = new BrowserWindow({ show: false });
const hidden = emittedOnce(w, 'hide');
const shown = emittedOnce(w, 'show');
let shown = emittedOnce(w, 'show');
const maximize = emittedOnce(w, 'maximize');
expect(w.isVisible()).to.be.false('visible');
w.maximize();
await maximize;
await shown;
expect(w.isMaximized()).to.be.true('maximized');
expect(w.isVisible()).to.be.true('visible');
// Even if the window is already maximized
w.hide();
await hidden;
expect(w.isVisible()).to.be.false('visible');
shown = emittedOnce(w, 'show');
w.maximize();
await shown; // Ensure a 'show' event happens when it becomes visible
await shown;
expect(w.isVisible()).to.be.true('visible');
});
});
Expand Down