Skip to content

Commit fdda864

Browse files
authored
Fix problem with multiple callMain calls (#41)
1 parent 9b85c48 commit fdda864

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

source/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ ipc.callRenderer = (browserWindow, channel, data) => new Promise((resolve, rejec
1414
const {sendChannel, dataChannel, errorChannel} = util.getRendererResponseChannels(channel);
1515

1616
const cleanup = () => {
17-
ipc.off(dataChannel, onData);
18-
ipc.off(errorChannel, onError);
17+
ipcMain.off(dataChannel, onData);
18+
ipcMain.off(errorChannel, onError);
1919
};
2020

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

37-
ipc.on(dataChannel, onData);
38-
ipc.on(errorChannel, onError);
37+
ipcMain.on(dataChannel, onData);
38+
ipcMain.on(errorChannel, onError);
3939

4040
const completeData = {
4141
dataChannel,
@@ -99,10 +99,10 @@ ipc.answerRenderer = (browserWindowOrChannel, channelOrCallback, callbackOrNothi
9999
}
100100
};
101101

102-
ipc.on(sendChannel, listener);
102+
ipcMain.on(sendChannel, listener);
103103

104104
return () => {
105-
ipc.off(sendChannel, listener);
105+
ipcMain.off(sendChannel, listener);
106106
};
107107
};
108108

source/renderer.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ ipc.callMain = (channel, data) => new Promise((resolve, reject) => {
1010
const {sendChannel, dataChannel, errorChannel} = util.getResponseChannels(channel);
1111

1212
const cleanup = () => {
13-
ipc.off(dataChannel, onData);
14-
ipc.off(errorChannel, onError);
13+
ipcRenderer.off(dataChannel, onData);
14+
ipcRenderer.off(errorChannel, onError);
1515
};
1616

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

27-
ipc.once(dataChannel, onData);
28-
ipc.once(errorChannel, onError);
27+
ipcRenderer.once(dataChannel, onData);
28+
ipcRenderer.once(errorChannel, onError);
2929

3030
const completeData = {
3131
dataChannel,
3232
errorChannel,
3333
userData: data
3434
};
3535

36-
ipc.send(sendChannel, completeData);
36+
ipcRenderer.send(sendChannel, completeData);
3737
});
3838

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

4545
try {
46-
ipc.send(dataChannel, await callback(userData));
46+
ipcRenderer.send(dataChannel, await callback(userData));
4747
} catch (error) {
48-
ipc.send(errorChannel, serializeError(error));
48+
ipcRenderer.send(errorChannel, serializeError(error));
4949
}
5050
};
5151

52-
ipc.on(sendChannel, listener);
52+
ipcRenderer.on(sendChannel, listener);
5353

5454
return () => {
55-
ipc.off(sendChannel, listener);
55+
ipcRenderer.off(sendChannel, listener);
5656
};
5757
};
5858

0 commit comments

Comments
 (0)