@lvce-editor/ipc 5.0.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +63 -105
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
import { VError } from '@lvce-editor/verror';
|
|
2
2
|
import { string, array } from '@lvce-editor/assert';
|
|
3
3
|
|
|
4
|
+
const attachEvent = (rawIpc, getData, that) => {
|
|
5
|
+
const wrapped = event => {
|
|
6
|
+
const data = getData(event);
|
|
7
|
+
that.dispatchEvent(new MessageEvent('message', {
|
|
8
|
+
data
|
|
9
|
+
}));
|
|
10
|
+
};
|
|
11
|
+
if ('onmessage' in rawIpc) {
|
|
12
|
+
rawIpc.onmessage = wrapped;
|
|
13
|
+
} else if ('on' in rawIpc) {
|
|
14
|
+
rawIpc.on('message', wrapped);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
class Ipc extends EventTarget {
|
|
18
|
+
constructor(rawIpc, getData) {
|
|
19
|
+
super();
|
|
20
|
+
attachEvent(rawIpc, getData, this);
|
|
21
|
+
this._rawIpc = rawIpc;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated use addEventListener instead of getter/setter
|
|
26
|
+
*/
|
|
27
|
+
set onmessage(listener) {
|
|
28
|
+
this.addEventListener('message', listener);
|
|
29
|
+
}
|
|
30
|
+
send(message) {
|
|
31
|
+
if ('postMessage' in this._rawIpc) {
|
|
32
|
+
this._rawIpc.postMessage(message);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if ('send' in this._rawIpc) {
|
|
36
|
+
this._rawIpc.send(message);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
throw new Error('send not supported');
|
|
40
|
+
}
|
|
41
|
+
sendAndTransfer(message, transfer) {
|
|
42
|
+
if ('postMessage' in this._rawIpc) {
|
|
43
|
+
this._rawIpc.postMessage(message, transfer);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
throw new Error('sendAndTransfer not supported');
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
if ('close' in this._rawIpc) {
|
|
50
|
+
this._rawIpc.close();
|
|
51
|
+
}
|
|
52
|
+
if ('kill' in this._rawIpc) {
|
|
53
|
+
this._rawIpc.kill();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
4
58
|
const E_INCOMPATIBLE_NATIVE_MODULE = 'E_INCOMPATIBLE_NATIVE_MODULE';
|
|
5
59
|
const E_MODULES_NOT_SUPPORTED_IN_ELECTRON = 'E_MODULES_NOT_SUPPORTED_IN_ELECTRON';
|
|
6
60
|
const ERR_MODULE_NOT_FOUND = 'ERR_MODULE_NOT_FOUND';
|
|
@@ -175,39 +229,7 @@ const getActualData$1 = event => {
|
|
|
175
229
|
};
|
|
176
230
|
};
|
|
177
231
|
const wrap$a = messagePort => {
|
|
178
|
-
return
|
|
179
|
-
messagePort,
|
|
180
|
-
on(event, listener) {
|
|
181
|
-
if (event === 'message') {
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
const wrappedListener = event => {
|
|
184
|
-
const actualData = getActualData$1(event);
|
|
185
|
-
const syntheticEvent = {
|
|
186
|
-
data: actualData,
|
|
187
|
-
target: this
|
|
188
|
-
};
|
|
189
|
-
listener(syntheticEvent);
|
|
190
|
-
};
|
|
191
|
-
this.messagePort.on(event, wrappedListener);
|
|
192
|
-
} else if (event === 'close') {
|
|
193
|
-
this.messagePort.on('close', listener);
|
|
194
|
-
} else {
|
|
195
|
-
throw new Error('unsupported event type');
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
off(event, listener) {
|
|
199
|
-
this.messagePort.off(event, listener);
|
|
200
|
-
},
|
|
201
|
-
send(message) {
|
|
202
|
-
this.messagePort.postMessage(message);
|
|
203
|
-
},
|
|
204
|
-
dispose() {
|
|
205
|
-
this.messagePort.close();
|
|
206
|
-
},
|
|
207
|
-
start() {
|
|
208
|
-
throw new Error('start method is deprecated');
|
|
209
|
-
}
|
|
210
|
-
};
|
|
232
|
+
return new Ipc(messagePort, getActualData$1);
|
|
211
233
|
};
|
|
212
234
|
|
|
213
235
|
const IpcChildWithElectronMessagePort = {
|
|
@@ -244,51 +266,11 @@ const listen$6 = () => {
|
|
|
244
266
|
}
|
|
245
267
|
return parentPort;
|
|
246
268
|
};
|
|
247
|
-
|
|
248
|
-
// @ts-ignore
|
|
249
269
|
const signal$5 = parentPort => {
|
|
250
270
|
parentPort.postMessage(readyMessage);
|
|
251
271
|
};
|
|
252
|
-
|
|
253
|
-
// @ts-ignore
|
|
254
272
|
const wrap$9 = parentPort => {
|
|
255
|
-
return
|
|
256
|
-
parentPort,
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
on(event, listener) {
|
|
259
|
-
if (event === 'message') {
|
|
260
|
-
// @ts-ignore
|
|
261
|
-
const wrappedListener = event => {
|
|
262
|
-
const actualData = getUtilityProcessPortData(event);
|
|
263
|
-
const syntheticEvent = {
|
|
264
|
-
data: actualData,
|
|
265
|
-
target: this
|
|
266
|
-
};
|
|
267
|
-
listener(syntheticEvent);
|
|
268
|
-
};
|
|
269
|
-
this.parentPort.on(event, wrappedListener);
|
|
270
|
-
} else if (event === 'close') {
|
|
271
|
-
this.parentPort.on('close', listener);
|
|
272
|
-
} else {
|
|
273
|
-
throw new Error('unsupported event type');
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
// @ts-ignore
|
|
277
|
-
off(event, listener) {
|
|
278
|
-
this.parentPort.off(event, listener);
|
|
279
|
-
},
|
|
280
|
-
// @ts-ignore
|
|
281
|
-
send(message) {
|
|
282
|
-
this.parentPort.postMessage(message);
|
|
283
|
-
},
|
|
284
|
-
// @ts-ignore
|
|
285
|
-
sendAndTransfer(message, transfer) {
|
|
286
|
-
this.parentPort.postMessage(message, transfer);
|
|
287
|
-
},
|
|
288
|
-
dispose() {
|
|
289
|
-
this.parentPort.close();
|
|
290
|
-
}
|
|
291
|
-
};
|
|
273
|
+
return new Ipc(parentPort, getUtilityProcessPortData);
|
|
292
274
|
};
|
|
293
275
|
|
|
294
276
|
const IpcChildWithElectronUtilityProcess = {
|
|
@@ -298,7 +280,7 @@ const IpcChildWithElectronUtilityProcess = {
|
|
|
298
280
|
wrap: wrap$9
|
|
299
281
|
};
|
|
300
282
|
|
|
301
|
-
const getData = event => {
|
|
283
|
+
const getData$1 = event => {
|
|
302
284
|
return event.data;
|
|
303
285
|
};
|
|
304
286
|
|
|
@@ -330,7 +312,7 @@ const wrap$8 = global => {
|
|
|
330
312
|
},
|
|
331
313
|
set onmessage(listener) {
|
|
332
314
|
const wrappedListener = event => {
|
|
333
|
-
const data = getData(event);
|
|
315
|
+
const data = getData$1(event);
|
|
334
316
|
// @ts-expect-error
|
|
335
317
|
listener({
|
|
336
318
|
data,
|
|
@@ -420,7 +402,7 @@ const wrap$7 = port => {
|
|
|
420
402
|
if (listener) {
|
|
421
403
|
// @ts-expect-error
|
|
422
404
|
this.wrappedListener = event => {
|
|
423
|
-
const data = getData(event);
|
|
405
|
+
const data = getData$1(event);
|
|
424
406
|
// @ts-expect-error
|
|
425
407
|
listener({
|
|
426
408
|
data,
|
|
@@ -884,35 +866,11 @@ const create$2 = async ({
|
|
|
884
866
|
childProcess.stderr.pipe(process.stderr);
|
|
885
867
|
return childProcess;
|
|
886
868
|
};
|
|
887
|
-
|
|
888
|
-
|
|
869
|
+
const getData = data => {
|
|
870
|
+
return data;
|
|
871
|
+
};
|
|
889
872
|
const wrap$2 = process => {
|
|
890
|
-
return
|
|
891
|
-
process,
|
|
892
|
-
// @ts-ignore
|
|
893
|
-
on(event, listener) {
|
|
894
|
-
const wrappedListener = message => {
|
|
895
|
-
const syntheticEvent = {
|
|
896
|
-
data: message,
|
|
897
|
-
target: this
|
|
898
|
-
};
|
|
899
|
-
listener(syntheticEvent);
|
|
900
|
-
};
|
|
901
|
-
this.process.on(event, wrappedListener);
|
|
902
|
-
},
|
|
903
|
-
// @ts-ignore
|
|
904
|
-
send(message) {
|
|
905
|
-
this.process.postMessage(message);
|
|
906
|
-
},
|
|
907
|
-
// @ts-ignore
|
|
908
|
-
sendAndTransfer(message, transfer) {
|
|
909
|
-
array(transfer);
|
|
910
|
-
this.process.postMessage(message, transfer);
|
|
911
|
-
},
|
|
912
|
-
dispose() {
|
|
913
|
-
this.process.kill();
|
|
914
|
-
}
|
|
915
|
-
};
|
|
873
|
+
return new Ipc(process, getData);
|
|
916
874
|
};
|
|
917
875
|
|
|
918
876
|
const IpcParentWithElectronUtilityProcess = {
|