Skip to content

Commit ca56c1f

Browse files
committed
Persist window size/position/fullscreen-ness between runs
1 parent 90fda7c commit ca56c1f

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

package-lock.json

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
"electron-compile": "^6.4.4",
2424
"electron-context-menu": "^0.10.1",
2525
"electron-squirrel-startup": "^1.0.0",
26+
"electron-window-state": "^5.0.3",
2627
"tslib": "^1.4.0"
2728
},
2829
"devDependencies": {
2930
"@types/electron-devtools-installer": "^2.0.2",
31+
"@types/electron-window-state": "^2.0.33",
3032
"@types/node": "^10.12.10",
3133
"@types/node-fetch": "^2.1.4",
3234
"@types/react": "^0.14.55",

src/index.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as os from 'os';
33
import * as path from 'path';
44
import { app, BrowserWindow, shell, Menu } from 'electron';
55

6+
import * as windowStateKeeper from 'electron-window-state';
7+
68
import registerContextMenu = require('electron-context-menu');
79
registerContextMenu({
810
showSaveImageAs: true
@@ -26,16 +28,25 @@ app.commandLine.appendSwitch('ignore-connections-limit', 'app.httptoolkit.tech')
2628
app.commandLine.appendSwitch('disable-renderer-backgrounding');
2729

2830
const createWindow = () => {
31+
// Load the previous window state, falling back to defaults
32+
let mainWindowState = windowStateKeeper({
33+
defaultWidth: 1366,
34+
defaultHeight: 768
35+
});
36+
2937
mainWindow = new BrowserWindow({
3038
title: 'HTTP Toolkit',
3139
icon: path.join(__dirname, 'src', 'icon.png'),
3240
backgroundColor: '#d8e2e6',
3341

34-
width: 1366,
35-
height: 768,
3642
minWidth: 1024,
3743
minHeight: 700,
3844

45+
x: mainWindowState.x,
46+
y: mainWindowState.y,
47+
width: mainWindowState.width,
48+
height: mainWindowState.height,
49+
3950
webPreferences: {
4051
contextIsolation: true,
4152
nodeIntegration: false
@@ -44,6 +55,8 @@ const createWindow = () => {
4455
show: false
4556
});
4657

58+
mainWindowState.manage(mainWindow);
59+
4760
mainWindow.loadURL(APP_URL);
4861

4962
mainWindow.on('ready-to-show', function() {

0 commit comments

Comments
 (0)