mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-23 07:09:01 +01:00
Merge pull request #536 from jarne/bugfix/bug-451-max-window-reset
Fix: save window maximized state
This commit is contained in:
commit
ece5ad3175
@ -10,7 +10,7 @@ const registerNetworkIpc = require('./ipc/network');
|
||||
const registerCollectionsIpc = require('./ipc/collection');
|
||||
const registerPreferencesIpc = require('./ipc/preferences');
|
||||
const Watcher = require('./app/watcher');
|
||||
const { loadWindowState, saveWindowState } = require('./utils/window');
|
||||
const { loadWindowState, saveBounds, saveMaximized } = require('./utils/window');
|
||||
|
||||
const lastOpenedCollections = new LastOpenedCollections();
|
||||
|
||||
@ -33,7 +33,7 @@ let watcher;
|
||||
|
||||
// Prepare the renderer once the app is ready
|
||||
app.on('ready', async () => {
|
||||
const { x, y, width, height } = loadWindowState();
|
||||
const { maximized, x, y, width, height } = loadWindowState();
|
||||
|
||||
mainWindow = new BrowserWindow({
|
||||
x,
|
||||
@ -55,6 +55,10 @@ app.on('ready', async () => {
|
||||
// autoHideMenuBar: true
|
||||
});
|
||||
|
||||
if (maximized) {
|
||||
mainWindow.maximize();
|
||||
}
|
||||
|
||||
const url = isDev
|
||||
? 'http://localhost:3000'
|
||||
: format({
|
||||
@ -66,8 +70,17 @@ app.on('ready', async () => {
|
||||
mainWindow.loadURL(url);
|
||||
watcher = new Watcher();
|
||||
|
||||
mainWindow.on('resize', () => saveWindowState(mainWindow));
|
||||
mainWindow.on('move', () => saveWindowState(mainWindow));
|
||||
const handleBoundsChange = () => {
|
||||
if (!mainWindow.isMaximized()) {
|
||||
saveBounds(mainWindow);
|
||||
}
|
||||
};
|
||||
|
||||
mainWindow.on('resize', handleBoundsChange);
|
||||
mainWindow.on('move', handleBoundsChange);
|
||||
|
||||
mainWindow.on('maximize', () => saveMaximized(true));
|
||||
mainWindow.on('unmaximize', () => saveMaximized(false));
|
||||
|
||||
mainWindow.webContents.on('new-window', function (e, url) {
|
||||
e.preventDefault();
|
||||
|
@ -3,6 +3,8 @@ const Store = require('electron-store');
|
||||
const DEFAULT_WINDOW_WIDTH = 1280;
|
||||
const DEFAULT_WINDOW_HEIGHT = 768;
|
||||
|
||||
const DEFAULT_MAXIMIZED = false;
|
||||
|
||||
class WindowStateStore {
|
||||
constructor() {
|
||||
this.store = new Store({
|
||||
@ -25,6 +27,14 @@ class WindowStateStore {
|
||||
setBounds(bounds) {
|
||||
this.store.set('window-bounds', bounds);
|
||||
}
|
||||
|
||||
getMaximized() {
|
||||
return this.store.get('maximized') || DEFAULT_MAXIMIZED;
|
||||
}
|
||||
|
||||
setMaximized(isMaximized) {
|
||||
this.store.set('maximized', isMaximized);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WindowStateStore;
|
||||
|
@ -7,12 +7,14 @@ const DEFAULT_WINDOW_WIDTH = 1280;
|
||||
const DEFAULT_WINDOW_HEIGHT = 768;
|
||||
|
||||
const loadWindowState = () => {
|
||||
const maximized = windowStateStore.getMaximized();
|
||||
const bounds = windowStateStore.getBounds();
|
||||
|
||||
const positionValid = isPositionValid(bounds);
|
||||
const sizeValid = isSizeValid(bounds);
|
||||
|
||||
return {
|
||||
maximized,
|
||||
x: bounds.x && positionValid ? bounds.x : undefined,
|
||||
y: bounds.y && positionValid ? bounds.y : undefined,
|
||||
width: bounds.width && sizeValid ? bounds.width : DEFAULT_WINDOW_WIDTH,
|
||||
@ -20,12 +22,16 @@ const loadWindowState = () => {
|
||||
};
|
||||
};
|
||||
|
||||
const saveWindowState = (window) => {
|
||||
const saveBounds = (window) => {
|
||||
const bounds = window.getBounds();
|
||||
|
||||
windowStateStore.setBounds(bounds);
|
||||
};
|
||||
|
||||
const saveMaximized = (isMaximized) => {
|
||||
windowStateStore.setMaximized(isMaximized);
|
||||
};
|
||||
|
||||
const isPositionValid = (bounds) => {
|
||||
const area = getArea(bounds);
|
||||
|
||||
@ -49,5 +55,6 @@ const getArea = (bounds) => {
|
||||
|
||||
module.exports = {
|
||||
loadWindowState,
|
||||
saveWindowState
|
||||
saveBounds,
|
||||
saveMaximized
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user