diff --git a/index.js b/index.js index e0690e5..fbd6815 100644 --- a/index.js +++ b/index.js @@ -35,8 +35,8 @@ module.exports = function (options) { } function validateState() { - var isValid = state && hasBounds(); - if (isValid && state.displayBounds) { + var isValid = state && (hasBounds() || state.isMaximized || state.isFullScreen); + if (hasBounds() && state.displayBounds) { // Check if the display where the window was last open is still available var displayBounds = screen.getDisplayMatching(state).bounds; isValid = deepEqual(state.displayBounds, displayBounds, {strict: true}); diff --git a/test.js b/test.js index cd50da3..30a8e5c 100644 --- a/test.js +++ b/test.js @@ -47,6 +47,52 @@ test('tries to read state file from the configured source', t => { jsonfile.readFileSync.restore(); }); +test('considers the state invalid if without bounds', t => { + const jsonfile = require('jsonfile'); + sinon.stub(jsonfile, 'readFileSync').returns({ + width: 100 + }); + + const state = require('./')({ + defaultWidth: 200 + }); + + t.not(state.width, 100); + jsonfile.readFileSync.restore(); +}); + +test('considers the state valid if without bounds but isMaximized is true', t => { + const jsonfile = require('jsonfile'); + sinon.stub(jsonfile, 'readFileSync').returns({ + isMaximized: true, + width: 100 + }); + + const state = require('./')({ + defaultWidth: 200 + }); + + t.true(state.isMaximized); + t.is(state.width, 100); + jsonfile.readFileSync.restore(); +}); + +test('considers the state valid if without bounds but isFullScreen is true', t => { + const jsonfile = require('jsonfile'); + sinon.stub(jsonfile, 'readFileSync').returns({ + isFullScreen: true, + width: 100 + }); + + const state = require('./')({ + defaultWidth: 200 + }); + + t.true(state.isFullScreen); + t.is(state.width, 100); + jsonfile.readFileSync.restore(); +}); + test('returns the defaults if the state in the file is invalid', t => { const jsonfile = require('jsonfile'); sinon.stub(jsonfile, 'readFileSync').returns({});