Skip to content

Commit

Permalink
Save and load window state
Browse files Browse the repository at this point in the history
  • Loading branch information
sentialx committed Dec 26, 2017
1 parent 60fbf5e commit 57ac5bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ node_modules
build
dist
package-lock.json
.vscode
.vscode
.vs
26 changes: 23 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const protocolName = 'wexond'

let mainWindow

let windowBounds = {}

/** Global events. */

app.on('ready', () => {
Expand Down Expand Up @@ -71,16 +73,34 @@ const createWindow = () => {
mainWindow.loadURL(path.join('file://', __dirname, '/public/app/index.html'))
mainWindow.setMenu(null)

windowBounds = mainWindow.getBounds()

mainWindow.on('resize', () => {
if (!mainWindow.isMaximized()) {
windowBounds = mainWindow.getBounds()
}
})

mainWindow.on('move', () => {
if (!mainWindow.isMaximized()) {
windowBounds = mainWindow.getBounds()
}
})

if (data != null && data.maximized) {
mainWindow.maximize()
}

mainWindow.on('closed', () => {
mainWindow = null
})

console.log(mainWindow.getBounds())

mainWindow.on('close', () => {
data = {
bounds: mainWindow.getBounds()
maximized: mainWindow.isMaximized(),
bounds: windowBounds
}

fs.writeFileSync(windowDataPath, JSON.stringify(data))
})

Expand Down

0 comments on commit 57ac5bf

Please sign in to comment.