@lvce-editor/ipc 5.1.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 -108
- 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,42 +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
|
-
sendAndTransfer(message, transfer) {
|
|
205
|
-
this.messagePort.postMessage(message, transfer);
|
|
206
|
-
},
|
|
207
|
-
dispose() {
|
|
208
|
-
this.messagePort.close();
|
|
209
|
-
},
|
|
210
|
-
start() {
|
|
211
|
-
throw new Error('start method is deprecated');
|
|
212
|
-
}
|
|
213
|
-
};
|
|
232
|
+
return new Ipc(messagePort, getActualData$1);
|
|
214
233
|
};
|
|
215
234
|
|
|
216
235
|
const IpcChildWithElectronMessagePort = {
|
|
@@ -247,51 +266,11 @@ const listen$6 = () => {
|
|
|
247
266
|
}
|
|
248
267
|
return parentPort;
|
|
249
268
|
};
|
|
250
|
-
|
|
251
|
-
// @ts-ignore
|
|
252
269
|
const signal$5 = parentPort => {
|
|
253
270
|
parentPort.postMessage(readyMessage);
|
|
254
271
|
};
|
|
255
|
-
|
|
256
|
-
// @ts-ignore
|
|
257
272
|
const wrap$9 = parentPort => {
|
|
258
|
-
return
|
|
259
|
-
parentPort,
|
|
260
|
-
// @ts-ignore
|
|
261
|
-
on(event, listener) {
|
|
262
|
-
if (event === 'message') {
|
|
263
|
-
// @ts-ignore
|
|
264
|
-
const wrappedListener = event => {
|
|
265
|
-
const actualData = getUtilityProcessPortData(event);
|
|
266
|
-
const syntheticEvent = {
|
|
267
|
-
data: actualData,
|
|
268
|
-
target: this
|
|
269
|
-
};
|
|
270
|
-
listener(syntheticEvent);
|
|
271
|
-
};
|
|
272
|
-
this.parentPort.on(event, wrappedListener);
|
|
273
|
-
} else if (event === 'close') {
|
|
274
|
-
this.parentPort.on('close', listener);
|
|
275
|
-
} else {
|
|
276
|
-
throw new Error('unsupported event type');
|
|
277
|
-
}
|
|
278
|
-
},
|
|
279
|
-
// @ts-ignore
|
|
280
|
-
off(event, listener) {
|
|
281
|
-
this.parentPort.off(event, listener);
|
|
282
|
-
},
|
|
283
|
-
// @ts-ignore
|
|
284
|
-
send(message) {
|
|
285
|
-
this.parentPort.postMessage(message);
|
|
286
|
-
},
|
|
287
|
-
// @ts-ignore
|
|
288
|
-
sendAndTransfer(message, transfer) {
|
|
289
|
-
this.parentPort.postMessage(message, transfer);
|
|
290
|
-
},
|
|
291
|
-
dispose() {
|
|
292
|
-
this.parentPort.close();
|
|
293
|
-
}
|
|
294
|
-
};
|
|
273
|
+
return new Ipc(parentPort, getUtilityProcessPortData);
|
|
295
274
|
};
|
|
296
275
|
|
|
297
276
|
const IpcChildWithElectronUtilityProcess = {
|
|
@@ -301,7 +280,7 @@ const IpcChildWithElectronUtilityProcess = {
|
|
|
301
280
|
wrap: wrap$9
|
|
302
281
|
};
|
|
303
282
|
|
|
304
|
-
const getData = event => {
|
|
283
|
+
const getData$1 = event => {
|
|
305
284
|
return event.data;
|
|
306
285
|
};
|
|
307
286
|
|
|
@@ -333,7 +312,7 @@ const wrap$8 = global => {
|
|
|
333
312
|
},
|
|
334
313
|
set onmessage(listener) {
|
|
335
314
|
const wrappedListener = event => {
|
|
336
|
-
const data = getData(event);
|
|
315
|
+
const data = getData$1(event);
|
|
337
316
|
// @ts-expect-error
|
|
338
317
|
listener({
|
|
339
318
|
data,
|
|
@@ -423,7 +402,7 @@ const wrap$7 = port => {
|
|
|
423
402
|
if (listener) {
|
|
424
403
|
// @ts-expect-error
|
|
425
404
|
this.wrappedListener = event => {
|
|
426
|
-
const data = getData(event);
|
|
405
|
+
const data = getData$1(event);
|
|
427
406
|
// @ts-expect-error
|
|
428
407
|
listener({
|
|
429
408
|
data,
|
|
@@ -887,35 +866,11 @@ const create$2 = async ({
|
|
|
887
866
|
childProcess.stderr.pipe(process.stderr);
|
|
888
867
|
return childProcess;
|
|
889
868
|
};
|
|
890
|
-
|
|
891
|
-
|
|
869
|
+
const getData = data => {
|
|
870
|
+
return data;
|
|
871
|
+
};
|
|
892
872
|
const wrap$2 = process => {
|
|
893
|
-
return
|
|
894
|
-
process,
|
|
895
|
-
// @ts-ignore
|
|
896
|
-
on(event, listener) {
|
|
897
|
-
const wrappedListener = message => {
|
|
898
|
-
const syntheticEvent = {
|
|
899
|
-
data: message,
|
|
900
|
-
target: this
|
|
901
|
-
};
|
|
902
|
-
listener(syntheticEvent);
|
|
903
|
-
};
|
|
904
|
-
this.process.on(event, wrappedListener);
|
|
905
|
-
},
|
|
906
|
-
// @ts-ignore
|
|
907
|
-
send(message) {
|
|
908
|
-
this.process.postMessage(message);
|
|
909
|
-
},
|
|
910
|
-
// @ts-ignore
|
|
911
|
-
sendAndTransfer(message, transfer) {
|
|
912
|
-
array(transfer);
|
|
913
|
-
this.process.postMessage(message, transfer);
|
|
914
|
-
},
|
|
915
|
-
dispose() {
|
|
916
|
-
this.process.kill();
|
|
917
|
-
}
|
|
918
|
-
};
|
|
873
|
+
return new Ipc(process, getData);
|
|
919
874
|
};
|
|
920
875
|
|
|
921
876
|
const IpcParentWithElectronUtilityProcess = {
|