其他分享
首页 > 其他分享> > 【Electron】electron-builder 打包nsis时,设置URL Protocol

【Electron】electron-builder 打包nsis时,设置URL Protocol

作者:互联网

问题

electron-builder使用nsis打包,安装时不会设置URL Protocol。

解决方法

自定义nsis 脚本

electron-builder 可以自定义打包脚本
https://www.electron.build/configuration/nsis#custom-nsis-script

脚本

!define SCHEMENAME "app" #修改为你自定义的URL Protocol

!macro customInstall
  DetailPrint "Register ${SCHEMENAME} URI Handler"
  DeleteRegKey HKCR "${SCHEMENAME}"
  WriteRegStr HKCR "${SCHEMENAME}" "" "${PRODUCT_NAME}"
  WriteRegStr HKCR "${SCHEMENAME}" "URL Protocol" ""
  WriteRegStr HKCR "${SCHEMENAME}\DefaultIcon" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME}"
  WriteRegStr HKCR "${SCHEMENAME}\shell" "" ""
  WriteRegStr HKCR "${SCHEMENAME}\shell\Open" "" ""
  WriteRegStr HKCR "${SCHEMENAME}\shell\Open\command" "" "$INSTDIR\${APP_EXECUTABLE_FILENAME} %1"
!macroend

!macro customUnInstall 
  DeleteRegKey HKCR "${SCHEMENAME}"
  ReadRegStr $0 HKCR "${SCHEMENAME}" ""
  DeleteRegKey HKCR "$0"
!macroend

标签:Protocol,URL,builder,nsis,electron,WriteRegStr,SCHEMENAME,HKCR
来源: https://www.cnblogs.com/gaoshang212/p/15843656.html