Skip to content

Commit f3dc399

Browse files
authored
feat: support fullScreen BrowserWindow property (electron#23145)
1 parent 928e23a commit f3dc399

File tree

3 files changed

+75
-15
lines changed

3 files changed

+75
-15
lines changed

docs/api/browser-window.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,10 @@ hide it immediately.
807807

808808
A `Boolean` property that determines whether the window is in simple (pre-Lion) fullscreen mode.
809809

810+
#### `win.fullScreen`
811+
812+
A `Boolean` property that determines whether the window is in fullscreen mode.
813+
810814
#### `win.visibleOnAllWorkspaces`
811815

812816
A `Boolean` property that determines whether the window is visible on all workspaces.

lib/browser/api/top-level-window.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ Object.defineProperty(TopLevelWindow.prototype, 'visibleOnAllWorkspaces', {
2929
set: function (visible) { this.setVisibleOnAllWorkspaces(visible); }
3030
});
3131

32+
Object.defineProperty(TopLevelWindow.prototype, 'fullScreen', {
33+
get: function () { return this.isFullScreen(); },
34+
set: function (full) { this.setFullScreen(full); }
35+
});
36+
3237
Object.defineProperty(TopLevelWindow.prototype, 'simpleFullScreen', {
3338
get: function () { return this.isSimpleFullScreen(); },
3439
set: function (simple) { this.setSimpleFullScreen(simple); }

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

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,27 +1010,78 @@ describe('BrowserWindow module', () => {
10101010
});
10111011

10121012
ifdescribe(process.platform === 'win32')(`Fullscreen state`, () => {
1013-
it(`checks normal bounds when fullscreen'ed`, (done) => {
1014-
const bounds = w.getBounds();
1015-
w.once('enter-full-screen', () => {
1016-
expectBoundsEqual(w.getNormalBounds(), bounds);
1017-
done();
1013+
it('with properties', () => {
1014+
it('can be set with the fullscreen constructor option', () => {
1015+
w = new BrowserWindow({ fullscreen: true });
1016+
expect(w.fullScreen).to.be.true();
1017+
});
1018+
1019+
it('can be changed', () => {
1020+
w.fullScreen = false;
1021+
expect(w.fullScreen).to.be.false();
1022+
w.fullScreen = true;
1023+
expect(w.fullScreen).to.be.true();
1024+
});
1025+
1026+
it(`checks normal bounds when fullscreen'ed`, (done) => {
1027+
const bounds = w.getBounds();
1028+
w.once('enter-full-screen', () => {
1029+
expectBoundsEqual(w.getNormalBounds(), bounds);
1030+
done();
1031+
});
1032+
w.show();
1033+
w.fullScreen = true;
1034+
});
1035+
1036+
it(`checks normal bounds when unfullscreen'ed`, (done) => {
1037+
const bounds = w.getBounds();
1038+
w.once('enter-full-screen', () => {
1039+
w.fullScreen = false;
1040+
});
1041+
w.once('leave-full-screen', () => {
1042+
expectBoundsEqual(w.getNormalBounds(), bounds);
1043+
done();
1044+
});
1045+
w.show();
1046+
w.fullScreen = true;
10181047
});
1019-
w.show();
1020-
w.setFullScreen(true);
10211048
});
10221049

1023-
it(`checks normal bounds when unfullscreen'ed`, (done) => {
1024-
const bounds = w.getBounds();
1025-
w.once('enter-full-screen', () => {
1050+
it('with functions', () => {
1051+
it('can be set with the fullscreen constructor option', () => {
1052+
w = new BrowserWindow({ fullscreen: true });
1053+
expect(w.isFullScreen()).to.be.true();
1054+
});
1055+
1056+
it('can be changed', () => {
10261057
w.setFullScreen(false);
1058+
expect(w.isFullScreen()).to.be.false();
1059+
w.setFullScreen(true);
1060+
expect(w.isFullScreen()).to.be.true();
10271061
});
1028-
w.once('leave-full-screen', () => {
1029-
expectBoundsEqual(w.getNormalBounds(), bounds);
1030-
done();
1062+
1063+
it(`checks normal bounds when fullscreen'ed`, (done) => {
1064+
const bounds = w.getBounds();
1065+
w.once('enter-full-screen', () => {
1066+
expectBoundsEqual(w.getNormalBounds(), bounds);
1067+
done();
1068+
});
1069+
w.show();
1070+
w.setFullScreen(true);
1071+
});
1072+
1073+
it(`checks normal bounds when unfullscreen'ed`, (done) => {
1074+
const bounds = w.getBounds();
1075+
w.once('enter-full-screen', () => {
1076+
w.setFullScreen(false);
1077+
});
1078+
w.once('leave-full-screen', () => {
1079+
expectBoundsEqual(w.getNormalBounds(), bounds);
1080+
done();
1081+
});
1082+
w.show();
1083+
w.setFullScreen(true);
10311084
});
1032-
w.show();
1033-
w.setFullScreen(true);
10341085
});
10351086
});
10361087
});

0 commit comments

Comments
 (0)