2018-01-10 17:02:29 +01:00
|
|
|
const { ipcRenderer } = require('electron');
|
|
|
|
|
|
|
|
class BDIpc {
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
static on(channel, cb) {
|
|
|
|
ipcRenderer.on(channel, (event, args) => cb(event, args));
|
|
|
|
}
|
|
|
|
|
2018-01-10 17:02:29 +01:00
|
|
|
static async send(channel, message) {
|
|
|
|
const __eid = Date.now().toString();
|
|
|
|
ipcRenderer.send(
|
|
|
|
channel.startsWith('bd-') ? channel: `bd-${channel}`,
|
|
|
|
message === undefined ? { __eid } : Object.assign(message, { __eid })
|
|
|
|
);
|
|
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
ipcRenderer.once(__eid, (event, arg) => {
|
|
|
|
if (arg.err) return reject(arg);
|
|
|
|
resolve(arg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-21 04:48:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { BDIpc };
|