Skip to content

Commit

Permalink
feat: persist window size
Browse files Browse the repository at this point in the history
this commit relates to #205
  • Loading branch information
4gray committed Dec 26, 2022
1 parent b42605c commit 2ce60e0
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 59 deletions.
20 changes: 17 additions & 3 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const {
attachTitlebarToWindow,
} = require('custom-electron-titlebar/main');
const contextMenu = require('electron-context-menu');
const Store = require('electron-store');
const store = new Store();

const WINDOW_BOUNDS = 'WINDOW_BOUNDS';

setupTitlebar();
let win: BrowserWindow | null = null;
Expand Down Expand Up @@ -36,9 +40,10 @@ function createWindow(): BrowserWindow {
icon: path.join(__dirname, '../dist/assets/icons/icon.png'),
titleBarStyle: 'hidden',
frame: false,
minWidth: 900,
minHeight: 700,
minWidth: 400,
minHeight: 500,
title: 'IPTVnator',
...store.get(WINDOW_BOUNDS),
});
attachTitlebarToWindow(win);

Expand All @@ -57,6 +62,10 @@ function createWindow(): BrowserWindow {
);
}

win.on('close', () => {
store.set(WINDOW_BOUNDS, win?.getNormalBounds());
});

// Emitted when the window is closed.
win.on('closed', () => {
// Dereference the window object, usually you would store window
Expand Down Expand Up @@ -138,9 +147,14 @@ try {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow();
win = createWindow();
api.setMainWindow(win);
}
});

app.on('before-quit', () => {
store.set(WINDOW_BOUNDS, win?.getNormalBounds());
});
} catch (e) {
// Catch Error
throw e;
Expand Down
Loading

0 comments on commit 2ce60e0

Please sign in to comment.