windowsmacoselectronelectron-builder

How to register electron app for 'tel' protocol at the time of installation?


At the time of installation, I want my app to get registered for handling the 'tel' protocol. My application should be listed in the supported applications

  1. I tried adding following key under electron builder config. under 'win' key and at high level too. protocols: [ { name: 'tel', schemes: ['tel'], }],

  2. I can run the post install script but did not find the parameter to which we can assign the post install script path in electron builder config.

  1. Updated info.plist, added following information

    CFBundleURLTypes CFBundleURLName tel CFBundleURLSchemes tel

On windows, when I try Win+R -> // It does not list my application in the list.

On MAC too, its not working.


Solution

    1. For MAC , we need to add following key in electron builder configs / in package.json if you have defined build object in it. Add this key at high level, not under 'mac'.

      protocols: [ { name: 'app-name', schemes: ['tel'], }, ]

    2. For Windows , we need to make changes in windows registry. I didn't find any existing parameter available for builder config for this. I am using 'nsis' for windows where we can write our own custom script. I just wanted to make registry changes on install and revert on uninstall so I went with 'include' option. Find details here: https://www.electron.build/nsis.html#custom-nsis-script

    To make changes in windows registry, we need admin privileges. To allow nsis to ak for permission , we need to add following line in builder config under nsis key

    allowElevation:true
    

    Now we need to write .nsh file which will be included. Under nsis key we will include our .nsh file

    include:'/installer.nsh'
    

    Under installer.nsh we will have following code

    RequestExecutionLevel admin  # Request admin privileges
    !define APP_NAME "app-name"
    !define APP_PATH "$INSTDIR\${APP_NAME}.exe"
    !macro customInstall
      WriteRegStr HKCU "Software\${APP_NAME}\\Capabilities" "ApplicationName" "${APP_NAME}"
      WriteRegStr HKCU "Software\${APP_NAME}\\Capabilities" "ApplicationDescription" "${APP_NAME}"
      WriteRegStr HKCU "Software\${APP_NAME}\\Capabilities\\URLAssociations" "tel" "${APP_NAME}.tel"
      WriteRegStr HKCU "Software\RegisteredApplications" "${APP_NAME}" "Software\${APP_NAME}\Capabilities"
      WriteRegStr HKCU "Software\\Classes\\${APP_NAME}.tel\\DefaultIcon" "" "${APP_PATH}"
      WriteRegStr HKCU "Software\\Classes\\${APP_NAME}.tel\\shell\\open\\command" "" "${APP_PATH} %1"
    !macroend
    !macro customUnInstall
      DeleteRegKey HKCU "Software\${APP_NAME}"
      DeleteRegKey HKCU "Software\\Classes\\${APP_NAME}.tel"
      DeleteRegValue HKCU "Software\RegisteredApplications" "${APP_NAME}"
    !macroend
    

    This will register your application for tel protocol on install and revert the registry changes on uninstall.