Skip to content

Commit

Permalink
Persist the logged-in window state (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 29, 2018
1 parent 20b2834 commit 420a443
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const config = require('./config');
const marketmaker = require('./marketmaker');
const {loginWindowSize} = require('./constants');
const {isDevelopment} = require('./util-common');
const rendererState = require('./renderer-state');

require('electron-unhandled')({
showDialog: !isDevelopment,
Expand Down Expand Up @@ -182,8 +183,9 @@ app.on('window-all-closed', () => {
});

app.on('before-quit', () => {
// TODO: Only save this when logged in.
// config.set('windowState', mainWindow.getBounds());
if (rendererState.isLoggedIn) {
config.set('windowState', mainWindow.getBounds());
}
});

ipc.answerRenderer('start-marketmaker', async seedPhrase => {
Expand Down
13 changes: 13 additions & 0 deletions app/renderer-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
const electron = require('electron');

const {ipcMain: ipc} = electron;

const rendererState = {};

ipc.on('app-container-state-updated', (event, state) => {
rendererState.appContainer = state;
rendererState.isLoggedIn = state.activeView !== 'Login' && state.activeView !== 'AppSettings';
});

module.exports = rendererState;
9 changes: 7 additions & 2 deletions app/renderer/containers/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ const setAppWindowBounds = () => {
win.setMaximizable(true);
win.setFullScreenable(true);
win.setMinimumSize(minWindowSize.width, minWindowSize.height);
setWindowBounds(config.get('windowState'));
win.center(); // TODO: Remove this when `setWindowBounds` handles positioning the window inside the window bounds

const windowState = config.get('windowState');
setWindowBounds(windowState);
const hasPositionState = Reflect.has(windowState, 'x');
if (!hasPositionState) {
win.center();
}
};

const initApi = async seedPhrase => {
Expand Down

0 comments on commit 420a443

Please sign in to comment.