Skip to content

Commit

Permalink
feat: enhance window management
Browse files Browse the repository at this point in the history
- Introduced functionality to save and restore window position and size using local storage.
- Implemented event listeners to track window movements and resizing, ensuring the application remembers its last state.
- Added logic to handle maximized state, allowing the window to restore its maximized state upon reopening.
  • Loading branch information
0xIbra committed Dec 17, 2024
1 parent a17b9fb commit 37a348e
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,20 @@ const DEFAULT_IGNORE_PATTERNS = [
'Thumbs.db',
];

// Near the top with other store initialization
const DEFAULT_WINDOW_BOUNDS = {
width: 1400,
height: 800,
x: undefined,
y: undefined
};

function createWindow() {
// Get stored window bounds
const windowBounds = store.get('windowBounds', DEFAULT_WINDOW_BOUNDS);

const win = new BrowserWindow({
width: 1400,
height: 800,
...windowBounds,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
Expand All @@ -62,9 +72,36 @@ function createWindow() {
icon: path.join(__dirname, 'assets/icons/256x256.png')
});

// Save window position and size when it changes
['move', 'resize'].forEach(event => {
win.on(event, () => {
if (!win.isMaximized()) {
const bounds = win.getBounds();
store.set('windowBounds', bounds);
}
});
});

// Save maximized state
win.on('maximize', () => {
store.set('windowMaximized', true);
});

win.on('unmaximize', () => {
store.set('windowMaximized', false);
// Save current bounds after unmaximize
const bounds = win.getBounds();
store.set('windowBounds', bounds);
});

remote.enable(win.webContents);
win.loadFile('index.html');

// Restore maximized state if it was maximized when closed
if (store.get('windowMaximized', false)) {
win.maximize();
}

return win;
}

Expand Down

0 comments on commit 37a348e

Please sign in to comment.