Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.

Commit 0cec257

Browse files
authored
Merge pull request #3223 from withspectrum/persist-window-state-desktop
Persist desktop app window state on reopen
2 parents 862f1c0 + 87797a0 commit 0cec257

File tree

4 files changed

+244
-347
lines changed

4 files changed

+244
-347
lines changed

desktop/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"dependencies": {
1414
"electron-is-dev": "^0.3.0",
1515
"electron-log": "^2.2.14",
16-
"electron-updater": "^2.21.4"
16+
"electron-updater": "^2.21.4",
17+
"electron-window-state": "^4.1.1"
1718
},
1819
"devDependencies": {
1920
"electron": "^1.8.4",

desktop/src/config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ module.exports = {
1717
'https://github.com/withspectrum/spectrum/blob/alpha/LICENSE',
1818
GITHUB_URL_ISSUES: 'https://github.com/withspectrum/spectrum/issues',
1919

20+
WINDOW_DEFAULT_HEIGHT: 800,
21+
WINDOW_DEFAULT_WIDTH: 1300,
2022
WINDOW_MIN_HEIGHT: 500,
2123
WINDOW_MIN_WIDTH: 770,
2224
WINDOW_BG_COLOR: '#F5F8FC',

desktop/src/main.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// @flow
22
const electron = require('electron');
3+
const windowStateKeeper = require('electron-window-state');
34
const { app, BrowserWindow } = electron;
45
const isDev = require('electron-is-dev');
56

@@ -26,12 +27,19 @@ function createWindow() {
2627
}, FIFTEEN_MINUTES);
2728
}
2829

29-
const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize;
30+
let mainWindowState = windowStateKeeper({
31+
defaultWidth: CONFIG.WINDOW_DEFAULT_WIDTH,
32+
defaultHeight: CONFIG.WINDOW_DEFAULT_HEIGHT,
33+
});
34+
35+
const { width, height, x, y } = mainWindowState;
3036

3137
// Create the main browser window.
3238
mainWindow = new BrowserWindow({
3339
width,
3440
height,
41+
x,
42+
y,
3543
titleBarStyle: 'hiddenInset',
3644
minHeight: CONFIG.WINDOW_MIN_HEIGHT,
3745
minWidth: CONFIG.WINDOW_MIN_WIDTH,
@@ -62,9 +70,10 @@ function createWindow() {
6270

6371
// if main window is ready to show, show up the main window
6472
mainWindow.once('ready-to-show', () => {
65-
mainWindow && mainWindow.maximize();
6673
mainWindow && mainWindow.show();
6774
});
75+
76+
mainWindowState.manage(mainWindow);
6877
}
6978

7079
// This method will be called when Electron has finished

0 commit comments

Comments
 (0)