From 5940c9c502e43ee24522d2e0f0f0d19f22ea4be1 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 7 Jul 2022 09:54:52 +0200 Subject: [PATCH] fix: safer check for WCO button updates --- shell/browser/native_window_views.cc | 6 ++--- spec-main/api-browser-window-spec.ts | 35 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 096b2555d39ae..7ed44948f1d68 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -875,7 +875,7 @@ bool NativeWindowViews::IsMovable() { void NativeWindowViews::SetMinimizable(bool minimizable) { #if defined(OS_WIN) FlipWindowStyle(GetAcceleratedWidget(), minimizable, WS_MINIMIZEBOX); - if (titlebar_overlay_enabled()) { + if (IsWindowControlsOverlayEnabled()) { auto* frame_view = static_cast(widget()->non_client_view()->frame_view()); frame_view->caption_button_container()->UpdateButtons(); @@ -895,7 +895,7 @@ bool NativeWindowViews::IsMinimizable() { void NativeWindowViews::SetMaximizable(bool maximizable) { #if defined(OS_WIN) FlipWindowStyle(GetAcceleratedWidget(), maximizable, WS_MAXIMIZEBOX); - if (titlebar_overlay_enabled()) { + if (IsWindowControlsOverlayEnabled()) { auto* frame_view = static_cast(widget()->non_client_view()->frame_view()); frame_view->caption_button_container()->UpdateButtons(); @@ -935,7 +935,7 @@ void NativeWindowViews::SetClosable(bool closable) { } else { EnableMenuItem(menu, SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); } - if (titlebar_overlay_enabled()) { + if (IsWindowControlsOverlayEnabled()) { auto* frame_view = static_cast(widget()->non_client_view()->frame_view()); frame_view->caption_button_container()->UpdateButtons(); diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 732f19a7cde0a..c2c8781077986 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -2162,6 +2162,41 @@ describe('BrowserWindow module', () => { ifit(process.platform === 'darwin')('sets Window Control Overlay with hidden inset title bar', async () => { await testWindowsOverlay('hiddenInset'); }); + + ifdescribe(process.platform === 'win32')('when an invalid titleBarStyle is initially set', () => { + let w: BrowserWindow; + + beforeEach(() => { + w = new BrowserWindow({ + show: false, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + }, + titleBarOverlay: { + color: '#0000f0', + symbolColor: '#ffffff' + }, + titleBarStyle: 'hiddenInset' + }); + }); + + afterEach(async () => { + await closeAllWindows(); + }); + + it('does not crash changing minimizability ', () => { + expect(() => { + w.setMinimizable(false); + }).to.not.throw(); + }); + + it('does not crash changing maximizability', () => { + expect(() => { + w.setMaximizable(false); + }).to.not.throw(); + }); + }); }); ifdescribe(process.platform === 'win32' || (process.platform === 'darwin' && semver.gte(os.release(), '14.0.0')))('"titleBarOverlay" option', () => {