Skip to content

Commit

Permalink
fix: on macOS show BrowserWindow on maximize if not currently shown
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Feb 18, 2022
1 parent e08ced5 commit 0c6ba08
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion shell/browser/native_window_mac.mm
Expand Up @@ -600,13 +600,19 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

void NativeWindowMac::Maximize() {
if (IsMaximized())
if (IsMaximized()) {
if (![window_ isVisible]) {
ShowInactive();
}
return;
}

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

ShowInactive();
}

void NativeWindowMac::Unmaximize() {
Expand Down
22 changes: 22 additions & 0 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -3509,6 +3509,28 @@ describe('BrowserWindow module', () => {
});
});

// TODO(dsanders11): Enable once maximize event works on Linux again on CI
ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => {
afterEach(closeAllWindows);
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');
const maximize = emittedOnce(w, 'maximize');
expect(w.isVisible()).to.be.false('visible');
w.maximize();
await maximize;
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');
w.maximize();
await shown;
expect(w.isVisible()).to.be.true('visible');
});
});

describe('BrowserWindow.unmaximize()', () => {
afterEach(closeAllWindows);
it('should restore the previous window position', () => {
Expand Down

0 comments on commit 0c6ba08

Please sign in to comment.