import { app , autoUpdater , BrowserWindow , dialog , Menu } from "electron" ; import { TrayMenu } from "./main/TrayMenu" ; import { MenuBar } from "./main/MenuBar" ; import { getIconsPath } from "./utils" ; import "./ipc/main" ; declare const MAIN_WINDOW_WEBPACK_ENTRY ; require ( "update-electron-app" ) ( ) ; if ( require ( "electron-squirrel-startup" ) ) { app . quit ( ) ; } const isDevelopement = ( process . env . NODE_ENV !== "production" ) ; const createWindow = ( ) : void => { const gotTheLock = app . requestSingleInstanceLock ( ) ; if ( ! gotTheLock ) { app . quit ( ) ; return ; } const mainWindow = new BrowserWindow ( { height : 850 , width : 1200 , minHeight : 600 , minWidth : 800 , webPreferences : { contextIsolation : false , nodeIntegration : true , } , icon : getIconsPath ( "icon.png" , isDevelopement ) , } ) ; mainWindow . loadURL ( MAIN_WINDOW_WEBPACK_ENTRY ) ; if ( isDevelopement ) { mainWindow . webContents . openDevTools ( ) ; } const trayMenu = new TrayMenu ( mainWindow , isDevelopement ) ; const menuBar = new MenuBar ( mainWindow , trayMenu ) ; const template = menuBar . generateTemplate ( ) ; const menu = Menu . buildFromTemplate ( template ) ; Menu . setApplicationMenu ( menu ) ; } ; app . on ( "ready" , createWindow ) ; app . on ( "window-all-closed" , ( ) => { if ( process . platform !== "darwin" ) { app . quit ( ) ; } } ) ; app . on ( "activate" , ( ) => { if ( BrowserWindow . getAllWindows ( ) . length === 0 ) { createWindow ( ) ; } } ) ; app . on ( "second-instance" , ( event , commandLine , workingDirectory ) => { const mainWindow = BrowserWindow . getAllWindows ( ) [ 0 ] ; if ( mainWindow ) { if ( mainWindow . isMinimized ( ) ) { mainWindow . restore ( ) ; } mainWindow . show ( ) ; } } ) ; autoUpdater . on ( "update-downloaded" , ( event , releaseNotes , releaseName ) => { const dialogOpts = { type : "info" , buttons : [ "Update" , "Later" ] , title : "Application Update" , message : process . platform === "win32" ? releaseNotes : releaseName , detail : "A new version has been downloaded. Restart the application to apply the updates." } ; dialog . showMessageBox ( dialogOpts ) . then ( ( returnValue ) => { if ( returnValue . response === 0 ) { autoUpdater . quitAndInstall ( ) ; } } ) ; } ) ;