小编Apa*_*hah的帖子

Windows 中自定义协议的 Electron app.on("open-url") 替代方案

我正在 Electron 中开发一个应用程序,我需要处理这个应用程序内的自定义协议。
我正在用app.setAsDefaultProtocolClient(PROTOCOL)这个。

我在 macOS 上使用“ open-url ”来通过我的自定义协议处理 URL,它运行顺利,但我无法在 Windows 上弄清楚它。我正在 URL 中发送一些数据,因此仅打开窗口是行不通的。

我检查了这个答案,但这是在 2016 年回答的,并且该方法makeSingleInstance现已弃用。在文档中,它建议使用requestSingleInstanceLock,但它不接受任何回调或返回 URL。

那么如何在 macOS 和 Windows 中启用相同的功能呢?


代码

索引.js

app.on('ready', () => createWindow(`file://${__dirname}/views/welcome.html`));

app.on('activate', () => {
  // eslint-disable-next-line no-shadow,global-require
  const { mainWindow } = require('./utils/createWindow');
  // On OS X it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === …
Run Code Online (Sandbox Code Playgroud)

javascript windows electron

4
推荐指数
1
解决办法
5471
查看次数

标签 统计

electron ×1

javascript ×1

windows ×1