Skip to content

Commit f8062e3

Browse files
author
pompurin404
committed
restore window state
#14
1 parent 1d1e712 commit f8062e3

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"electron": "^31.3.1",
4747
"electron-builder": "^25.0.3",
4848
"electron-vite": "^2.3.0",
49+
"electron-window-state": "^5.0.3",
4950
"eslint": "^8.57.0",
5051
"eslint-plugin-react": "^7.35.0",
5152
"framer-motion": "^11.3.21",

pnpm-lock.yaml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { electronApp, optimizer, is } from '@electron-toolkit/utils'
22
import { registerIpcMainHandlers } from './utils/ipc'
3+
import windowStateKeeper from 'electron-window-state'
34
import { app, shell, BrowserWindow, Menu, dialog, Notification } from 'electron'
45
import { stopCore } from './core/manager'
56
import { triggerSysProxy } from './resolve/sysproxy'
@@ -132,11 +133,17 @@ async function handleDeepLink(url: string): Promise<void> {
132133
export function createWindow(show = false): void {
133134
Menu.setApplicationMenu(null)
134135
// Create the browser window.
136+
const mainWindowState = windowStateKeeper({
137+
defaultWidth: 800,
138+
defaultHeight: 600
139+
})
135140
mainWindow = new BrowserWindow({
136141
minWidth: 800,
137142
minHeight: 600,
138-
width: 800,
139-
height: 600,
143+
width: mainWindowState.width,
144+
height: mainWindowState.height,
145+
x: mainWindowState.x,
146+
y: mainWindowState.y,
140147
show: false,
141148
autoHideMenuBar: true,
142149
...(process.platform === 'linux' ? { icon: icon } : {}),
@@ -146,6 +153,7 @@ export function createWindow(show = false): void {
146153
sandbox: false
147154
}
148155
})
156+
mainWindowState.manage(mainWindow)
149157
mainWindow.on('ready-to-show', async () => {
150158
const { silentStart } = await getAppConfig()
151159
if (!silentStart || show) {

0 commit comments

Comments
 (0)