@lvce-editor/ipc 7.1.1 → 7.3.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/browser.js +42 -12
- package/dist/index.d.ts +2 -3
- package/dist/index.js +125 -42
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -2,24 +2,25 @@ const getData$1 = event => {
|
|
|
2
2
|
return event.data;
|
|
3
3
|
};
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const data = getData(
|
|
5
|
+
const attachEvents = that => {
|
|
6
|
+
const handleMessage = (...args) => {
|
|
7
|
+
const data = that.getData(...args);
|
|
8
8
|
that.dispatchEvent(new MessageEvent('message', {
|
|
9
9
|
data
|
|
10
10
|
}));
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
that.onMessage(handleMessage);
|
|
13
|
+
const handleClose = event => {
|
|
14
|
+
that.dispatchEvent(new Event('close'));
|
|
15
|
+
};
|
|
16
|
+
that.onClose(handleClose);
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
class Ipc extends EventTarget {
|
|
19
20
|
constructor(rawIpc) {
|
|
20
21
|
super();
|
|
21
|
-
attachEvent(rawIpc, this.getData, this);
|
|
22
22
|
this._rawIpc = rawIpc;
|
|
23
|
+
attachEvents(this);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
26
|
|
|
@@ -50,6 +51,12 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
50
51
|
dispose() {
|
|
51
52
|
// ignore
|
|
52
53
|
}
|
|
54
|
+
onClose(callback) {
|
|
55
|
+
// ignore
|
|
56
|
+
}
|
|
57
|
+
onMessage(callback) {
|
|
58
|
+
this._rawIpc.addEventListener('message', callback);
|
|
59
|
+
}
|
|
53
60
|
}
|
|
54
61
|
const wrap$4 = global => {
|
|
55
62
|
return new IpcChildWithModuleWorker(global);
|
|
@@ -323,6 +330,12 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
323
330
|
this._rawIpc.close();
|
|
324
331
|
}
|
|
325
332
|
}
|
|
333
|
+
onClose(callback) {
|
|
334
|
+
// ignore
|
|
335
|
+
}
|
|
336
|
+
onMessage(callback) {
|
|
337
|
+
this._rawIpc.addEventListener('message', callback);
|
|
338
|
+
}
|
|
326
339
|
}
|
|
327
340
|
const wrap$3 = port => {
|
|
328
341
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
@@ -348,12 +361,17 @@ class IpcChildWithWindow extends Ipc {
|
|
|
348
361
|
this._rawIpc.postMessage(message);
|
|
349
362
|
}
|
|
350
363
|
sendAndTransfer(message, transfer) {
|
|
351
|
-
|
|
352
|
-
this._rawIpc.postMessage(message, '*', transfer);
|
|
364
|
+
this._rawIpc.postMessage(message, location.origin, transfer);
|
|
353
365
|
}
|
|
354
366
|
dispose() {
|
|
355
367
|
// ignore
|
|
356
368
|
}
|
|
369
|
+
onClose(callback) {
|
|
370
|
+
// ignore
|
|
371
|
+
}
|
|
372
|
+
onMessage(callback) {
|
|
373
|
+
this._rawIpc.addEventListener('message', callback);
|
|
374
|
+
}
|
|
357
375
|
}
|
|
358
376
|
const wrap$2 = window => {
|
|
359
377
|
return new IpcChildWithWindow(window);
|
|
@@ -497,7 +515,13 @@ class IpcParentWithModuleWorker extends Ipc {
|
|
|
497
515
|
this._rawIpc.postMessage(message, transfer);
|
|
498
516
|
}
|
|
499
517
|
dispose() {
|
|
500
|
-
//
|
|
518
|
+
// ignore
|
|
519
|
+
}
|
|
520
|
+
onClose(callback) {
|
|
521
|
+
// ignore
|
|
522
|
+
}
|
|
523
|
+
onMessage(callback) {
|
|
524
|
+
this._rawIpc.addEventListener('message', callback);
|
|
501
525
|
}
|
|
502
526
|
}
|
|
503
527
|
const wrap$1 = worker => {
|
|
@@ -557,6 +581,12 @@ class IpcParentWithWebSocket extends Ipc {
|
|
|
557
581
|
dispose() {
|
|
558
582
|
this._rawIpc.close();
|
|
559
583
|
}
|
|
584
|
+
onClose(callback) {
|
|
585
|
+
this._rawIpc.addEventListener('close', callback);
|
|
586
|
+
}
|
|
587
|
+
onMessage(callback) {
|
|
588
|
+
this._rawIpc.addEventListener('message', callback);
|
|
589
|
+
}
|
|
560
590
|
}
|
|
561
591
|
const wrap = webSocket => {
|
|
562
592
|
return new IpcParentWithWebSocket(webSocket);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
interface Ipc {
|
|
1
|
+
interface Ipc extends EventTarget {
|
|
2
2
|
readonly send: (message: any) => void
|
|
3
3
|
readonly sendAndTransfer: (message: any, transfer: any) => void
|
|
4
|
-
readonly on: any
|
|
5
|
-
readonly onmessage: any
|
|
6
4
|
readonly dispose: () => void
|
|
7
5
|
readonly isDisposed: () => void
|
|
8
6
|
}
|
|
@@ -17,6 +15,7 @@ export const IpcChildWithElectronUtilityProcess: IpcChild
|
|
|
17
15
|
export const IpcChildWithNodeForkedProcess: IpcChild
|
|
18
16
|
export const IpcChildWithWebSocket: IpcChild
|
|
19
17
|
export const IpcChildWithNodeWorker: IpcChild
|
|
18
|
+
export const IpcChildWithRendererProcess2: IpcChild
|
|
20
19
|
|
|
21
20
|
interface IpcParent {
|
|
22
21
|
readonly create: any
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
import { VError } from '@lvce-editor/verror';
|
|
2
2
|
import { string, array } from '@lvce-editor/assert';
|
|
3
3
|
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const data = getData(
|
|
4
|
+
const attachEvents = that => {
|
|
5
|
+
const handleMessage = (...args) => {
|
|
6
|
+
const data = that.getData(...args);
|
|
7
7
|
that.dispatchEvent(new MessageEvent('message', {
|
|
8
8
|
data
|
|
9
9
|
}));
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
that.onMessage(handleMessage);
|
|
12
|
+
const handleClose = event => {
|
|
13
|
+
that.dispatchEvent(new Event('close'));
|
|
14
|
+
};
|
|
15
|
+
that.onClose(handleClose);
|
|
16
16
|
};
|
|
17
|
+
|
|
17
18
|
class Ipc extends EventTarget {
|
|
18
19
|
constructor(rawIpc) {
|
|
19
20
|
super();
|
|
20
|
-
attachEvent(rawIpc, this.getData, this);
|
|
21
21
|
this._rawIpc = rawIpc;
|
|
22
|
+
attachEvents(this);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -171,7 +172,7 @@ const isMessagePortMain = value => {
|
|
|
171
172
|
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
172
173
|
};
|
|
173
174
|
|
|
174
|
-
const listen$
|
|
175
|
+
const listen$8 = ({
|
|
175
176
|
messagePort
|
|
176
177
|
}) => {
|
|
177
178
|
if (!isMessagePortMain(messagePort)) {
|
|
@@ -211,16 +212,22 @@ class IpcChildWithElectronMessagePort extends Ipc {
|
|
|
211
212
|
dispose() {
|
|
212
213
|
this._rawIpc.close();
|
|
213
214
|
}
|
|
215
|
+
onMessage(callback) {
|
|
216
|
+
this._rawIpc.on('message', callback);
|
|
217
|
+
}
|
|
218
|
+
onClose(callback) {
|
|
219
|
+
this._rawIpc.on('close', callback);
|
|
220
|
+
}
|
|
214
221
|
}
|
|
215
|
-
const wrap$
|
|
222
|
+
const wrap$b = messagePort => {
|
|
216
223
|
return new IpcChildWithElectronMessagePort(messagePort);
|
|
217
224
|
};
|
|
218
225
|
|
|
219
226
|
const IpcChildWithElectronMessagePort$1 = {
|
|
220
227
|
__proto__: null,
|
|
221
|
-
listen: listen$
|
|
228
|
+
listen: listen$8,
|
|
222
229
|
signal: signal$6,
|
|
223
|
-
wrap: wrap$
|
|
230
|
+
wrap: wrap$b
|
|
224
231
|
};
|
|
225
232
|
|
|
226
233
|
// @ts-ignore
|
|
@@ -240,7 +247,7 @@ const getUtilityProcessPortData = event => {
|
|
|
240
247
|
|
|
241
248
|
const readyMessage = 'ready';
|
|
242
249
|
|
|
243
|
-
const listen$
|
|
250
|
+
const listen$7 = () => {
|
|
244
251
|
// @ts-ignore
|
|
245
252
|
const {
|
|
246
253
|
parentPort
|
|
@@ -266,23 +273,29 @@ class IpcChildWithElectronUtilityProcess extends Ipc {
|
|
|
266
273
|
dispose() {
|
|
267
274
|
this._rawIpc.close();
|
|
268
275
|
}
|
|
276
|
+
onClose(callback) {
|
|
277
|
+
this._rawIpc.on('close', callback);
|
|
278
|
+
}
|
|
279
|
+
onMessage(callback) {
|
|
280
|
+
this._rawIpc.on('message', callback);
|
|
281
|
+
}
|
|
269
282
|
}
|
|
270
|
-
const wrap$
|
|
283
|
+
const wrap$a = parentPort => {
|
|
271
284
|
return new IpcChildWithElectronUtilityProcess(parentPort);
|
|
272
285
|
};
|
|
273
286
|
|
|
274
287
|
const IpcChildWithElectronUtilityProcess$1 = {
|
|
275
288
|
__proto__: null,
|
|
276
|
-
listen: listen$
|
|
289
|
+
listen: listen$7,
|
|
277
290
|
signal: signal$5,
|
|
278
|
-
wrap: wrap$
|
|
291
|
+
wrap: wrap$a
|
|
279
292
|
};
|
|
280
293
|
|
|
281
|
-
const getData = event => {
|
|
294
|
+
const getData$1 = event => {
|
|
282
295
|
return event.data;
|
|
283
296
|
};
|
|
284
297
|
|
|
285
|
-
const listen$
|
|
298
|
+
const listen$6 = () => {
|
|
286
299
|
// @ts-ignore
|
|
287
300
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
288
301
|
throw new TypeError('module is not in web worker scope');
|
|
@@ -294,7 +307,7 @@ const signal$4 = global => {
|
|
|
294
307
|
};
|
|
295
308
|
class IpcChildWithModuleWorker extends Ipc {
|
|
296
309
|
getData(event) {
|
|
297
|
-
return getData(event);
|
|
310
|
+
return getData$1(event);
|
|
298
311
|
}
|
|
299
312
|
send(message) {
|
|
300
313
|
// @ts-ignore
|
|
@@ -307,16 +320,22 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
307
320
|
dispose() {
|
|
308
321
|
// ignore
|
|
309
322
|
}
|
|
323
|
+
onClose(callback) {
|
|
324
|
+
// ignore
|
|
325
|
+
}
|
|
326
|
+
onMessage(callback) {
|
|
327
|
+
this._rawIpc.addEventListener('message', callback);
|
|
328
|
+
}
|
|
310
329
|
}
|
|
311
|
-
const wrap$
|
|
330
|
+
const wrap$9 = global => {
|
|
312
331
|
return new IpcChildWithModuleWorker(global);
|
|
313
332
|
};
|
|
314
333
|
|
|
315
334
|
const IpcChildWithModuleWorker$1 = {
|
|
316
335
|
__proto__: null,
|
|
317
|
-
listen: listen$
|
|
336
|
+
listen: listen$6,
|
|
318
337
|
signal: signal$4,
|
|
319
|
-
wrap: wrap$
|
|
338
|
+
wrap: wrap$9
|
|
320
339
|
};
|
|
321
340
|
|
|
322
341
|
const withResolvers = () => {
|
|
@@ -348,10 +367,10 @@ const waitForFirstMessage = async port => {
|
|
|
348
367
|
return event.data;
|
|
349
368
|
};
|
|
350
369
|
|
|
351
|
-
const listen$
|
|
352
|
-
const parentIpcRaw = listen$
|
|
370
|
+
const listen$5 = async () => {
|
|
371
|
+
const parentIpcRaw = listen$6();
|
|
353
372
|
signal$4(parentIpcRaw);
|
|
354
|
-
const parentIpc = wrap$
|
|
373
|
+
const parentIpc = wrap$9(parentIpcRaw);
|
|
355
374
|
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
356
375
|
if (firstMessage.method !== 'initialize') {
|
|
357
376
|
throw new IpcError('unexpected first message');
|
|
@@ -366,7 +385,7 @@ const listen$4 = async () => {
|
|
|
366
385
|
};
|
|
367
386
|
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
368
387
|
getData(event) {
|
|
369
|
-
return getData(event);
|
|
388
|
+
return getData$1(event);
|
|
370
389
|
}
|
|
371
390
|
send(message) {
|
|
372
391
|
this._rawIpc.postMessage(message);
|
|
@@ -379,18 +398,24 @@ class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
|
379
398
|
this._rawIpc.close();
|
|
380
399
|
}
|
|
381
400
|
}
|
|
401
|
+
onClose(callback) {
|
|
402
|
+
// ignore
|
|
403
|
+
}
|
|
404
|
+
onMessage(callback) {
|
|
405
|
+
this._rawIpc.addEventListener('message', callback);
|
|
406
|
+
}
|
|
382
407
|
}
|
|
383
|
-
const wrap$
|
|
408
|
+
const wrap$8 = port => {
|
|
384
409
|
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
385
410
|
};
|
|
386
411
|
|
|
387
412
|
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
388
413
|
__proto__: null,
|
|
389
|
-
listen: listen$
|
|
390
|
-
wrap: wrap$
|
|
414
|
+
listen: listen$5,
|
|
415
|
+
wrap: wrap$8
|
|
391
416
|
};
|
|
392
417
|
|
|
393
|
-
const listen$
|
|
418
|
+
const listen$4 = async () => {
|
|
394
419
|
if (!process.send) {
|
|
395
420
|
throw new Error('process.send must be defined');
|
|
396
421
|
}
|
|
@@ -414,7 +439,7 @@ const getActualData = (message, handle) => {
|
|
|
414
439
|
};
|
|
415
440
|
|
|
416
441
|
// @ts-ignore
|
|
417
|
-
const wrap$
|
|
442
|
+
const wrap$7 = process => {
|
|
418
443
|
return {
|
|
419
444
|
process,
|
|
420
445
|
// @ts-ignore
|
|
@@ -450,16 +475,16 @@ const wrap$6 = process => {
|
|
|
450
475
|
|
|
451
476
|
const IpcChildWithNodeForkedProcess = {
|
|
452
477
|
__proto__: null,
|
|
453
|
-
listen: listen$
|
|
478
|
+
listen: listen$4,
|
|
454
479
|
signal: signal$3,
|
|
455
|
-
wrap: wrap$
|
|
480
|
+
wrap: wrap$7
|
|
456
481
|
};
|
|
457
482
|
|
|
458
483
|
const isMessagePort = value => {
|
|
459
484
|
return value && value instanceof MessagePort;
|
|
460
485
|
};
|
|
461
486
|
|
|
462
|
-
const listen$
|
|
487
|
+
const listen$3 = async ({
|
|
463
488
|
messagePort
|
|
464
489
|
}) => {
|
|
465
490
|
if (!isMessagePort(messagePort)) {
|
|
@@ -470,7 +495,7 @@ const listen$2 = async ({
|
|
|
470
495
|
const signal$2 = messagePort => {
|
|
471
496
|
messagePort.start();
|
|
472
497
|
};
|
|
473
|
-
const wrap$
|
|
498
|
+
const wrap$6 = port => {
|
|
474
499
|
return {
|
|
475
500
|
port,
|
|
476
501
|
on(event, listener) {
|
|
@@ -500,12 +525,12 @@ const wrap$5 = port => {
|
|
|
500
525
|
|
|
501
526
|
const IpcChildWithNodeMessagePort = {
|
|
502
527
|
__proto__: null,
|
|
503
|
-
listen: listen$
|
|
528
|
+
listen: listen$3,
|
|
504
529
|
signal: signal$2,
|
|
505
|
-
wrap: wrap$
|
|
530
|
+
wrap: wrap$6
|
|
506
531
|
};
|
|
507
532
|
|
|
508
|
-
const listen$
|
|
533
|
+
const listen$2 = async () => {
|
|
509
534
|
const {
|
|
510
535
|
parentPort
|
|
511
536
|
} = await import('node:worker_threads');
|
|
@@ -517,7 +542,7 @@ const listen$1 = async () => {
|
|
|
517
542
|
const signal$1 = parentPort => {
|
|
518
543
|
parentPort.postMessage(readyMessage);
|
|
519
544
|
};
|
|
520
|
-
const wrap$
|
|
545
|
+
const wrap$5 = parentPort => {
|
|
521
546
|
return {
|
|
522
547
|
parentPort,
|
|
523
548
|
on(event, listener) {
|
|
@@ -544,8 +569,54 @@ const wrap$4 = parentPort => {
|
|
|
544
569
|
|
|
545
570
|
const IpcChildWithNodeWorker = {
|
|
546
571
|
__proto__: null,
|
|
547
|
-
listen: listen$
|
|
572
|
+
listen: listen$2,
|
|
548
573
|
signal: signal$1,
|
|
574
|
+
wrap: wrap$5
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
const preloadChannelType = 'port';
|
|
578
|
+
const listen$1 = ({
|
|
579
|
+
webContents
|
|
580
|
+
}) => {
|
|
581
|
+
return webContents;
|
|
582
|
+
};
|
|
583
|
+
const getData = (event, message) => {
|
|
584
|
+
const {
|
|
585
|
+
ports
|
|
586
|
+
} = event;
|
|
587
|
+
const data = {
|
|
588
|
+
...message,
|
|
589
|
+
params: [...message.params, ...ports]
|
|
590
|
+
};
|
|
591
|
+
return data;
|
|
592
|
+
};
|
|
593
|
+
class IpcChildWithRendererProcess2 extends Ipc {
|
|
594
|
+
getData(event, message) {
|
|
595
|
+
return getData(event, message);
|
|
596
|
+
}
|
|
597
|
+
send(message) {
|
|
598
|
+
this._rawIpc.postMessage(preloadChannelType, message);
|
|
599
|
+
}
|
|
600
|
+
sendAndTransfer(message, transfer) {
|
|
601
|
+
this._rawIpc.postMessage(preloadChannelType, message, transfer);
|
|
602
|
+
}
|
|
603
|
+
dispose() {
|
|
604
|
+
// ignore
|
|
605
|
+
}
|
|
606
|
+
onMessage(callback) {
|
|
607
|
+
this._rawIpc.ipc.on(preloadChannelType, callback);
|
|
608
|
+
}
|
|
609
|
+
onClose(callback) {
|
|
610
|
+
this._rawIpc.on('destroyed', callback);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
const wrap$4 = webContents => {
|
|
614
|
+
return new IpcChildWithRendererProcess2(webContents);
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
const IpcChildWithRendererProcess2$1 = {
|
|
618
|
+
__proto__: null,
|
|
619
|
+
listen: listen$1,
|
|
549
620
|
wrap: wrap$4
|
|
550
621
|
};
|
|
551
622
|
|
|
@@ -845,6 +916,12 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
|
|
|
845
916
|
dispose() {
|
|
846
917
|
this._rawIpc.kill();
|
|
847
918
|
}
|
|
919
|
+
onClose(callback) {
|
|
920
|
+
this._rawIpc.on('exit', callback);
|
|
921
|
+
}
|
|
922
|
+
onMessage(callback) {
|
|
923
|
+
this._rawIpc.on('message', callback);
|
|
924
|
+
}
|
|
848
925
|
}
|
|
849
926
|
const wrap$2 = process => {
|
|
850
927
|
return new IpcParentWithElectronUtilityProcess(process);
|
|
@@ -1012,6 +1089,12 @@ class IpcParentWithNodeForkedProcess extends Ipc {
|
|
|
1012
1089
|
dispose() {
|
|
1013
1090
|
this._rawIpc.kill();
|
|
1014
1091
|
}
|
|
1092
|
+
onClose(callback) {
|
|
1093
|
+
this._rawIpc.on('close', callback);
|
|
1094
|
+
}
|
|
1095
|
+
onMessage(callback) {
|
|
1096
|
+
this._rawIpc.on('message', callback);
|
|
1097
|
+
}
|
|
1015
1098
|
}
|
|
1016
1099
|
const wrap$1 = childProcess => {
|
|
1017
1100
|
return new IpcParentWithNodeForkedProcess(childProcess);
|
|
@@ -1106,4 +1189,4 @@ const IpcParentWithNodeWorker = {
|
|
|
1106
1189
|
wrap
|
|
1107
1190
|
};
|
|
1108
1191
|
|
|
1109
|
-
export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
|
|
1192
|
+
export { IpcChildWithElectronMessagePort$1 as IpcChildWithElectronMessagePort, IpcChildWithElectronUtilityProcess$1 as IpcChildWithElectronUtilityProcess, IpcChildWithModuleWorker$1 as IpcChildWithModuleWorker, IpcChildWithModuleWorkerAndMessagePort$1 as IpcChildWithModuleWorkerAndMessagePort, IpcChildWithNodeForkedProcess, IpcChildWithNodeMessagePort, IpcChildWithNodeWorker, IpcChildWithRendererProcess2$1 as IpcChildWithRendererProcess2, IpcChildWithWebSocket, IpcParentWithElectronUtilityProcess$1 as IpcParentWithElectronUtilityProcess, IpcParentWithNodeForkedProcess$1 as IpcParentWithNodeForkedProcess, IpcParentWithNodeWorker };
|