gpt4 book ai didi

Electron 回复错误: An object could not be cloned

转载 作者:行者123 更新时间:2023-12-02 18:21:23 24 4
gpt4 key购买 nike

我试图要求主应用程序找到某种设备,我一直在尝试使用 ipc 来做到这一点,但无法使其与异步发送和同步发送一起工作。我怀疑主要是在试图回复 promise 。

渲染器:

const recognizedDevices = ipcRenderer.sendSync('findDevice');
console.log(recognizedDevices);

主要:

ipcMain.on('findDevice', (event) => findDevice(event));
const findDevice = async (event) => {
let recognizedDevices = await findConnectedDevices();
if(recognizedDevices){
console.log("found");
console.log(recognizedDevices);
return event.returnValue = recognizedDevices;
}
//TODO: If no device found
}

主要结果:

    found
[
HID {
_events: [Object: null prototype] { newListener: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
_raw: HID {},
write: [Function: bound write],
getFeatureReport: [Function: bound getFeatureReport],
sendFeatureReport: [Function: bound sendFeatureReport],
setNonBlocking: [Function: bound setNonBlocking],
readSync: [Function: bound readSync],
readTimeout: [Function: bound readTimeout],
getDeviceInfo: [Function: bound getDeviceInfo],
_paused: true,
[Symbol(kCapture)]: false
}
]

我希望在渲染器中收到相同的日志结果,但不幸的是我得到了错误:无法克隆对象。

如果我尝试用 recognizeDevice.length 回复,我确实会在前端收到“1”,所以看起来它们之间的通信良好。看来问题出在发送对象上。

最佳答案

主进程和渲染进程之间通过IPC channel 交换的数据通过 Structured Clone Algorithm 进行序列化。函数和符号不可序列化,但您正尝试将它们传送过来:

 [
HID {
˟ _events: [Object: null prototype] { newListener: [Function (anonymous)] },
_eventsCount: 1,
_maxListeners: undefined,
_raw: HID {},
˟ write: [Function: bound write],
˟ getFeatureReport: [Function: bound getFeatureReport],
˟ sendFeatureReport: [Function: bound sendFeatureReport],
˟ setNonBlocking: [Function: bound setNonBlocking],
˟ readSync: [Function: bound readSync],
˟ readTimeout: [Function: bound readTimeout],
˟ getDeviceInfo: [Function: bound getDeviceInfo],
_paused: true,
˟ [Symbol(kCapture)]: false
}
]

关于 Electron 回复错误: An object could not be cloned,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70839472/

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