mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-01 18:06:53 +01:00
feat: save window state
open the main window in the last used position of the screen
This commit is contained in:
parent
0c002918eb
commit
8f9385d508
@ -111,6 +111,7 @@
|
||||
"electron-log": "^4.4.1",
|
||||
"electron-store": "^8.0.1",
|
||||
"electron-updater": "^4.3.9",
|
||||
"electron-window-state": "^5.0.3",
|
||||
"faker": "^5.5.3",
|
||||
"marked": "^4.0.0",
|
||||
"moment": "^2.29.1",
|
||||
|
@ -3,6 +3,7 @@
|
||||
import { app, BrowserWindow, /* session, */ nativeImage, Menu } from 'electron';
|
||||
import * as path from 'path';
|
||||
import Store from 'electron-store';
|
||||
import * as windowStateKeeper from 'electron-window-state';
|
||||
import * as remoteMain from '@electron/remote/main';
|
||||
|
||||
import ipcHandlers from './ipc-handlers';
|
||||
@ -18,12 +19,15 @@ process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
|
||||
|
||||
// global reference to mainWindow (necessary to prevent window from being garbage collected)
|
||||
let mainWindow;
|
||||
let mainWindowState;
|
||||
|
||||
async function createMainWindow () {
|
||||
const icon = require('../renderer/images/logo-32.png');
|
||||
const window = new BrowserWindow({
|
||||
width: 1024,
|
||||
height: 800,
|
||||
width: mainWindowState.width,
|
||||
height: mainWindowState.height,
|
||||
x: mainWindowState.x,
|
||||
y: mainWindowState.y,
|
||||
minWidth: 900,
|
||||
minHeight: 550,
|
||||
title: 'Antares SQL',
|
||||
@ -41,6 +45,9 @@ async function createMainWindow () {
|
||||
backgroundColor: '#1d1d1d'
|
||||
});
|
||||
|
||||
mainWindowState.manage(window);
|
||||
window.on('moved', saveWindowState);
|
||||
|
||||
remoteMain.enable(window.webContents);
|
||||
|
||||
try {
|
||||
@ -70,6 +77,7 @@ async function createMainWindow () {
|
||||
}
|
||||
|
||||
window.on('closed', () => {
|
||||
window.removeListener('moved', saveWindowState);
|
||||
mainWindow = null;
|
||||
});
|
||||
|
||||
@ -104,6 +112,11 @@ else {
|
||||
|
||||
// create main BrowserWindow when electron is ready
|
||||
app.on('ready', async () => {
|
||||
mainWindowState = windowStateKeeper({
|
||||
defaultWidth: 1024,
|
||||
defaultHeight: 800
|
||||
});
|
||||
|
||||
mainWindow = await createMainWindow();
|
||||
createAppMenu();
|
||||
|
||||
@ -160,3 +173,7 @@ function createAppMenu () {
|
||||
|
||||
Menu.setApplicationMenu(menu);
|
||||
}
|
||||
|
||||
function saveWindowState () {
|
||||
mainWindowState.saveState(mainWindow);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user