在电子应用程序的安装过程中注册自定义协议 [英] registering custom protocol at installation process in electron app

查看:10
本文介绍了在电子应用程序的安装过程中注册自定义协议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是电子新手,想知道如何在应用安装过程中为应用注册自定义协议.

Hi I am new to electron and was wondering how i can register a custom protocol for the app at the time of installation process of the app.

我正在使用 electron-builder 来构建应用程序.这是构建构建代码

I am using electron-builder for building the app. Here is the build build code

"build": {
"appId": "com.test.testapp",
"productName": "testapp",
"asar": true,
"protocols": [{
  "name": "testapp",
  "schemes": [ "testapp" ]
}],
"nsis": {
  "oneClick": false,
  "perMachine": true,
  "allowToChangeInstallationDirectory": true,
  "runAfterFinish": false,
  "createDesktopShortcut": true
},
"squirrelWindows": {
  "msi": true
},
"directories": {
  "output": "distribution"
}

我知道通过添加以下行来注册自定义协议

I know that by adding the below line registers the custom protocol

 app.setAsDefaultProtocolClient("testapp");

但只有在我至少第一次运行该应用程序时才会这样做.

but it only does if i run the app at least the first time.

我不希望安装后用户会启动应用程序.

Which i don't want there is no guarantee that the user will launch the app after installation.

那么有没有办法可以在安装过程中使用 electron-builder 注册自定义协议

So is there a way that i can register the custom protocol in the installation process using electron-builder

推荐答案

我还是 Electron 和 electron-builder 的新手,但已经为 NSIS-target 解决了这个问题.首先,据我所知,app.setAsDefaultProtocolClient 用于处理应用程序内部的自定义协议.您需要使用 electron-builder 本身注册此自定义协议.

I'm still new to Electron and electron-builder but solved this problem for NSIS-target already. First of all I should note that app.setAsDefaultProtocolClient used to handle custom protocols inside the application as far as I do understand. You need to register this custom protocol using electron-builder itself.

其次,我需要在 NSIS 和 squirrelWindows 之间进行选择.据我了解,NSIS 是更可取的,因为 Squirrel 的支持较少并且存在一些问题.同样,我不是专家,但我读过一些关于它的东西.所以 squirrelWindows 部分是多余的.您不指定 win.target,默认为 "nsis".

Secondly I need to choose between NSIS and squirrelWindows. NSIS is the preferable as long I understand because Squirrel is less supported and has some problems. Again I'm not an expert but I read something about it. So squirrelWindows section is redundant. You don't specify win.target and it is "nsis" by default.

NSIS 目标的自定义协议注册存在问题.您可以在此处阅读更多信息:Protocol (scheme) for windows 但有一种解决方法.您需要在 build 文件夹中创建一个名为 installer.nsh 的文件,其内容如下:

There is a problem with the custom protocol registration for NSIS target. You can read more here: Protocol (scheme) for windows but there is a workaround. You need to create a file named installer.nsh in your build folder with such a content:

!macro customInstallDetailPrint "注册 evehq-ng URI 处理程序"DeleteRegKey HKCR "evehq-ng"WriteRegStr HKCR "evehq-ng" "" "URL:evehq-ng"WriteRegStr HKCR "evehq-ng" "EveHQ NG SSO 认证协议" ""WriteRegStr HKCR "evehq-ngDefaultIcon" "" "$INSTDIR${APP_EXECUTABLE_FILENAME}"WriteRegStr HKCR "evehq-ngshell" "" ""WriteRegStr HKCR "evehq-ngshellOpen" "" ""WriteRegStr HKCR "evehq-ngshellOpencommand" "" "$INSTDIR${APP_EXECUTABLE_FILENAME} %1"!宏端

evehq-ng 替换为您的协议字符串,将 EveHQ NG SSO 身份验证协议 替换为您的协议描述.

Replace evehq-ng with your protocol string and EveHQ NG SSO authentication Protocol with your protocol description.

之后,您必须将 nsis.perMachine 设置为 true.

After that you have to set nsis.perMachine to true.

我还没有为 Linux 解决这个问题,但是朝着这个方向努力.你可以在我的概念证明项目中看到我的代码:EveHQ-NG 概念证明应用程序.

I haven't yet solved this problem for Linux but work in this direction. You can see my code in my proof of concepts project here: EveHQ-NG proof of concepts application.

如果你想为 Linux 和 MacOS 解决这个问题,请在此处或 GitHub 上给我留言.

If you will solve this problem for Linux and MacOS write me a message somehow here or on GitHub.

希望对你有帮助.

这篇关于在电子应用程序的安装过程中注册自定义协议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆