Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol (scheme) for windows #623

Closed
Feelnoobskill opened this issue Aug 1, 2016 · 18 comments
Closed

Protocol (scheme) for windows #623

Feelnoobskill opened this issue Aug 1, 2016 · 18 comments

Comments

@Feelnoobskill
Copy link

  • Version: 5.4.2
  • Target: Windows

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?

@develar
Copy link
Member

develar commented Aug 3, 2016

Squirrel.Windows: do it on some squirrel event --squirrel-install/--squirrel-updated

NSIS: will be implemented soon, workaround: #583

@Toflar
Copy link
Contributor

Toflar commented Aug 10, 2016

Very interested in this too :)

@ghost
Copy link

ghost commented Aug 25, 2016

I followed the instructions in #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.

@ghost ghost mentioned this issue Aug 29, 2016
@ghost
Copy link

ghost commented Aug 29, 2016

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.

@develar
Copy link
Member

develar commented Aug 30, 2016

apparently

Docs is not yet updated because I am not sure. If anyone can confirm and fix docs — please PR.

@develar develar changed the title How to set protocol for windows platform? Protocol (scheme) for windows Feb 8, 2017
@develar develar added the backlog label Feb 8, 2017
@develar
Copy link
Member

develar commented Feb 8, 2017

Moved to backlog to keep issue list clear.

@nicolasandrieux
Copy link

@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 ?

@ghost
Copy link

ghost commented Apr 11, 2017

Those two identifiers are already defined.

And yes, per machine goes into build.nsis object.

@electronABS
Copy link

electronABS commented Sep 3, 2018

@joshua-smith : I set perMachine : true and nsh script still not writing register key after installation process !!

installer.nsh

!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

package.json

`{
"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 
    
}

}
`

@noseratio
Copy link

@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.

@woxixiulayin
Copy link

yeah, i got the same problem.There is not much info about how to get Protocol (scheme) work for windows.

@noseratio
Copy link

@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.

@woxixiulayin
Copy link

@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

@hacdias
Copy link

hacdias commented Jan 29, 2019

@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.

@danny-does-stuff
Copy link

@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?

@hacdias
Copy link

hacdias commented Aug 14, 2019

@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.

@danny-does-stuff
Copy link

@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?

@hacdias
Copy link

hacdias commented Aug 14, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants