restore window state

#14
This commit is contained in:
pompurin404 2024-08-14 12:16:08 +08:00
parent 1d1e712014
commit f8062e3251
No known key found for this signature in database
3 changed files with 31 additions and 2 deletions

View File

@ -46,6 +46,7 @@
"electron": "^31.3.1",
"electron-builder": "^25.0.3",
"electron-vite": "^2.3.0",
"electron-window-state": "^5.0.3",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.35.0",
"framer-motion": "^11.3.21",

View File

@ -84,6 +84,9 @@ importers:
electron-vite:
specifier: ^2.3.0
version: 2.3.0(vite@5.3.5(@types/node@22.1.0))
electron-window-state:
specifier: ^5.0.3
version: 5.0.3
eslint:
specifier: ^8.57.0
version: 8.57.0
@ -2505,6 +2508,10 @@ packages:
'@swc/core':
optional: true
electron-window-state@5.0.3:
resolution: {integrity: sha512-1mNTwCfkolXl3kMf50yW3vE2lZj0y92P/HYWFBrb+v2S/pCka5mdwN3cagKm458A7NjndSwijynXgcLWRodsVg==}
engines: {node: '>=8.0.0'}
electron@31.3.1:
resolution: {integrity: sha512-9fiuWlRhBfygtcT+auRd/WdBK/f8LZZcrpx0RjpXhH2DPTP/PfnkC4JB1PW55qCbGbh4wAgkYbf4ExIag8oGCA==}
engines: {node: '>= 12.20.55'}
@ -3373,6 +3380,10 @@ packages:
resolution: {integrity: sha512-umcy022ILvb5/3Djuu8LWeqUa8D68JaBzlttKeMWen48SjabqS3iY5w/vzeMzMUNhLDifyhbOwKDSznB1vvrwg==}
engines: {node: '>= 18'}
mkdirp@0.5.6:
resolution: {integrity: sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==}
hasBin: true
mkdirp@1.0.4:
resolution: {integrity: sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==}
engines: {node: '>=10'}
@ -7886,6 +7897,11 @@ snapshots:
transitivePeerDependencies:
- supports-color
electron-window-state@5.0.3:
dependencies:
jsonfile: 4.0.0
mkdirp: 0.5.6
electron@31.3.1:
dependencies:
'@electron/get': 2.0.3
@ -8884,6 +8900,10 @@ snapshots:
minipass: 7.1.2
rimraf: 5.0.10
mkdirp@0.5.6:
dependencies:
minimist: 1.2.8
mkdirp@1.0.4: {}
mkdirp@3.0.1: {}

View File

@ -1,5 +1,6 @@
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import { registerIpcMainHandlers } from './utils/ipc'
import windowStateKeeper from 'electron-window-state'
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
import { stopCore } from './core/manager'
import { triggerSysProxy } from './resolve/sysproxy'
@ -132,11 +133,17 @@ async function handleDeepLink(url: string): Promise<void> {
export function createWindow(show = false): void {
Menu.setApplicationMenu(null)
// Create the browser window.
const mainWindowState = windowStateKeeper({
defaultWidth: 800,
defaultHeight: 600
})
mainWindow = new BrowserWindow({
minWidth: 800,
minHeight: 600,
width: 800,
height: 600,
width: mainWindowState.width,
height: mainWindowState.height,
x: mainWindowState.x,
y: mainWindowState.y,
show: false,
autoHideMenuBar: true,
...(process.platform === 'linux' ? { icon: icon } : {}),
@ -146,6 +153,7 @@ export function createWindow(show = false): void {
sandbox: false
}
})
mainWindowState.manage(mainWindow)
mainWindow.on('ready-to-show', async () => {
const { silentStart } = await getAppConfig()
if (!silentStart || show) {