From 4e44ab4d4d264d1756c229b24723017a36319507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=ABck=20V=C3=A9zien?= Date: Thu, 8 Feb 2018 18:24:11 +0100 Subject: [PATCH] Save window positions --- src/main/app.js | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/main/app.js b/src/main/app.js index f294c18b..172909ad 100644 --- a/src/main/app.js +++ b/src/main/app.js @@ -23,24 +23,26 @@ const getWindowPosition = (height, width) => { } } -const defaultWindowOptions = ({ height, width }) => ({ - ...getWindowPosition(height, width), +const defaultWindowOptions = { backgroundColor: '#fff', webPreferences: { devTools, }, -}) +} function createMainWindow() { const MIN_HEIGHT = 768 const MIN_WIDTH = 1024 + const savedDimensions = db.getIn('settings', 'window.dimensions', {}) + const savedPositions = db.getIn('settings', 'window.positions', null) const width = savedDimensions.width || MIN_WIDTH const height = savedDimensions.height || MIN_HEIGHT const windowOptions = { - ...defaultWindowOptions({ height, width }), + ...defaultWindowOptions, + ...(savedPositions !== null ? savedPositions : getWindowPosition(height, width)), ...(process.platform === 'darwin' ? { frame: false, @@ -81,10 +83,21 @@ function createMainWindow() { } }) - window.on('resize', debounce(() => { - const [width, height] = window.getSize() - db.setIn('settings', 'window.dimensions', { width, height }) - }, 100)) + window.on( + 'resize', + debounce(() => { + const [width, height] = window.getSize() + db.setIn('settings', 'window.dimensions', { width, height }) + }, 100), + ) + + window.on( + 'move', + debounce(() => { + const [x, y] = window.getPosition() + db.setIn('settings', 'window.positions', { x, y }) + }, 100), + ) window.webContents.on('devtools-opened', () => { window.focus() @@ -104,7 +117,8 @@ function createPreloadWindow() { const width = 256 const windowOptions = { - ...defaultWindowOptions({ height, width }), + ...defaultWindowOptions, + ...getWindowPosition(height, width), closable: false, frame: false, fullscreenable: false,