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