import { app , BrowserWindow } from 'electron' ; import { join } from 'path' ; import { URL } from 'url' ; import './security-restrictions' ; const isSingleInstance = app . requestSingleInstanceLock ( ) ; const isDevelopment = import . meta . env . MODE === 'development' ; if ( ! isSingleInstance ) { app . quit ( ) ; process . exit ( 0 ) ; } app . disableHardwareAcceleration ( ) ; if ( isDevelopment ) { app . whenReady ( ) . then ( ( ) => import ( 'electron-devtools-installer' ) ) . then ( ( { default : installExtension , REACT_DEVELOPER_TOOLS } ) => installExtension ( REACT_DEVELOPER_TOOLS , { loadExtensionOptions : { allowFileAccess : true , } , } ) ) . catch ( e => console . error ( 'Failed install extension:' , e ) ) ; } let mainWindow = null ; const createWindow = async ( ) => { mainWindow = new BrowserWindow ( { show : false , webPreferences : { nativeWindowOpen : true , webviewTag : false , preload : join ( __dirname , '../../preload/dist/index.cjs' ) , } , } ) ; see https mainWindow . on ( 'ready-to-show' , ( ) => { mainWindow ?. show ( ) ; if ( isDevelopment ) { mainWindow ?. webContents . openDevTools ( ) ; } } ) ; /**
     * URL for main window.
     * Vite dev server for development.
     * `file://../renderer/index.html` for production and test
     */ const pageUrl = isDevelopment && import . meta . env . VITE_DEV_SERVER_URL !== undefined ? import . meta . env . VITE_DEV_SERVER_URL : new URL ( '../renderer/dist/index.html' , 'file://' + __dirname ) . toString ( ) ; await mainWindow . loadURL ( pageUrl ) ; } ; app . on ( 'second-instance' , ( ) => { if ( mainWindow ) { if ( mainWindow . isMinimized ( ) ) mainWindow . restore ( ) ; mainWindow . focus ( ) ; } } ) ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . whenReady ( ) . then ( createWindow ) . catch ( ( e ) => console . error ( 'Failed create window:' , e ) ) ; if ( import . meta . env . PROD ) { app . whenReady ( ) . then ( ( ) => import ( 'electron-updater' ) ) . then ( ( { autoUpdater } ) => autoUpdater . checkForUpdatesAndNotify ( ) ) . catch ( ( e ) => console . error ( 'Failed check updates:' , e ) ) ; }