X Tutup
Skip to content

Commit dcf825b

Browse files
fix: fire show event when BrowserWindow shown via maximize() (electron#33214)
Co-authored-by: David Sanders <dsanders11@ucsbalum.com>
1 parent cee4e37 commit dcf825b

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

shell/browser/native_window_views.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,13 @@ void NativeWindowViews::SetEnabledInternal(bool enable) {
580580

581581
#if BUILDFLAG(IS_LINUX)
582582
void NativeWindowViews::Maximize() {
583-
if (IsVisible())
583+
if (IsVisible()) {
584584
widget()->Maximize();
585-
else
585+
} else {
586586
widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED,
587587
gfx::Rect());
588+
NotifyWindowShow();
589+
}
588590
}
589591
#endif
590592

shell/browser/native_window_views_win.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,13 @@ HHOOK NativeWindowViews::mouse_hook_ = NULL;
178178
void NativeWindowViews::Maximize() {
179179
// Only use Maximize() when window is NOT transparent style
180180
if (!transparent()) {
181-
if (IsVisible())
181+
if (IsVisible()) {
182182
widget()->Maximize();
183-
else
183+
} else {
184184
widget()->native_widget_private()->Show(ui::SHOW_STATE_MAXIMIZED,
185185
gfx::Rect());
186-
return;
186+
NotifyWindowShow();
187+
}
187188
} else {
188189
restore_bounds_ = GetBounds();
189190
auto display = display::Screen::GetScreen()->GetDisplayNearestWindow(

spec-main/api-browser-window-spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3556,6 +3556,29 @@ describe('BrowserWindow module', () => {
35563556
});
35573557
});
35583558

3559+
// TODO(dsanders11): Enable once maximize event works on Linux again on CI
3560+
ifdescribe(process.platform !== 'linux')('BrowserWindow.maximize()', () => {
3561+
afterEach(closeAllWindows);
3562+
// TODO(dsanders11): Disabled on macOS, see https://github.com/electron/electron/issues/32947
3563+
ifit(process.platform !== 'darwin')('should show the window if it is not currently shown', async () => {
3564+
const w = new BrowserWindow({ show: false });
3565+
const hidden = emittedOnce(w, 'hide');
3566+
const shown = emittedOnce(w, 'show');
3567+
const maximize = emittedOnce(w, 'maximize');
3568+
expect(w.isVisible()).to.be.false('visible');
3569+
w.maximize();
3570+
await maximize;
3571+
expect(w.isVisible()).to.be.true('visible');
3572+
// Even if the window is already maximized
3573+
w.hide();
3574+
await hidden;
3575+
expect(w.isVisible()).to.be.false('visible');
3576+
w.maximize();
3577+
await shown; // Ensure a 'show' event happens when it becomes visible
3578+
expect(w.isVisible()).to.be.true('visible');
3579+
});
3580+
});
3581+
35593582
describe('BrowserWindow.unmaximize()', () => {
35603583
afterEach(closeAllWindows);
35613584
it('should restore the previous window position', () => {

0 commit comments

Comments
 (0)
X Tutup