需求 通过网页 a标签中的href 如 myapp://startapp/xxxxx或者 myapp://xxxxx调起electron 并拿到 xxxxx 参数。
eletron main/index.js
let args = [];
// 加一个 `--` 以确保后面的参数不被 Electron 处理
args.push('--');
app.setAsDefaultProtocolClient(PROTOCOL, args);
handleArgv(args);
function handleArgv(argv) {
handleUrl(argv);
}
function handleUrl(urlStr) {
const storage = require('electron-localstorage');
console.log(urlStr)
storage.removeItem("name");
storage.setItem("name", JSON.stringify(urlStr))
}
在 handleArgv的方法中 我也尝试过使用 process.argv去获取protocol协议,但是都无法拿到。
这是注册表
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\myapp]
@="URL:myapp Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\myapp\DefaultIcon]
@="C:\\Users\\Administrator\\Desktop\\HWCloudLinkDemo\\Code\\build\\HW CloudLink-win32-ia32\\HW CloudLink.exe"
[HKEY_CLASSES_ROOT\myapp\shell]
[HKEY_CLASSES_ROOT\myapp\shell\open]
[HKEY_CLASSES_ROOT\myapp\shell\open\command]
@="C:\\Users\\Administrator\\Desktop\\HWCloudLinkDemo\\Code\\build\\HW CloudLink-win32-ia32\\HW CloudLink.exe \"%1\""
请问我该如何写才能拿到 protocol 中的参数呢?感激不尽