feat: hide menu bar on windows fullscreen (#43402)

* feat: hide menu bar on windows fullscreen

* test: state prior to html fullscreen transition

* refactor: restore `#ifdef` for readability

Reference: https://github.com/electron/electron/pull/43402#discussion_r1729356262

* docs: menu bar behavior changed

---------

Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
Piotr Płaczek 2024-09-12 19:13:04 +01:00 коммит произвёл GitHub
Родитель 3dd7e46291
Коммит 29c2744e57
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 53 добавлений и 0 удалений

Просмотреть файл

@ -14,6 +14,10 @@ This document uses the following convention to categorize breaking changes:
## Planned Breaking API Changes (33.0)
### Behavior Changed: menu bar will be hidden during fullscreen on Windows
This brings the behavior to parity with Linux. Prior behavior: Menu bar is still visible during fullscreen on Windows. New behavior: Menu bar is hidden during fullscreen on Windows.
### Behavior Changed: `webContents` property on `login` on `app`
The `webContents` property in the `login` event from `app` will be `null`

Просмотреть файл

@ -746,6 +746,24 @@ void NativeWindowViews::SetFullScreen(bool fullscreen) {
// Note: the following must be after "widget()->SetFullscreen(fullscreen);"
if (leaving_fullscreen && !IsVisible())
FlipWindowStyle(GetAcceleratedWidget(), true, WS_VISIBLE);
// Auto-hide menubar when in fullscreen.
if (fullscreen) {
menu_bar_visible_before_fullscreen_ = IsMenuBarVisible();
SetMenuBarVisibility(false);
} else {
// No fullscreen -> fullscreen video -> un-fullscreen video results
// in `NativeWindowViews::SetFullScreen(false)` being called twice.
// `menu_bar_visible_before_fullscreen_` is always false on the
// second call which results in `SetMenuBarVisibility(false)` no
// matter what. We check `leaving_fullscreen` to avoid this.
if (!leaving_fullscreen)
return;
SetMenuBarVisibility(!IsMenuBarAutoHide() &&
menu_bar_visible_before_fullscreen_);
menu_bar_visible_before_fullscreen_ = false;
}
#else
if (IsVisible())
widget()->SetFullscreen(fullscreen);

Просмотреть файл

@ -5630,6 +5630,37 @@ describe('BrowserWindow module', () => {
});
});
ifdescribe(process.platform !== 'darwin')('fullscreen state', () => {
it('correctly remembers state prior to HTML fullscreen transition', async () => {
const w = new BrowserWindow();
await w.loadFile(path.join(fixtures, 'pages', 'a.html'));
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
expect(w.isFullScreen()).to.be.false('is fullscreen');
const enterFullScreen = once(w, 'enter-full-screen');
const leaveFullScreen = once(w, 'leave-full-screen');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isFullScreen()).to.be.false('is fullscreen');
expect(w.isMenuBarVisible()).to.be.true('isMenuBarVisible');
w.setMenuBarVisibility(false);
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
await w.webContents.executeJavaScript('document.getElementById("div").requestFullscreen()', true);
await enterFullScreen;
await w.webContents.executeJavaScript('document.exitFullscreen()', true);
await leaveFullScreen;
expect(w.isMenuBarVisible()).to.be.false('isMenuBarVisible');
});
});
ifdescribe(process.platform === 'darwin')('fullscreenable state', () => {
it('with functions', () => {
it('can be set with fullscreenable constructor option', () => {