fix: fullscreen restoration on Windows (#49891)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot]
2026-02-21 09:45:13 +01:00
committed by GitHub
parent b5c7b6fddd
commit a9c8647508
3 changed files with 30 additions and 0 deletions

View File

@@ -197,6 +197,14 @@ void ElectronDesktopWindowTreeHostWin::SetAllowScreenshots(bool allow) {
UpdateAllowScreenshots();
}
// Refs https://chromium-review.googlesource.com/c/chromium/src/+/7095963
// Chromium's fullscreen handler conflicts with ours and results in incorrect
// restoration.
void ElectronDesktopWindowTreeHostWin::Restore() {
::SendMessage(GetAcceleratedWidget(), WM_SYSCOMMAND,
static_cast<WPARAM>(SC_RESTORE), 0);
}
void ElectronDesktopWindowTreeHostWin::UpdateAllowScreenshots() {
bool allowed = views::DesktopWindowTreeHostWin::AreScreenshotsAllowed();
if (allowed == allow_screenshots_)

View File

@@ -50,6 +50,7 @@ class ElectronDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin,
LRESULT* result) override;
void HandleVisibilityChanged(bool visible) override;
void SetAllowScreenshots(bool allow) override;
void Restore() override;
// ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;

View File

@@ -4882,6 +4882,27 @@ describe('BrowserWindow module', () => {
await restore;
expect(w.isMaximized()).to.equal(true);
});
ifit(process.platform !== 'linux')('should not break fullscreen state', async () => {
const w = new BrowserWindow({ show: false });
w.show();
const enterFS = once(w, 'enter-full-screen');
w.setFullScreen(true);
await enterFS;
expect(w.isFullScreen()).to.be.true('not fullscreen');
w.restore();
await setTimeout(1000);
expect(w.isFullScreen()).to.be.true('not fullscreen after restore');
expect(w.isMinimized()).to.be.false('should not be minimized');
// Clean up fullscreen state.
const leaveFS = once(w, 'leave-full-screen');
w.setFullScreen(false);
await leaveFS;
});
});
// TODO(dsanders11): Enable once maximize event works on Linux again on CI