import { ipcMain , app , Tray , BrowserWindow , screen , dialog } from 'electron' ; import * as fs from 'fs' ; const isLocal = require ( 'electron-is-dev' ) ; const transparencyDisabled = fs . existsSync ( `${ app . getPath ( 'userData' ) }/NO_TRANSPARENCY` ) ; const autoUpdater = require ( 'electron-updater' ) . autoUpdater ; autoUpdater . requestHeaders = { 'Cache-Control' : 'no-cache' } ; require ( 'electron-debug' ) ( { enabled : true } ) ; import * as path from 'path' ; import * as url from 'url' ; import { Ipc , ElmIpc } from './ipc' ; const log = require ( 'electron-log' ) ; const assetsDirectory = path . join ( __dirname , 'assets' ) ; const { version } = require ( './package.json' ) ; log . info ( `Running version ${ version }` ) ; let checkForUpdates = true ; let mainWindow ; function createMainWindow ( ) { mainWindow = new BrowserWindow ( { width : 800 , height : 600 } ) ; let isDevEnv = process . env . NODE_ENV === 'dev' ; let prodUrl = url . format ( { pathname : path . join ( __dirname , 'src/renderer/index.html' ) , protocol : 'file:' } ) ; let devUrl = url . format ( { hostname : 'localhost' , pathname : path . join ( 'src/renderer/index.html' ) , port : '8080' , protocol : 'http' , slashes : true } ) ; mainWindow . loadURL ( isDevEnv ? devUrl : prodUrl ) ; } const focusMainWindow = ( ) => { if ( mainWindow ) { mainWindow . focus ( ) ; } } ; const shouldQuit = app . makeSingleInstance ( ( commandLine , workingDirectory ) => { focusMainWindow ( ) ; } ) ; if ( shouldQuit ) { app . quit ( ) ; } const onMac = /^darwin/ . test ( process . platform ) ; const onWindows = /^win/ . test ( process . platform ) ; function onReady ( ) { createMainWindow ( ) ; setupAutoUpdater ( ) ; Ipc . setupIpcMessageHandler ( ( ipc ) => { if ( ipc . message === 'Quit' ) { app . quit ( ) ; } else if ( ipc . message === 'GreetingDialog' ) { dialog . showMessageBox ( mainWindow , { message : 'Hello!' } ) ; } else { const _exhaustiveCheck = ipc ; } } ) ; } app . on ( 'ready' , onReady ) ; app . on ( 'window-all-closed' , function ( ) { if ( process . platform !== 'darwin' ) { app . quit ( ) ; } } ) ; app . on ( 'activate' , function ( ) { if ( mainWindow ) { mainWindow . show ( ) ; } } ) ; const setupAutoUpdater = ( ) => { autoUpdater . logger = log ; autoUpdater . on ( 'checking-for-update' , ( ) => { log . info ( 'checking-for-update' ) ; } ) ; autoUpdater . on ( 'error' , ( ev , err ) => { log . info ( 'error checking for updates' ) ; checkForUpdates = true ; } ) ; autoUpdater . on ( 'update-available' , ( ) => { log . info ( 'update-available' ) ; checkForUpdates = false ; } ) ; autoUpdater . on ( 'update-downloaded' , ( versionInfo ) => { log . info ( 'update-downloaded: ' , versionInfo ) ; } ) ; autoUpdater . on ( 'update-not-available' , ( ) => { log . info ( 'update-not-available' ) ; } ) ; if ( ! isLocal ) { autoUpdater . checkForUpdates ( ) ; let myCheckForUpdates = ( ) => { if ( checkForUpdates ) { autoUpdater . checkForUpdates ( ) ; } } ; const updateIntervalSeconds = 120 ; setInterval ( myCheckForUpdates , updateIntervalSeconds * 1000 ) ; } } ;