Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
t13m committed Jun 30, 2021
1 parent 9b85c48 commit dd97099
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions source/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipc.callRenderer = (browserWindow, channel, data) => new Promise((resolve, rejec
const {sendChannel, dataChannel, errorChannel} = util.getRendererResponseChannels(channel);

const cleanup = () => {
ipc.off(dataChannel, onData);
ipc.off(errorChannel, onError);
ipcMain.off(dataChannel, onData);
ipcMain.off(errorChannel, onError);
};

const onData = (event, result) => {
Expand All @@ -34,8 +34,8 @@ ipc.callRenderer = (browserWindow, channel, data) => new Promise((resolve, rejec
}
};

ipc.on(dataChannel, onData);
ipc.on(errorChannel, onError);
ipcMain.on(dataChannel, onData);
ipcMain.on(errorChannel, onError);

const completeData = {
dataChannel,
Expand Down Expand Up @@ -99,10 +99,10 @@ ipc.answerRenderer = (browserWindowOrChannel, channelOrCallback, callbackOrNothi
}
};

ipc.on(sendChannel, listener);
ipcMain.on(sendChannel, listener);

return () => {
ipc.off(sendChannel, listener);
ipcMain.off(sendChannel, listener);
};
};

Expand Down
18 changes: 9 additions & 9 deletions source/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ipc.callMain = (channel, data) => new Promise((resolve, reject) => {
const {sendChannel, dataChannel, errorChannel} = util.getResponseChannels(channel);

const cleanup = () => {
ipc.off(dataChannel, onData);
ipc.off(errorChannel, onError);
ipcRenderer.off(dataChannel, onData);
ipcRenderer.off(errorChannel, onError);
};

const onData = (_event, result) => {
Expand All @@ -24,16 +24,16 @@ ipc.callMain = (channel, data) => new Promise((resolve, reject) => {
reject(deserializeError(error));
};

ipc.once(dataChannel, onData);
ipc.once(errorChannel, onError);
ipcRenderer.once(dataChannel, onData);
ipcRenderer.once(errorChannel, onError);

const completeData = {
dataChannel,
errorChannel,
userData: data
};

ipc.send(sendChannel, completeData);
ipcRenderer.send(sendChannel, completeData);
});

ipc.answerMain = (channel, callback) => {
Expand All @@ -43,16 +43,16 @@ ipc.answerMain = (channel, callback) => {
const {dataChannel, errorChannel, userData} = data;

try {
ipc.send(dataChannel, await callback(userData));
ipcRenderer.send(dataChannel, await callback(userData));
} catch (error) {
ipc.send(errorChannel, serializeError(error));
ipcRenderer.send(errorChannel, serializeError(error));
}
};

ipc.on(sendChannel, listener);
ipcRenderer.on(sendChannel, listener);

return () => {
ipc.off(sendChannel, listener);
ipcRenderer.off(sendChannel, listener);
};
};

Expand Down

0 comments on commit dd97099

Please sign in to comment.