import path from 'path' ; import { app , protocol , BrowserWindow , shell , screen , } from 'electron' ; import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' ; import installExtension , { VUEJS_DEVTOOLS } from 'electron-devtools-installer' ; import log from 'electron-log' ; import { setupAutoUpdater } from './Update/Updater' ; const isDevelopment = process . env . NODE_ENV !== 'production' ; declare const __static ; let win ; protocol . registerSchemesAsPrivileged ( [ { scheme : 'app' , privileges : { secure : true , standard : true } } , ] ) ; log . transports . file . level = 'silly' ; if ( ! process . env . IS_TEST ) { Object . assign ( console , log . functions ) ; } function createWindow ( ) { const size = getWindowSize ( 1650 , 955 ) ; win = new BrowserWindow ( { width : size . width , height : size . height , webPreferences : { contextIsolation : false , nodeIntegration : ( process . env . ELECTRON_NODE_INTEGRATION as unknown ) as boolean , } , icon : path . join ( __static , 'icon.png' ) , } ) ; win . setMenuBarVisibility ( false ) ; configureExternalsUrlsOpenBrowser ( win ) ; loadApplication ( win ) ; win . on ( 'closed' , ( ) => { win = null ; } ) ; } let macOsQuit = false ; app . on ( 'window-all-closed' , ( ) => { if ( process . platform === 'darwin' && ! macOsQuit ) { return ; } app . quit ( ) ; } ) ; if ( process . platform === 'darwin' ) { app . on ( 'before-quit' , ( ) => { macOsQuit = true ; } ) ; } app . on ( 'activate' , ( ) => { if ( win === null ) { createWindow ( ) ; } } ) ; app . on ( 'ready' , async ( ) => { if ( isDevelopment && ! process . env . IS_TEST ) { try { await installExtension ( VUEJS_DEVTOOLS ) ; } catch ( e ) { console . error ( 'Vue Devtools failed to install:' , e . toString ( ) ) ; } } createWindow ( ) ; } ) ; if ( isDevelopment ) { if ( process . platform === 'win32' ) { process . on ( 'message' , ( data ) => { if ( data === 'graceful-exit' ) { app . quit ( ) ; } } ) ; } else { process . on ( 'SIGTERM' , ( ) => { app . quit ( ) ; } ) ; } } function loadApplication ( window ) { if ( process . env . WEBPACK_DEV_SERVER_URL ) { loadUrlWithNodeWorkaround ( win , process . env . WEBPACK_DEV_SERVER_URL as string ) ; if ( ! process . env . IS_TEST ) { window . webContents . openDevTools ( ) ; } } else { createProtocol ( 'app' ) ; loadUrlWithNodeWorkaround ( win , 'app://./index.html' ) ; const updater = setupAutoUpdater ( ) ; updater . checkForUpdates ( ) ; } } function configureExternalsUrlsOpenBrowser ( window ) { window . webContents . on ( 'new-window' , ( event , url ) => { if ( url !== win . webContents . getURL ( ) ) { event . preventDefault ( ) ; shell . openExternal ( url ) ; } } ) ; } function loadUrlWithNodeWorkaround ( window , url ) { setTimeout ( ( ) => { window . loadURL ( url ) ; } , 10 ) ; } function getWindowSize ( idealWidth , idealHeight ) { let { width , height } = screen . getPrimaryDisplay ( ) . workAreaSize ; width = Math . min ( width , idealWidth ) ; height = Math . min ( height , idealHeight ) ; return { width , height } ; }