Skip to content

Commit

Permalink
Add persistent window state
Browse files Browse the repository at this point in the history
  • Loading branch information
Heath123 committed Dec 8, 2020
1 parent c65b30b commit f880fea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
17 changes: 11 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"clusterize.js": "^0.18.1",
"electron-localshortcut": "^3.2.1",
"electron-squirrel-startup": "^1.0.0",
"electron-window-state": "^5.0.3",
"escape-html": "^1.0.3",
"md5-file": "^5.0.0",
"minecraft-data": "^2.70.2",
Expand Down
20 changes: 18 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const packetHandler = require('./packetHandler.js')
const setupDataFolder = require('./setupDataFolder.js')

const electronLocalShortcut = require('electron-localshortcut')
const windowStateKeeper = require('electron-window-state')
const fs = require('fs')

let proxy // Defined later when an option is chosen
Expand Down Expand Up @@ -81,16 +82,29 @@ function makeMenu (direction, text, id) {
}

function createWindow () {
// Load the previous state with fallback to defaults
const mainWindowState = windowStateKeeper({
defaultWidth: 1000,
defaultHeight: 800
});

// Let us register listeners on the window, so we can update the state
// automatically (the listeners will be removed when the window is closed)
// and restore the maximized or full screen state

// Create the browser window.
const win = new BrowserWindow({
width: 800,
height: 600,
x: mainWindowState.x,
y: mainWindowState.y,
width: mainWindowState.width,
height: mainWindowState.height,
// frame: false,
webPreferences: {
nodeIntegration: true
},
icon: resourcesPath + 'icons/icon.png'
})

win.setMenu(null)
// and load the index.html of the app.
win.loadFile('html/startPage/index.html')
Expand All @@ -99,6 +113,8 @@ function createWindow () {
electronLocalShortcut.register(win, 'F12', () => {
win.openDevTools()
})

mainWindowState.manage(win)
}

// This method will be called when Electron has finished
Expand Down

0 comments on commit f880fea

Please sign in to comment.