File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import { BrowserWindow } from 'electron';
1010export const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
1111
1212const CHUNK_SIZE = 64 * 1024 ;
13- let window : any ;
13+ let window : BrowserWindow | null = null ;
1414
1515process . env [ 'ELECTRON_DISABLE_SECURITY_WARNINGS' ] = 'true' ;
1616
@@ -49,7 +49,15 @@ const applyAppIcon = () => {
4949 return icon ;
5050} ;
5151
52- const createWindow = ( ) => {
52+ const createWindow = async ( ) => {
53+ if ( ! app . isReady ( ) ) {
54+ await app . whenReady ( ) ;
55+ }
56+
57+ if ( window && ! window . isDestroyed ( ) ) {
58+ return window ;
59+ }
60+
5361 const appIcon = applyAppIcon ( ) ;
5462
5563 window = new BrowserWindow ( {
@@ -73,6 +81,10 @@ const createWindow = () => {
7381 icon : appIcon
7482 } ) ;
7583
84+ window . on ( 'closed' , ( ) => {
85+ window = null ;
86+ } ) ;
87+
7688 const serveUrl = process . env . VITE_DEV_SERVER_URL ;
7789
7890 if ( app . isPackaged ) {
@@ -85,6 +97,8 @@ const createWindow = () => {
8597 } ) ;
8698 window . webContents . openDevTools ( ) ;
8799 }
100+
101+ return window ;
88102} ;
89103
90104app . whenReady ( ) . then ( ( ) => {
You can’t perform that action at this time.
0 commit comments