2022-04-12 16:56:55 +00:00
const { join , basename } = require ( 'path' ) ;
2021-12-13 08:40:18 +00:00
2022-04-30 11:06:27 +00:00
const reg = ( a , c ) => require ( 'child_process' ) . execFile ( 'reg.exe' , a , c ) ;
2021-12-13 08:40:18 +00:00
2022-03-11 12:52:16 +00:00
const appName = basename ( process . execPath , '.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
2022-04-29 22:15:34 +00:00
exports . install = ( cb ) => reg ( [ 'add' , ... queuePrefix , '/d' , join ( process . execPath , '..' , '..' , 'Update.exe' ) + ' --processStart ' + basename ( process . execPath ) + ( settings . get ( 'START_MINIMIZED' ) ? ' --process-start-args --start-minimized' : '' ) , '/f' ] , cb ) ; // Make reg (with Electron args if start min)
2022-04-12 16:56:55 +00:00
exports . update = ( cb ) => exports . isInstalled ( installed => installed ? exports . install ( cb ) : cb ( ) ) ; // Reinstall if installed, else just cb
2021-12-13 08:40:18 +00:00
2022-04-29 22:15:34 +00:00
exports . uninstall = ( cb ) => reg ( [ 'delete' , ... queuePrefix , '/f' ] , ( ) => cb ( ) ) ; // Delete reg
2021-12-13 08:40:18 +00:00
2022-04-29 22:15:34 +00:00
exports . isInstalled = ( cb ) => reg ( [ 'query' , ... queuePrefix ] , ( e , out ) => cb ( out . includes ( appName ) ) ) ; // Check reg