save window stats on all close types

This commit is contained in:
Andrew Gundersen 2021-03-20 12:33:55 -05:00
commit e7fd5a0bfa
5 changed files with 54 additions and 32 deletions

View file

@ -19,7 +19,6 @@ const onNavBar = (_event: any, action: string): void => {
console.log("onNavBar")
if (win) {
if (action === "close") {
saveWindowState()
win.close()
} else {
win.minimize()
@ -54,7 +53,7 @@ const saveWindowState = () => {
fs.writeFile('windowState.json', state, (err) => {
if (err) throw err;
return;
});
});
}
}
@ -62,7 +61,7 @@ const saveWindowState = () => {
const onWindowMount = (): void => {
backgroundMitt.emit('window-active', true);
// handle win nav-bar event.
// Handle win nav-bar event.
ipcMain.removeHandler('nav-bar'); // avoid setting duplicate handlers
ipcMain.handle('nav-bar', onNavBar);
@ -115,6 +114,10 @@ export async function createWindow(): Promise<void> {
// Handle window close.
win.on("closed", onWindowDismount);
// Save window state on resize and move.
win.on("moved", saveWindowState);
win.on("resize", saveWindowState);
win.once('ready-to-show', () => {
if (win) win.show()
})