Skip to content
This repository has been archived by the owner on Dec 27, 2022. It is now read-only.

Commit

Permalink
Fail safe window state reading
Browse files Browse the repository at this point in the history
  • Loading branch information
szwacz committed Feb 29, 2016
1 parent 2022260 commit 60bd286
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/vendor/electron_boilerplate/window_state.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,21 @@ export default function (name, defaults) {

var userDataDir = jetpack.cwd(app.getPath('userData'));
var stateStoreFile = 'window-state-' + name +'.json';

var state = userDataDir.read(stateStoreFile, 'json') || {
var state = {
width: defaults.width,
height: defaults.height
};

try {
var loadedState = userDataDir.read(stateStoreFile, 'json');
if (loadedState != null) {
state = loadedState;
}
} catch (err) {
// For some reason json can't be read.
// No worries, we have defaults.
}

var saveState = function (win) {
if (!win.isMaximized() && !win.isMinimized()) {
var position = win.getPosition();
Expand Down

0 comments on commit 60bd286

Please sign in to comment.