@@ -19,6 +19,7 @@ import path from 'path'
1919import i18next from 'i18next'
2020import Backend from 'i18next-fs-backend'
2121import { uniq } from 'lodash'
22+ import { Registry } from 'rage-edit' ;
2223
2324
2425//get app parameter
@@ -41,9 +42,11 @@ function startup() {
4142 } else {
4243
4344 //I set the app to open at operating system startup
44- app . setLoginItemSettings ( {
45- openAtLogin : true
46- } )
45+ if ( process . env . node_env !== 'development' ) {
46+ app . setLoginItemSettings ( {
47+ openAtLogin : true
48+ } )
49+ }
4750
4851 ///LOGGER
4952 startLogger ( )
@@ -183,7 +186,7 @@ function attachOnReadyProcess() {
183186 SplashScreenController . instance . window . addOnBuildListener ( ( ) => {
184187 setTimeout ( startApp , 2500 )
185188 } )
186- attachProtocolListeners ( )
189+ await attachProtocolListeners ( )
187190
188191 app . on ( 'activate' , ( e , isWindowOpen ) => {
189192 log ( 'ACTIVATE WINDOW' , e , isWindowOpen )
@@ -283,25 +286,69 @@ function attachOnReadyProcess() {
283286 } )
284287}
285288
289+ async function registryProtocol ( protocol : string ) {
290+ const AppName = app . getName ( ) ;
291+
292+ await Registry . set ( `HKCU\\Software\\${ AppName } \\Capabilities` , 'ApplicationName' , AppName ) ;
293+ await Registry . set ( `HKCU\\Software\\${ AppName } \\Capabilities` , 'ApplicationDescription' , AppName ) ;
294+
295+ await Registry . set ( `HKCU\\Software\\${ AppName } \\Capabilities\\URLAssociations` , protocol , `${ AppName } .${ protocol } ` ) ;
296+
297+ await Registry . set ( `HKCU\\Software\\Classes\\${ AppName } .${ protocol } \\DefaultIcon` , '' , process . execPath ) ;
298+
299+ await Registry . set ( `HKCU\\Software\\Classes\\${ AppName } .${ protocol } \\shell\\open\\command` , '' , `"${ process . execPath } " "%1"` ) ;
300+
301+ await Registry . set ( `HKCU\\Software\\RegisteredApplications` , AppName , `Software\\${ AppName } \\Capabilities` ) ;
302+
303+ }
304+
305+ async function removeRegistryProtocol ( protocol : string ) {
306+ const AppName = app . getName ( ) ;
286307
287- function attachProtocolListeners ( ) {
288- // remove so we can register each time as we run the app.
289- app . removeAsDefaultProtocolClient ( 'tel' )
290- app . removeAsDefaultProtocolClient ( 'callto' )
291- app . removeAsDefaultProtocolClient ( 'nethlink' )
308+ await Registry . delete ( `HKCU\\Software\\${ AppName } ` ) ;
309+
310+ await Registry . delete ( `HKCU\\Software\\Classes\\${ AppName } .${ protocol } ` ) ;
311+
312+ await Registry . delete ( `HKCU\\Software\\RegisteredApplications` , AppName ) ;
313+
314+ }
315+
316+ async function attachProtocolListeners ( ) {
317+ if ( process . env . node_env === 'development' ) {
318+ // remove so we can register each time as we run the app.
319+ if ( process . platform === 'win32' ) {
320+ await removeRegistryProtocol ( 'tel' )
321+ await removeRegistryProtocol ( 'callto' )
322+ await removeRegistryProtocol ( 'nethlink' )
323+ } else {
324+ app . removeAsDefaultProtocolClient ( 'tel' )
325+ app . removeAsDefaultProtocolClient ( 'callto' )
326+ app . removeAsDefaultProtocolClient ( 'nethlink' )
327+
328+ }
329+ }
330+ if ( process . platform === 'win32' ) {
331+ await registryProtocol ( 'tel' )
332+ await registryProtocol ( 'callto' )
333+ await registryProtocol ( 'nethlink' )
334+ }
292335
293336 // if we are running a non-packaged version of the app && on windows
294- if ( process . env . node_env === 'development' && process . platform === 'win32' ) {
337+ const res : { [ protocol : string ] : boolean } = { }
338+ if ( process . env . node_env === 'development' && process . argv . length > 2 ) {
339+ log ( process . argv . join ( '; ' ) )
295340 // set the path of electron.exe and your app.
296341 // these two additional parameters are only available on windows.
297- app . setAsDefaultProtocolClient ( 'tel' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
298- app . setAsDefaultProtocolClient ( 'callto' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
299- app . setAsDefaultProtocolClient ( 'nethlink' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
342+ res [ 'tel' ] = app . setAsDefaultProtocolClient ( 'tel' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
343+ res [ 'callto' ] = app . setAsDefaultProtocolClient ( 'callto' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
344+ res [ 'nethlink' ] = app . setAsDefaultProtocolClient ( 'nethlink' , process . execPath , [ resolve ( process . argv [ 1 ] ) ] )
300345 } else {
301- app . setAsDefaultProtocolClient ( 'tel' )
302- app . setAsDefaultProtocolClient ( 'callto' )
303- app . setAsDefaultProtocolClient ( 'nethlink' )
346+ res [ 'tel' ] = app . setAsDefaultProtocolClient ( 'tel' )
347+ res [ 'callto' ] = app . setAsDefaultProtocolClient ( 'callto' )
348+ res [ 'nethlink' ] = app . setAsDefaultProtocolClient ( 'nethlink' )
349+
304350 }
351+ log ( 'associated protocols:' , res )
305352
306353 app . on ( 'second-instance' , ( event , commandLine , workingDirectory , additionalData ) => {
307354 // Print out data received from the second instance.
0 commit comments