From 1b6264724a08feeab3b5a94f424abe6c2dadde45 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 16 Apr 2020 17:16:37 -0700 Subject: [PATCH] feat: support fullScreen BrowserWindow property --- docs/api/browser-window.md | 4 ++ lib/browser/api/top-level-window.js | 5 ++ spec-main/api-browser-window-spec.ts | 81 ++++++++++++++++++++++------ 3 files changed, 75 insertions(+), 15 deletions(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 2e07c535991d5..d76eb249cb23e 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -807,6 +807,10 @@ hide it immediately. A `Boolean` property that determines whether the window is in simple (pre-Lion) fullscreen mode. +#### `win.fullScreen` + +A `Boolean` property that determines whether the window is in fullscreen mode. + #### `win.visibleOnAllWorkspaces` A `Boolean` property that determines whether the window is visible on all workspaces. diff --git a/lib/browser/api/top-level-window.js b/lib/browser/api/top-level-window.js index a4fd836987353..9a90887fcf250 100644 --- a/lib/browser/api/top-level-window.js +++ b/lib/browser/api/top-level-window.js @@ -29,6 +29,11 @@ Object.defineProperty(TopLevelWindow.prototype, 'visibleOnAllWorkspaces', { set: function (visible) { this.setVisibleOnAllWorkspaces(visible); } }); +Object.defineProperty(TopLevelWindow.prototype, 'fullScreen', { + get: function () { return this.isFullScreen(); }, + set: function (full) { this.setFullScreen(full); } +}); + Object.defineProperty(TopLevelWindow.prototype, 'simpleFullScreen', { get: function () { return this.isSimpleFullScreen(); }, set: function (simple) { this.setSimpleFullScreen(simple); } diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index 89f30ea3efc18..d4a9f654ab725 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -993,27 +993,78 @@ describe('BrowserWindow module', () => { }); ifdescribe(process.platform === 'win32')(`Fullscreen state`, () => { - it(`checks normal bounds when fullscreen'ed`, (done) => { - const bounds = w.getBounds(); - w.once('enter-full-screen', () => { - expectBoundsEqual(w.getNormalBounds(), bounds); - done(); + it('with properties', () => { + it('can be set with the fullscreen constructor option', () => { + w = new BrowserWindow({ fullscreen: true }); + expect(w.fullScreen).to.be.true(); + }); + + it('can be changed', () => { + w.fullScreen = false; + expect(w.fullScreen).to.be.false(); + w.fullScreen = true; + expect(w.fullScreen).to.be.true(); + }); + + it(`checks normal bounds when fullscreen'ed`, (done) => { + const bounds = w.getBounds(); + w.once('enter-full-screen', () => { + expectBoundsEqual(w.getNormalBounds(), bounds); + done(); + }); + w.show(); + w.fullScreen = true; + }); + + it(`checks normal bounds when unfullscreen'ed`, (done) => { + const bounds = w.getBounds(); + w.once('enter-full-screen', () => { + w.fullScreen = false; + }); + w.once('leave-full-screen', () => { + expectBoundsEqual(w.getNormalBounds(), bounds); + done(); + }); + w.show(); + w.fullScreen = true; }); - w.show(); - w.setFullScreen(true); }); - it(`checks normal bounds when unfullscreen'ed`, (done) => { - const bounds = w.getBounds(); - w.once('enter-full-screen', () => { + it('with functions', () => { + it('can be set with the fullscreen constructor option', () => { + w = new BrowserWindow({ fullscreen: true }); + expect(w.isFullScreen()).to.be.true(); + }); + + it('can be changed', () => { w.setFullScreen(false); + expect(w.isFullScreen()).to.be.false(); + w.setFullScreen(true); + expect(w.isFullScreen()).to.be.true(); }); - w.once('leave-full-screen', () => { - expectBoundsEqual(w.getNormalBounds(), bounds); - done(); + + it(`checks normal bounds when fullscreen'ed`, (done) => { + const bounds = w.getBounds(); + w.once('enter-full-screen', () => { + expectBoundsEqual(w.getNormalBounds(), bounds); + done(); + }); + w.show(); + w.setFullScreen(true); + }); + + it(`checks normal bounds when unfullscreen'ed`, (done) => { + const bounds = w.getBounds(); + w.once('enter-full-screen', () => { + w.setFullScreen(false); + }); + w.once('leave-full-screen', () => { + expectBoundsEqual(w.getNormalBounds(), bounds); + done(); + }); + w.show(); + w.setFullScreen(true); }); - w.show(); - w.setFullScreen(true); }); }); });