/**
 * This module is responsible on handling all the setup events that is submitted by squirrel.
 */ import { app } from 'electron' ; import { spawn } from 'child_process' ; import { resolve , join , basename } from 'path' ; import { environment } from '../../environments/environment' ; export default class SquirrelEvents { private static isAppFirstRun = false ; private static appFolder = resolve ( process . execPath , '..' ) ; private static appRootFolder = resolve ( SquirrelEvents . appFolder , '..' ) ; private static updateExe = resolve ( join ( SquirrelEvents . appRootFolder , 'Update.exe' ) ) ; private static exeName = resolve ( join ( SquirrelEvents . appRootFolder , 'app-' + environment . version , basename ( process . execPath ) ) ) ; static handleEvents ( ) { if ( process . argv . length === 1 || process . platform !== 'win32' ) { return false ; } switch ( process . argv [ 1 ] ) { case '--squirrel-install' : case '--squirrel-updated' : SquirrelEvents . update ( [ '--createShortcut' , SquirrelEvents . exeName ] ) ; return true ; case '--squirrel-uninstall' : SquirrelEvents . update ( [ '--removeShortcut' , SquirrelEvents . exeName ] ) ; return true ; case '--squirrel-obsolete' : app . quit ( ) ; return true ; case '--squirrel-firstrun' : SquirrelEvents . isAppFirstRun = true ; return false ; } return false ; } static isFirstRun ( ) { return SquirrelEvents . isAppFirstRun ; } private static update ( args ) { try { spawn ( SquirrelEvents . updateExe , args , { detached : true } ) . on ( 'close' , ( ) => setTimeout ( app . quit , 1000 ) ) ; } catch ( error ) { setTimeout ( app . quit , 1000 ) ; } } }