@lvce-editor/ipc 10.0.3 → 10.0.4
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/electron.js +101 -86
- package/dist/index.js +5 -2
- package/package.json +1 -1
package/dist/electron.js
CHANGED
|
@@ -37,6 +37,102 @@ const Exit = 1;
|
|
|
37
37
|
const Error$1 = 2;
|
|
38
38
|
const Message = 3;
|
|
39
39
|
|
|
40
|
+
const walkValue = (value, transferrables, isTransferrable) => {
|
|
41
|
+
if (!value) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (isTransferrable(value)) {
|
|
45
|
+
transferrables.push(value);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (Array.isArray(value)) {
|
|
49
|
+
for (const item of value) {
|
|
50
|
+
walkValue(item, transferrables, isTransferrable);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof value === 'object') {
|
|
55
|
+
for (const property of Object.values(value)) {
|
|
56
|
+
walkValue(property, transferrables, isTransferrable);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const isMessagePort = value => {
|
|
63
|
+
return value && value instanceof MessagePort;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const isMessagePortMain = value => {
|
|
67
|
+
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const isOffscreenCanvas = value => {
|
|
71
|
+
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const isInstanceOf = (value, constructorName) => {
|
|
75
|
+
return value?.constructor?.name === constructorName;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const isSocket = value => {
|
|
79
|
+
return isInstanceOf(value, 'Socket');
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
83
|
+
|
|
84
|
+
const isTransferrable = value => {
|
|
85
|
+
for (const fn of transferrables) {
|
|
86
|
+
if (fn(value)) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return false;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getTransferrables = value => {
|
|
94
|
+
const transferrables = [];
|
|
95
|
+
walkValue(value, transferrables, isTransferrable);
|
|
96
|
+
return transferrables;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const removeValues = (value, toRemove) => {
|
|
100
|
+
if (!value) {
|
|
101
|
+
return value;
|
|
102
|
+
}
|
|
103
|
+
if (Array.isArray(value)) {
|
|
104
|
+
const newItems = [];
|
|
105
|
+
for (const item of value) {
|
|
106
|
+
if (!toRemove.includes(item)) {
|
|
107
|
+
newItems.push(removeValues(item, toRemove));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return newItems;
|
|
111
|
+
}
|
|
112
|
+
if (typeof value === 'object') {
|
|
113
|
+
const newObject = Object.create(null);
|
|
114
|
+
for (const [key, property] of Object.entries(value)) {
|
|
115
|
+
if (!toRemove.includes(property)) {
|
|
116
|
+
newObject[key] = removeValues(property, toRemove);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return newObject;
|
|
120
|
+
}
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// workaround for electron not supporting transferrable objects
|
|
125
|
+
// as parameters. If the transferrable object is a parameter, in electron
|
|
126
|
+
// only an empty objected is received in the main process
|
|
127
|
+
const fixElectronParameters = value => {
|
|
128
|
+
const transfer = getTransferrables(value);
|
|
129
|
+
const newValue = removeValues(value, transfer);
|
|
130
|
+
return {
|
|
131
|
+
newValue,
|
|
132
|
+
transfer
|
|
133
|
+
};
|
|
134
|
+
};
|
|
135
|
+
|
|
40
136
|
const withResolvers = () => {
|
|
41
137
|
let _resolve;
|
|
42
138
|
const promise = new Promise(resolve => {
|
|
@@ -340,65 +436,6 @@ class IpcError extends VError {
|
|
|
340
436
|
}
|
|
341
437
|
}
|
|
342
438
|
|
|
343
|
-
const walkValue = (value, transferrables, isTransferrable) => {
|
|
344
|
-
if (!value) {
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
if (isTransferrable(value)) {
|
|
348
|
-
transferrables.push(value);
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
if (Array.isArray(value)) {
|
|
352
|
-
for (const item of value) {
|
|
353
|
-
walkValue(item, transferrables, isTransferrable);
|
|
354
|
-
}
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
if (typeof value === 'object') {
|
|
358
|
-
for (const property of Object.values(value)) {
|
|
359
|
-
walkValue(property, transferrables, isTransferrable);
|
|
360
|
-
}
|
|
361
|
-
return;
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
const isMessagePort = value => {
|
|
366
|
-
return value && value instanceof MessagePort;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
const isMessagePortMain = value => {
|
|
370
|
-
return value && value.constructor && value.constructor.name === 'MessagePortMain';
|
|
371
|
-
};
|
|
372
|
-
|
|
373
|
-
const isOffscreenCanvas = value => {
|
|
374
|
-
return typeof OffscreenCanvas !== 'undefined' && value instanceof OffscreenCanvas;
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
const isInstanceOf = (value, constructorName) => {
|
|
378
|
-
return value?.constructor?.name === constructorName;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const isSocket = value => {
|
|
382
|
-
return isInstanceOf(value, 'Socket');
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
const transferrables = [isMessagePort, isMessagePortMain, isOffscreenCanvas, isSocket];
|
|
386
|
-
|
|
387
|
-
const isTransferrable = value => {
|
|
388
|
-
for (const fn of transferrables) {
|
|
389
|
-
if (fn(value)) {
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return false;
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
const getTransferrables = value => {
|
|
397
|
-
const transferrables = [];
|
|
398
|
-
walkValue(value, transferrables, isTransferrable);
|
|
399
|
-
return transferrables;
|
|
400
|
-
};
|
|
401
|
-
|
|
402
439
|
// @ts-ignore
|
|
403
440
|
const create$2 = async ({
|
|
404
441
|
path,
|
|
@@ -447,8 +484,11 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
|
|
|
447
484
|
this._rawIpc.postMessage(message);
|
|
448
485
|
}
|
|
449
486
|
sendAndTransfer(message) {
|
|
450
|
-
const
|
|
451
|
-
|
|
487
|
+
const {
|
|
488
|
+
newValue,
|
|
489
|
+
transfer
|
|
490
|
+
} = fixElectronParameters(message);
|
|
491
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
452
492
|
}
|
|
453
493
|
dispose() {
|
|
454
494
|
this._rawIpc.kill();
|
|
@@ -496,31 +536,6 @@ class ChildProcessError extends Error {
|
|
|
496
536
|
}
|
|
497
537
|
}
|
|
498
538
|
|
|
499
|
-
const removeValues = (value, toRemove) => {
|
|
500
|
-
if (!value) {
|
|
501
|
-
return value;
|
|
502
|
-
}
|
|
503
|
-
if (Array.isArray(value)) {
|
|
504
|
-
const newItems = [];
|
|
505
|
-
for (const item of value) {
|
|
506
|
-
if (!toRemove.includes(item)) {
|
|
507
|
-
newItems.push(removeValues(item, toRemove));
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
return newItems;
|
|
511
|
-
}
|
|
512
|
-
if (typeof value === 'object') {
|
|
513
|
-
const newObject = Object.create(null);
|
|
514
|
-
for (const [key, property] of Object.entries(value)) {
|
|
515
|
-
if (!toRemove.includes(property)) {
|
|
516
|
-
newObject[key] = removeValues(property, toRemove);
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
return newObject;
|
|
520
|
-
}
|
|
521
|
-
return value;
|
|
522
|
-
};
|
|
523
|
-
|
|
524
539
|
// workaround for node not supporting transferrable objects
|
|
525
540
|
// as parameters. If the transferrable object is a parameter,
|
|
526
541
|
// it is received as a plain object is received in the receiving process
|
package/dist/index.js
CHANGED
|
@@ -1014,8 +1014,11 @@ class IpcParentWithElectronUtilityProcess extends Ipc {
|
|
|
1014
1014
|
this._rawIpc.postMessage(message);
|
|
1015
1015
|
}
|
|
1016
1016
|
sendAndTransfer(message) {
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1017
|
+
const {
|
|
1018
|
+
newValue,
|
|
1019
|
+
transfer
|
|
1020
|
+
} = fixElectronParameters(message);
|
|
1021
|
+
this._rawIpc.postMessage(newValue, transfer);
|
|
1019
1022
|
}
|
|
1020
1023
|
dispose() {
|
|
1021
1024
|
this._rawIpc.kill();
|