gpt4 book ai didi

javascript - 处理 "ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed"(Electron 7.0)

转载 作者:行者123 更新时间:2023-11-30 19:10:41 26 4
gpt4 key购买 nike

升级到 Electron 7.0 后,我注意到这条弃用消息:

(node:8308) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.

有问题的代码是:

  await new Promise((resolve, reject) => {
electron.protocol.registerBufferProtocol(MY_PROTOCOL,
(request, callback) => {
const uri = request.url;
if (uri) {
callback({ mimeType: 'text/plain', data: Buffer.from(uri) });
}
else {
callback({ error: -324 }); // EMPTY_RESPONSE
}
},
error => error? reject(error): resolve()
);
});

从 Electron 7 开始,现在调用 registerBufferProtocol 的正确方法是什么?

最佳答案

我花了很长时间才弄清楚如何使用 Electron 7.0 正确调用 registerBufferProtocol,因此与社区和我 future 的自己分享。

根据 Electron 的 Breaking changes文档,registerBufferProtocol 现在是同步的,所以调用它实际上变得更简单了:

  electron.protocol.registerBufferProtocol(MY_PROTOCOL,
(request, callback) => {
const uri = request.url;
if (uri) {
callback({ mimeType: 'text/plain', data: Buffer.from(uri) });
}
else {
callback({ error: -324 }); // EMPTY_RESPONSE
}
});

警告中(对我而言)令人困惑的部分是 callback 实际上不是 handler 的 callback arg ,而是传递给 protocol.registerBufferProtocol 的最后一个 completion arg API 本身。

关于javascript - 处理 "ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed"(Electron 7.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58513608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com