Skip to content

PRO-2684/protocio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚚 Protocio

LiteLoaderQQNT 插件,用于注册自定义协议,然后将链接交付给对应插件处理。

🪄 具体功能

  • 协议注册:注册 llqqnt:// 协议,当在浏览器中点击这种链接时,便会唤起 QQ
  • 链接交付:此插件得知 llqqnt://<slug>/... 链接被点击时,会派发类型 slug 的自定义事件,插件只需监听即可。
  • 内置处理器:此插件亦注册了一个 URL 处理器,用于处理 llqqnt://protocio/ 链接
    • ping:在控制台输出 pong,用于测试
    • quit/<second>:在指定秒数后退出 QQNT,未指定或小于等于 0 则立即退出 (e.g. llqqnt://protocio/quit/5)
    • restart/<second>:在指定秒数后重启 QQNT,未指定或小于等于 0 则立即重启 (e.g. llqqnt://protocio/restart/5)
    • list:列出所有已注册的 URL 处理器
    • 其它:其它命令会在控制台输出 Unknown command: <command>,用于调试 (e.g. llqqnt://protocio/bad-command)

📥 安装

自动安装

插件安装器插件列表查看 中找到 Protocio 并安装。

手动安装

  • 稳定版: 下载 Release 中的 protocio-release.zip,解压后放入数据目录下的 plugins/protocio 文件夹中即可。(若没有该文件夹请自行创建)
  • CI 版: 若想体验最新的 CI 功能,可以下载源码后同上安装。(仅需下载下面列出的文件)

完成后的目录结构应该如下:

plugins (所有的插件目录)
└── protocio (此插件目录)
    ├── manifest.json (插件元数据)
    ├── main.js (插件脚本)
    └── icons/ (插件用到的图标)

🤔 使用方法

事件侦听器

在您的插件主进程中,在 app.whenReady 后通过 LiteLoader.api.protocio.addEventListener 注册事件侦听器,通过 LiteLoader.api.protocio.removeEventListener 注销事件侦听器,其接口定义与 EventTarget 标准 一致。其中 type 参数建议设置为插件的 slug 以避免混淆和冲突,虽然这并不是强制的。

自定义事件

派发的事件为 CustomEvent,其 type 属性即为网址路径的第一部分。其 detail 属性包含:

  • args: URL 剩余部分的数组,空值被过滤。
  • url: 完整的 URL。

通常只需要使用其中的 args

例如对于网址 llqqnt://protocio/whatever,则:

  • type: protocio
  • args: ["whatever"]
  • url: llqqnt://protocio/whatever

范例

const { app } = require("electron");
app.whenReady().then(() => {
    LiteLoader.api.protocio.addEventListener("<slug>", e => {
        const { args, url } = e.detail;
        doSomething(args, url); // 处理...
    });
});
旧版 API 与兼容性

[!WARNING] 仅为了保证兼容性,后续可能会移除。

  • LiteLoader.api.registerUrlHandler(slug, handler, force) => { success, message }
    • handler: (args, url) => <any>
    • force 参数被忽略,允许添加多个 handler
  • LiteLoader.api.registerUrlHandler(slug, ignore) => { success, message }
    • 不再有实际效果,success 总是返回 false

⚠️ 注意事项

  • 关于多个 QQNT 实例的兼容性:此插件 允许运行多个 QQNT 实例,但是 只有第一个实例 会响应 llqqnt:// 链接。

💻 调试

Debug 模式:若您想要调试 此插件本身,可以使用 --protocio-debug 参数启动 QQNT,此时插件会在控制台输出更详细的调试信息。

⭐ Star History

Stargazers over time

About

Register custom protocol and deliver the link to corresponding plugin to handle it

Topics

Resources

Stars

Watchers

Forks