2025-07-07 03:47:12 +09:00

19 lines
598 B
JavaScript

const crypto = require('crypto');
function ipcRequest(req, channel, payload) {
return new Promise((resolve, reject) => {
const responseChannel = `${channel}-${crypto.randomUUID()}`;
req.bridge.once(responseChannel, (response) => {
if (response.success) {
resolve(response.data);
} else {
reject(new Error(response.error || `IPC request to ${channel} failed`));
}
});
req.bridge.emit('web-data-request', channel, responseChannel, payload);
});
}
module.exports = { ipcRequest };