I'm trying to build my application for OSX and for Windows. Right now my package.json looks like below:
"build": {
"appId": "",
"app-category-type": "",
"dmg": {},
"win": {
"iconUrl": ""
},
"protocols": [
{
"name": "App name",
"schemes": ["myapp"]
}
]
}
So everything working for OSX and I can open application using myapp:// scheme. How can I make the same for Windows?
Squirrel.Windows: do it on some squirrel event --squirrel-install/--squirrel-updated
NSIS: will be implemented soon, workaround: #583
Very interested in this too :)
I followed the instructions in https://github.com/electron-userland/electron-builder/issues/583 but it isn't working for me. I have installer.nsh in the build/ directory, and I know it is reading it because I had a typo in a variable name and the build failed. When I fixed the typo, the build succeeded.
Here is my installer.nsh:
!macro customInstall
DetailPrint "Register __scheme__ URI Handler"
DeleteRegKey HKCR "__scheme__"
WriteRegStr HKCR "__scheme__" "" "URL:__scheme__"
WriteRegStr HKCR "__scheme__" "URL Protocol" ""
WriteRegStr HKCR "__scheme__\DefaultIcon" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
WriteRegStr HKCR "__scheme__\shell" "" ""
WriteRegStr HKCR "__scheme__\shell\Open" "" ""
WriteRegStr HKCR "__scheme__\shell\Open\command" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME} %1"
!macroend
(replace __scheme__ with myapp or whatever, obviously)
But when I run the installer, I'm not seeing any of these registry keys get created.
Is there another step I'm missing? Is there any way for me to see the actual configuration file being passed to nsis, so I can diagnose what's wrong?
I did have this working in a previous version of electron-builder (back when you used to have to run packager manually), by passing the entire NSIS template file. But I'd like to avoid doing that if I can, for obvious reasons.
I figured out my problem. I didn't set the installer to perMachine: true, so it was installing for a single user, and apparently the registry keys don't work in that case.
apparently
Docs is not yet updated because I am not sure. If anyone can confirm and fix docs — please PR.
Moved to backlog to keep issue list clear.
@Joshua-Smith
hey, first thx for your comments,
can you tell me if I have to replace $INSTDIR and ${APP_EXECUTABLE_FILENAME} by something or if this is already defined?
When you et perMachine: true this is on the package.json file under build.nsis object right ?
Those two identifiers are already defined.
And yes, per machine goes into build.nsis object.
@Joshua-Smith : I set perMachine : true and nsh script still not writing register key after installation process !!
!macro customInstall
DetailPrint "Register test URI Handler"
DeleteRegKey HKCR "test"
WriteRegStr HKCR "test" "" "URL:test"
WriteRegStr HKCR "test" "URL Protocol" ""
WriteRegStr HKCR "test\shell" "" ""
WriteRegStr HKCR "test\shell\Open" "" ""
WriteRegStr HKCR "test\shell\Open\command" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME} %1"
!macroend
`{
"name": "electron app",
"productName": "electronapp",
"version": "0.1.0",
"author": "me",
"description": "electron app test",
"main": "main.js",
"devDependencies": {
"electron-builder": "^20.28.3",
"electron-packager": "^12.1.1",
"electron-winstaller": "^2.6.4",
"electron": "^1.8.8"
},
"build": {
"appId": "fr.digitalberry.berryagent",
"win": {
"target": "nsis",
"icon": "build/icon.ico"
}
},
"scripts": {
"start": "electron .",
"dist": "build",
"test": "echo "Error: no test specified" && exit 1",
},
"dependencies": {
},
"nsis": {
"oneClick" : false ,
"allowToChangeInstallationDirectory": true,
"include" : "build/script.nsh" ,
"perMachine" : true
}
}
`
@digitalberry-ahmed , have you figured it out? Moving from Electron 2 to 3, the custom protocol registration stopped working for me too, regardless of perMachine value. As a workaround for now, I'm gonna do it "manually" inside the app upon the first run.
yeah, i got the same problem.There is not much info about how to get Protocol (scheme) work for windows.
@woxixiulayin, for now I've solved it using this package: register-protocol-win32. A side benefit of doing it runtime is that it can be easily debugged.
@noseratio thanks for your reply.I just want to register protocol during app installing in windows.
I find the solution in this answer https://stackoverflow.com/questions/45809064/registering-custom-protocol-at-installation-process-in-electron-app
@develar this is quite easy to implement via the NSIS script. I'm using the following macro to make it work:
!macro AddProtocolHandler Protocol Description
DeleteRegKey SHELL_CONTEXT "Software\Classes\${Protocol}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}" "" "${Description}"
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}" "URL Protocol" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}\DefaultIcon" "" "$appExe,0"
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}\shell" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}\shell\open" "" ""
WriteRegStr SHELL_CONTEXT "Software\Classes\${Protocol}\shell\open\command" "" "$appExe %1"
!macroend
And then I just call it for each protocol. It could be done here for the protocols defined in the Build configuration.
@hacdias you have a couple of differences to what was suggested above. First you have SHELL_CONTEXT instead of HKCR, and "$appExe,0" instead of "$INSTDIR\${APP_EXECUTABLE_FILENAME}", and "$appExe %1" instead of "$INSTDIR${APP_EXECUTABLE_FILENAME} %1". I would love to know if this worked for you and why?
@dannyharding10
SHELL_CONTEXT picks between HKCU (current user) or HKCM (current machine) according to what the user decided during setup (machine or user installation)."$appExe,0" is the icon at index 0 of the application executable."$appExe %1" calls the app executable with the file as argument.The appExe variable is defined somewhere in the base NSIS script from electron-builder.
@hacdias good to know, thank you! I also noticed yours includes Software\Classes at the beginning of the paths, any reason for this? I tried using your setup as it seems preferable to me, but it did not work. When I switched to the way @Joshua-Smith has it above, it did work. Any insights? I assume that what you have is still working for you?
I have Software/Classes prepended because I don't add them to HKCR (current ROOT) but to HKCU (current user). See https://stackoverflow.com/questions/53984433/hkey-local-machine-software-classes-vs-hkey-classes-root.
Yes, it's still working here.
Most helpful comment
I figured out my problem. I didn't set the installer to
perMachine: true, so it was installing for a single user, and apparently the registry keys don't work in that case.