diff --git a/package-lock.json b/package-lock.json index 611fa729..548ff858 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "path-browserify": "^1.0.1", "postcss": "^8.4.35", "prettier": "^3.2.4", + "rage-edit": "^1.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.50.1", @@ -20607,6 +20608,13 @@ "performance-now": "^2.1.0" } }, + "node_modules/rage-edit": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/rage-edit/-/rage-edit-1.2.0.tgz", + "integrity": "sha512-0RspBRc2s6We4g7hRCvT5mu7YPEnfjvQK8Tt354a2uUNJCMC7MKLvo/1mLvHUCQ/zbP6siQyp5VRZN7UCpMFZg==", + "dev": true, + "license": "MIT" + }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", diff --git a/package.json b/package.json index c8e47b5c..81c63377 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,8 @@ "@electron-toolkit/tsconfig": "^1.0.1", "@electron-toolkit/utils": "^3.0.0", "@fortawesome/fontawesome-svg-core": "^6.5.1", - "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/free-regular-svg-icons": "^6.5.1", + "@fortawesome/free-solid-svg-icons": "^6.5.1", "@fortawesome/react-fontawesome": "^0.2.0", "@headlessui/react": "^1.7.18", "@hookform/resolvers": "^3.3.4", @@ -79,6 +79,7 @@ "path-browserify": "^1.0.1", "postcss": "^8.4.35", "prettier": "^3.2.4", + "rage-edit": "^1.2.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.50.1", diff --git a/src/main/main.ts b/src/main/main.ts index b2add5a3..d1bc0c03 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -19,6 +19,7 @@ import path from 'path' import i18next from 'i18next' import Backend from 'i18next-fs-backend' import { uniq } from 'lodash' +import { Registry } from 'rage-edit'; //get app parameter @@ -41,9 +42,11 @@ function startup() { } else { //I set the app to open at operating system startup - app.setLoginItemSettings({ - openAtLogin: true - }) + if (process.env.node_env !== 'development') { + app.setLoginItemSettings({ + openAtLogin: true + }) + } ///LOGGER startLogger() @@ -183,7 +186,7 @@ function attachOnReadyProcess() { SplashScreenController.instance.window.addOnBuildListener(() => { setTimeout(startApp, 2500) }) - attachProtocolListeners() + await attachProtocolListeners() app.on('activate', (e, isWindowOpen) => { log('ACTIVATE WINDOW', e, isWindowOpen) @@ -283,25 +286,69 @@ function attachOnReadyProcess() { }) } +async function registryProtocol(protocol: string) { + const AppName = app.getName(); + + await Registry.set(`HKCU\\Software\\${AppName}\\Capabilities`, 'ApplicationName', AppName); + await Registry.set(`HKCU\\Software\\${AppName}\\Capabilities`, 'ApplicationDescription', AppName); + + await Registry.set(`HKCU\\Software\\${AppName}\\Capabilities\\URLAssociations`, protocol, `${AppName}.${protocol}`); + + await Registry.set(`HKCU\\Software\\Classes\\${AppName}.${protocol}\\DefaultIcon`, '', process.execPath); + + await Registry.set(`HKCU\\Software\\Classes\\${AppName}.${protocol}\\shell\\open\\command`, '', `"${process.execPath}" "%1"`); + + await Registry.set(`HKCU\\Software\\RegisteredApplications`, AppName, `Software\\${AppName}\\Capabilities`); + +} + +async function removeRegistryProtocol(protocol: string) { + const AppName = app.getName(); -function attachProtocolListeners() { - // remove so we can register each time as we run the app. - app.removeAsDefaultProtocolClient('tel') - app.removeAsDefaultProtocolClient('callto') - app.removeAsDefaultProtocolClient('nethlink') + await Registry.delete(`HKCU\\Software\\${AppName}`); + + await Registry.delete(`HKCU\\Software\\Classes\\${AppName}.${protocol}`); + + await Registry.delete(`HKCU\\Software\\RegisteredApplications`, AppName); + +} + +async function attachProtocolListeners() { + if (process.env.node_env === 'development') { + // remove so we can register each time as we run the app. + if (process.platform === 'win32') { + await removeRegistryProtocol('tel') + await removeRegistryProtocol('callto') + await removeRegistryProtocol('nethlink') + } else { + app.removeAsDefaultProtocolClient('tel') + app.removeAsDefaultProtocolClient('callto') + app.removeAsDefaultProtocolClient('nethlink') + + } + } + if (process.platform === 'win32') { + await registryProtocol('tel') + await registryProtocol('callto') + await registryProtocol('nethlink') + } // if we are running a non-packaged version of the app && on windows - if (process.env.node_env === 'development' && process.platform === 'win32') { + const res: { [protocol: string]: boolean } = {} + if (process.env.node_env === 'development' && process.argv.length > 2) { + log(process.argv.join('; ')) // set the path of electron.exe and your app. // these two additional parameters are only available on windows. - app.setAsDefaultProtocolClient('tel', process.execPath, [resolve(process.argv[1])]) - app.setAsDefaultProtocolClient('callto', process.execPath, [resolve(process.argv[1])]) - app.setAsDefaultProtocolClient('nethlink', process.execPath, [resolve(process.argv[1])]) + res['tel'] = app.setAsDefaultProtocolClient('tel', process.execPath, [resolve(process.argv[1])]) + res['callto'] = app.setAsDefaultProtocolClient('callto', process.execPath, [resolve(process.argv[1])]) + res['nethlink'] = app.setAsDefaultProtocolClient('nethlink', process.execPath, [resolve(process.argv[1])]) } else { - app.setAsDefaultProtocolClient('tel') - app.setAsDefaultProtocolClient('callto') - app.setAsDefaultProtocolClient('nethlink') + res['tel'] = app.setAsDefaultProtocolClient('tel') + res['callto'] = app.setAsDefaultProtocolClient('callto') + res['nethlink'] = app.setAsDefaultProtocolClient('nethlink') + } + log('associated protocols:', res) app.on('second-instance', (event, commandLine, workingDirectory, additionalData) => { // Print out data received from the second instance.