2021-12-13 08:40:18 +00:00
const path = require ( 'path' ) ;
const windowsUtils = require ( '../utils/windowsUtils' ) ;
const retainAsar = require ( './retainAsar' ) ;
const appSettings = require ( '../appSettings' ) ;
const settings = appSettings . getSettings ( ) ;
2021-12-13 09:38:32 +00:00
const appName = path . basename ( process . execPath , '.exe' ) ;
2021-12-13 08:40:18 +00:00
const fullExeName = path . basename ( process . execPath ) ;
const updatePath = path . join ( path . dirname ( process . execPath ) , '..' , 'Update.exe' ) ;
2022-01-29 10:23:41 +00:00
const queuePrefix = [ 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run' , '/v' , appName ] ;
2021-12-13 08:40:18 +00:00
exports . install = ( callback ) => {
2021-12-13 18:59:56 +00:00
log ( 'AutoStart' , 'Install' ) ;
2022-01-29 10:23:41 +00:00
const execPath = ` ${ updatePath } --processStart ${ fullExeName } ` + ( settings . get ( 'START_MINIMIZED' , false ) ? ' --process-start-args --start-minimized' : '' ) ; // Add Electron args if start minimized on
windowsUtils . addToRegistry ( [ [ ... queuePrefix , '/d' , execPath ] ] , callback ) ; // Make reg
2021-12-13 08:40:18 +00:00
} ;
exports . update = ( callback ) => {
2021-12-13 18:59:56 +00:00
log ( 'AutoStart' , 'Update' ) ;
2022-01-29 10:23:41 +00:00
exports . isInstalled ( installed => installed ? exports . install ( callback ) : callback ( ) ) ; // Reinstall if installed, else just callback
2021-12-13 08:40:18 +00:00
retainAsar ( ) ; // Retain OpenAsar
} ;
exports . uninstall = ( callback ) => {
2021-12-13 18:59:56 +00:00
log ( 'AutoStart' , 'Uninstall' ) ;
2022-01-29 10:23:41 +00:00
windowsUtils . spawnReg ( [ 'delete' , ... queuePrefix , '/f' ] , ( _error , _stdout ) => callback ( ) ) ; // Delete reg
2021-12-13 08:40:18 +00:00
} ;
2022-01-29 10:23:41 +00:00
exports . isInstalled = ( callback ) => windowsUtils . spawnReg ( [ 'query' , ... queuePrefix ] , ( _error , stdout ) => callback ( stdout . includes ( appName ) ) ) ; // Check reg