Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider a state without bounds still valid if fullscreen of maximized #10

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
46 changes: 46 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down