Skip to content

Commit 677fca4

Browse files
committed
fix(kkrpc): dispatch to messageListeners in Electron utility process adapters
Both ElectronUtilityProcessIO (main-process side) and ElectronUtilityProcessChildIO (child-process side) had on()/off() methods that registered messageListeners, but handleMessage() never checked them. Incoming messages went straight to resolveRead/queue, so any listener registered via on("message", cb) would silently never fire. Every other IO adapter in kkrpc follows a three-tier dispatch priority: messageListeners > resolveRead > messageQueue. The Electron utility process adapters were the only ones that skipped the first tier. This fix aligns them with the universal pattern used by WorkerParentIO, WorkerChildIO, NodeIo, IframeParentIO, IframeChildIO, WebSocketClientIO, and WebSocketServerIO.
1 parent 6cbd387 commit 677fca4

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

packages/kkrpc/src/adapters/electron-child.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ export class ElectronUtilityProcessChildIO implements IoInterface {
5151
return
5252
}
5353

54-
if (this.resolveRead) {
55-
this.resolveRead(message)
56-
this.resolveRead = null
54+
if (this.messageListeners.size > 0) {
55+
this.messageListeners.forEach((listener) => listener(message))
5756
} else {
58-
this.messageQueue.push(message)
57+
if (this.resolveRead) {
58+
this.resolveRead(message)
59+
this.resolveRead = null
60+
} else {
61+
this.messageQueue.push(message)
62+
}
5963
}
6064
}
6165

packages/kkrpc/src/adapters/electron.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ export class ElectronUtilityProcessIO implements IoInterface {
7171
return
7272
}
7373

74-
if (this.resolveRead) {
75-
this.resolveRead(normalized)
76-
this.resolveRead = null
74+
if (this.messageListeners.size > 0) {
75+
this.messageListeners.forEach((listener) => listener(normalized))
7776
} else {
78-
this.messageQueue.push(normalized)
77+
if (this.resolveRead) {
78+
this.resolveRead(normalized)
79+
this.resolveRead = null
80+
} else {
81+
this.messageQueue.push(normalized)
82+
}
7983
}
8084
}
8185

0 commit comments

Comments
 (0)