@lvce-editor/embeds-process 4.3.0 → 4.5.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/embedsProcessMain.js +229 -206
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ const add = (id, ipc) => {
|
|
|
7
7
|
const get$2 = id => {
|
|
8
8
|
return ipcMap[id];
|
|
9
9
|
};
|
|
10
|
-
const remove$
|
|
10
|
+
const remove$2 = id => {
|
|
11
11
|
delete ipcMap[id];
|
|
12
12
|
};
|
|
13
13
|
const getAll = () => {
|
|
@@ -15,39 +15,7 @@ const getAll = () => {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
const MainProcess$2 = -5;
|
|
18
|
-
const SharedProcess$2 =
|
|
19
|
-
|
|
20
|
-
const rpcs = Object.create(null);
|
|
21
|
-
const set$5 = (id, rpc) => {
|
|
22
|
-
rpcs[id] = rpc;
|
|
23
|
-
};
|
|
24
|
-
const get$1 = id => {
|
|
25
|
-
return rpcs[id];
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const create$5 = rpcId => {
|
|
29
|
-
return {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
invoke(method, ...params) {
|
|
32
|
-
const rpc = get$1(rpcId);
|
|
33
|
-
// @ts-ignore
|
|
34
|
-
return rpc.invoke(method, ...params);
|
|
35
|
-
},
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
invokeAndTransfer(method, ...params) {
|
|
38
|
-
const rpc = get$1(rpcId);
|
|
39
|
-
// @ts-ignore
|
|
40
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
41
|
-
},
|
|
42
|
-
set(rpc) {
|
|
43
|
-
set$5(rpcId, rpc);
|
|
44
|
-
},
|
|
45
|
-
async dispose() {
|
|
46
|
-
const rpc = get$1(rpcId);
|
|
47
|
-
await rpc.dispose();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
};
|
|
18
|
+
const SharedProcess$2 = 1492;
|
|
51
19
|
|
|
52
20
|
const normalizeLine = line => {
|
|
53
21
|
if (line.startsWith('Error: ')) {
|
|
@@ -331,8 +299,8 @@ const getModuleNotFoundError = stderr => {
|
|
|
331
299
|
const messageIndex = lines.findIndex(isModuleNotFoundMessage);
|
|
332
300
|
const message = lines[messageIndex];
|
|
333
301
|
return {
|
|
334
|
-
|
|
335
|
-
|
|
302
|
+
code: ERR_MODULE_NOT_FOUND,
|
|
303
|
+
message
|
|
336
304
|
};
|
|
337
305
|
};
|
|
338
306
|
const isModuleNotFoundError = stderr => {
|
|
@@ -355,14 +323,14 @@ const isUnhelpfulNativeModuleError = stderr => {
|
|
|
355
323
|
const getNativeModuleErrorMessage = stderr => {
|
|
356
324
|
const message = getMessageCodeBlock(stderr);
|
|
357
325
|
return {
|
|
358
|
-
|
|
359
|
-
|
|
326
|
+
code: E_INCOMPATIBLE_NATIVE_MODULE,
|
|
327
|
+
message: `Incompatible native node module: ${message}`
|
|
360
328
|
};
|
|
361
329
|
};
|
|
362
330
|
const getModuleSyntaxError = () => {
|
|
363
331
|
return {
|
|
364
|
-
|
|
365
|
-
|
|
332
|
+
code: E_MODULES_NOT_SUPPORTED_IN_ELECTRON,
|
|
333
|
+
message: `ES Modules are not supported in electron`
|
|
366
334
|
};
|
|
367
335
|
};
|
|
368
336
|
const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
@@ -381,8 +349,8 @@ const getHelpfulChildProcessError = (stdout, stderr) => {
|
|
|
381
349
|
rest
|
|
382
350
|
} = getDetails(lines);
|
|
383
351
|
return {
|
|
384
|
-
message: actualMessage,
|
|
385
352
|
code: '',
|
|
353
|
+
message: actualMessage,
|
|
386
354
|
stack: rest
|
|
387
355
|
};
|
|
388
356
|
};
|
|
@@ -392,8 +360,8 @@ class IpcError extends VError {
|
|
|
392
360
|
if (stdout || stderr) {
|
|
393
361
|
// @ts-ignore
|
|
394
362
|
const {
|
|
395
|
-
message,
|
|
396
363
|
code,
|
|
364
|
+
message,
|
|
397
365
|
stack
|
|
398
366
|
} = getHelpfulChildProcessError(stdout, stderr);
|
|
399
367
|
const cause = new Error(message);
|
|
@@ -631,8 +599,8 @@ const removeListener = (emitter, type, callback) => {
|
|
|
631
599
|
};
|
|
632
600
|
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
633
601
|
const {
|
|
634
|
-
|
|
635
|
-
|
|
602
|
+
promise,
|
|
603
|
+
resolve
|
|
636
604
|
} = Promise.withResolvers();
|
|
637
605
|
const listenerMap = Object.create(null);
|
|
638
606
|
const cleanup = value => {
|
|
@@ -644,8 +612,8 @@ const getFirstEvent = (eventEmitter, eventMap) => {
|
|
|
644
612
|
for (const [event, type] of Object.entries(eventMap)) {
|
|
645
613
|
const listener = event => {
|
|
646
614
|
cleanup({
|
|
647
|
-
|
|
648
|
-
|
|
615
|
+
event,
|
|
616
|
+
type
|
|
649
617
|
});
|
|
650
618
|
};
|
|
651
619
|
addListener(eventEmitter, event, listener);
|
|
@@ -661,28 +629,28 @@ const getFirstWebSocketEvent = async webSocket => {
|
|
|
661
629
|
WebSocket
|
|
662
630
|
} = await import('ws');
|
|
663
631
|
switch (webSocket.readyState) {
|
|
664
|
-
case WebSocket.
|
|
632
|
+
case WebSocket.CLOSED:
|
|
665
633
|
return {
|
|
666
|
-
|
|
667
|
-
|
|
634
|
+
event: undefined,
|
|
635
|
+
type: Close
|
|
668
636
|
};
|
|
669
|
-
case WebSocket.
|
|
637
|
+
case WebSocket.OPEN:
|
|
670
638
|
return {
|
|
671
|
-
|
|
672
|
-
|
|
639
|
+
event: undefined,
|
|
640
|
+
type: Open
|
|
673
641
|
};
|
|
674
642
|
}
|
|
675
643
|
// @ts-ignore
|
|
676
644
|
const {
|
|
677
|
-
|
|
678
|
-
|
|
645
|
+
event,
|
|
646
|
+
type
|
|
679
647
|
} = await getFirstEvent(webSocket, {
|
|
680
|
-
|
|
681
|
-
|
|
648
|
+
close: Close,
|
|
649
|
+
open: Open
|
|
682
650
|
});
|
|
683
651
|
return {
|
|
684
|
-
|
|
685
|
-
|
|
652
|
+
event,
|
|
653
|
+
type
|
|
686
654
|
};
|
|
687
655
|
};
|
|
688
656
|
|
|
@@ -712,8 +680,8 @@ const handleUpgrade$1 = async (...args) => {
|
|
|
712
680
|
return module.handleUpgrade(...args);
|
|
713
681
|
};
|
|
714
682
|
const listen$1$1 = async ({
|
|
715
|
-
|
|
716
|
-
|
|
683
|
+
handle,
|
|
684
|
+
request
|
|
717
685
|
}) => {
|
|
718
686
|
if (!request) {
|
|
719
687
|
throw new IpcError('request must be defined');
|
|
@@ -733,14 +701,19 @@ const signal$4 = webSocket => {
|
|
|
733
701
|
};
|
|
734
702
|
const wrap$9 = webSocket => {
|
|
735
703
|
return {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
704
|
+
dispose() {
|
|
705
|
+
this.webSocket.close();
|
|
706
|
+
},
|
|
707
|
+
// @ts-ignore
|
|
708
|
+
off(event, listener) {
|
|
709
|
+
this.webSocket.off(event, listener);
|
|
710
|
+
},
|
|
741
711
|
// @ts-ignore
|
|
742
712
|
on(event, listener) {
|
|
743
713
|
switch (event) {
|
|
714
|
+
case 'close':
|
|
715
|
+
webSocket.on('close', listener);
|
|
716
|
+
break;
|
|
744
717
|
case 'message':
|
|
745
718
|
// @ts-ignore
|
|
746
719
|
const wrappedListener = message => {
|
|
@@ -753,28 +726,23 @@ const wrap$9 = webSocket => {
|
|
|
753
726
|
};
|
|
754
727
|
webSocket.on('message', wrappedListener);
|
|
755
728
|
break;
|
|
756
|
-
case 'close':
|
|
757
|
-
webSocket.on('close', listener);
|
|
758
|
-
break;
|
|
759
729
|
default:
|
|
760
730
|
throw new Error('unknown event listener type');
|
|
761
731
|
}
|
|
762
732
|
},
|
|
763
733
|
// @ts-ignore
|
|
764
|
-
off(event, listener) {
|
|
765
|
-
this.webSocket.off(event, listener);
|
|
766
|
-
},
|
|
767
|
-
// @ts-ignore
|
|
768
734
|
send(message) {
|
|
769
735
|
const stringifiedMessage = serialize(message);
|
|
770
736
|
this.webSocket.send(stringifiedMessage);
|
|
771
737
|
},
|
|
772
|
-
dispose() {
|
|
773
|
-
this.webSocket.close();
|
|
774
|
-
},
|
|
775
738
|
start() {
|
|
776
739
|
throw new Error('start method is deprecated');
|
|
777
|
-
}
|
|
740
|
+
},
|
|
741
|
+
webSocket,
|
|
742
|
+
/**
|
|
743
|
+
* @type {any}
|
|
744
|
+
*/
|
|
745
|
+
wrappedListener: undefined
|
|
778
746
|
};
|
|
779
747
|
};
|
|
780
748
|
const IpcChildWithWebSocket = {
|
|
@@ -784,56 +752,14 @@ const IpcChildWithWebSocket = {
|
|
|
784
752
|
wrap: wrap$9
|
|
785
753
|
};
|
|
786
754
|
|
|
787
|
-
const Two = '2.0';
|
|
788
|
-
const create$4 = (method, params) => {
|
|
789
|
-
return {
|
|
790
|
-
jsonrpc: Two,
|
|
791
|
-
method,
|
|
792
|
-
params
|
|
793
|
-
};
|
|
794
|
-
};
|
|
755
|
+
const Two$1 = '2.0';
|
|
795
756
|
const callbacks = Object.create(null);
|
|
796
|
-
const
|
|
797
|
-
callbacks[id] = fn;
|
|
798
|
-
};
|
|
799
|
-
const get = id => {
|
|
757
|
+
const get$1 = id => {
|
|
800
758
|
return callbacks[id];
|
|
801
759
|
};
|
|
802
|
-
const remove = id => {
|
|
760
|
+
const remove$1 = id => {
|
|
803
761
|
delete callbacks[id];
|
|
804
762
|
};
|
|
805
|
-
let id = 0;
|
|
806
|
-
const create$3 = () => {
|
|
807
|
-
return ++id;
|
|
808
|
-
};
|
|
809
|
-
const registerPromise = () => {
|
|
810
|
-
const id = create$3();
|
|
811
|
-
const {
|
|
812
|
-
resolve,
|
|
813
|
-
promise
|
|
814
|
-
} = Promise.withResolvers();
|
|
815
|
-
set$4(id, resolve);
|
|
816
|
-
return {
|
|
817
|
-
id,
|
|
818
|
-
promise
|
|
819
|
-
};
|
|
820
|
-
};
|
|
821
|
-
const create$2 = (method, params) => {
|
|
822
|
-
const {
|
|
823
|
-
id,
|
|
824
|
-
promise
|
|
825
|
-
} = registerPromise();
|
|
826
|
-
const message = {
|
|
827
|
-
jsonrpc: Two,
|
|
828
|
-
method,
|
|
829
|
-
params,
|
|
830
|
-
id
|
|
831
|
-
};
|
|
832
|
-
return {
|
|
833
|
-
message,
|
|
834
|
-
promise
|
|
835
|
-
};
|
|
836
|
-
};
|
|
837
763
|
class JsonRpcError extends Error {
|
|
838
764
|
constructor(message) {
|
|
839
765
|
super(message);
|
|
@@ -977,14 +903,14 @@ const warn = (...args) => {
|
|
|
977
903
|
console.warn(...args);
|
|
978
904
|
};
|
|
979
905
|
const resolve = (id, response) => {
|
|
980
|
-
const fn = get(id);
|
|
906
|
+
const fn = get$1(id);
|
|
981
907
|
if (!fn) {
|
|
982
908
|
console.log(response);
|
|
983
909
|
warn(`callback ${id} may already be disposed`);
|
|
984
910
|
return;
|
|
985
911
|
}
|
|
986
912
|
fn(response);
|
|
987
|
-
remove(id);
|
|
913
|
+
remove$1(id);
|
|
988
914
|
};
|
|
989
915
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
990
916
|
const getErrorType = prettyError => {
|
|
@@ -1029,7 +955,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
1029
955
|
};
|
|
1030
956
|
const create$1 = (id, error) => {
|
|
1031
957
|
return {
|
|
1032
|
-
jsonrpc: Two,
|
|
958
|
+
jsonrpc: Two$1,
|
|
1033
959
|
id,
|
|
1034
960
|
error
|
|
1035
961
|
};
|
|
@@ -1040,20 +966,20 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
1040
966
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
1041
967
|
return create$1(id, errorProperty);
|
|
1042
968
|
};
|
|
1043
|
-
const create = (message, result) => {
|
|
969
|
+
const create$2 = (message, result) => {
|
|
1044
970
|
return {
|
|
1045
|
-
jsonrpc: Two,
|
|
971
|
+
jsonrpc: Two$1,
|
|
1046
972
|
id: message.id,
|
|
1047
973
|
result: result ?? null
|
|
1048
974
|
};
|
|
1049
975
|
};
|
|
1050
976
|
const getSuccessResponse = (message, result) => {
|
|
1051
977
|
const resultProperty = result ?? null;
|
|
1052
|
-
return create(message, resultProperty);
|
|
978
|
+
return create$2(message, resultProperty);
|
|
1053
979
|
};
|
|
1054
980
|
const getErrorResponseSimple = (id, error) => {
|
|
1055
981
|
return {
|
|
1056
|
-
jsonrpc: Two,
|
|
982
|
+
jsonrpc: Two$1,
|
|
1057
983
|
id,
|
|
1058
984
|
error: {
|
|
1059
985
|
code: Custom,
|
|
@@ -1140,29 +1066,6 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
1140
1066
|
}
|
|
1141
1067
|
throw new JsonRpcError('unexpected message');
|
|
1142
1068
|
};
|
|
1143
|
-
const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
1144
|
-
const {
|
|
1145
|
-
message,
|
|
1146
|
-
promise
|
|
1147
|
-
} = create$2(method, params);
|
|
1148
|
-
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1149
|
-
ipc.sendAndTransfer(message);
|
|
1150
|
-
} else {
|
|
1151
|
-
ipc.send(message);
|
|
1152
|
-
}
|
|
1153
|
-
const responseMessage = await promise;
|
|
1154
|
-
return unwrapJsonRpcResult(responseMessage);
|
|
1155
|
-
};
|
|
1156
|
-
const send = (transport, method, ...params) => {
|
|
1157
|
-
const message = create$4(method, params);
|
|
1158
|
-
transport.send(message);
|
|
1159
|
-
};
|
|
1160
|
-
const invoke$3 = (ipc, method, ...params) => {
|
|
1161
|
-
return invokeHelper(ipc, method, params, false);
|
|
1162
|
-
};
|
|
1163
|
-
const invokeAndTransfer$2 = (ipc, method, ...params) => {
|
|
1164
|
-
return invokeHelper(ipc, method, params, true);
|
|
1165
|
-
};
|
|
1166
1069
|
|
|
1167
1070
|
class CommandNotFoundError extends Error {
|
|
1168
1071
|
constructor(command) {
|
|
@@ -1185,24 +1088,87 @@ const execute = (command, ...args) => {
|
|
|
1185
1088
|
return fn(...args);
|
|
1186
1089
|
};
|
|
1187
1090
|
|
|
1091
|
+
const Two = '2.0';
|
|
1092
|
+
const create$t = (method, params) => {
|
|
1093
|
+
return {
|
|
1094
|
+
jsonrpc: Two,
|
|
1095
|
+
method,
|
|
1096
|
+
params
|
|
1097
|
+
};
|
|
1098
|
+
};
|
|
1099
|
+
const create$s = (id, method, params) => {
|
|
1100
|
+
const message = {
|
|
1101
|
+
id,
|
|
1102
|
+
jsonrpc: Two,
|
|
1103
|
+
method,
|
|
1104
|
+
params
|
|
1105
|
+
};
|
|
1106
|
+
return message;
|
|
1107
|
+
};
|
|
1108
|
+
let id = 0;
|
|
1109
|
+
const create$r = () => {
|
|
1110
|
+
return ++id;
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
1114
|
+
|
|
1115
|
+
const registerPromise = map => {
|
|
1116
|
+
const id = create$r();
|
|
1117
|
+
const {
|
|
1118
|
+
promise,
|
|
1119
|
+
resolve
|
|
1120
|
+
} = Promise.withResolvers();
|
|
1121
|
+
map[id] = resolve;
|
|
1122
|
+
return {
|
|
1123
|
+
id,
|
|
1124
|
+
promise
|
|
1125
|
+
};
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
// @ts-ignore
|
|
1129
|
+
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
1130
|
+
const {
|
|
1131
|
+
id,
|
|
1132
|
+
promise
|
|
1133
|
+
} = registerPromise(callbacks);
|
|
1134
|
+
const message = create$s(id, method, params);
|
|
1135
|
+
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
1136
|
+
ipc.sendAndTransfer(message);
|
|
1137
|
+
} else {
|
|
1138
|
+
ipc.send(message);
|
|
1139
|
+
}
|
|
1140
|
+
const responseMessage = await promise;
|
|
1141
|
+
return unwrapJsonRpcResult(responseMessage);
|
|
1142
|
+
};
|
|
1188
1143
|
const createRpc = ipc => {
|
|
1144
|
+
const callbacks = Object.create(null);
|
|
1145
|
+
ipc._resolve = (id, response) => {
|
|
1146
|
+
const fn = callbacks[id];
|
|
1147
|
+
if (!fn) {
|
|
1148
|
+
console.warn(`callback ${id} may already be disposed`);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
fn(response);
|
|
1152
|
+
delete callbacks[id];
|
|
1153
|
+
};
|
|
1189
1154
|
const rpc = {
|
|
1155
|
+
async dispose() {
|
|
1156
|
+
await ipc?.dispose();
|
|
1157
|
+
},
|
|
1158
|
+
invoke(method, ...params) {
|
|
1159
|
+
return invokeHelper(callbacks, ipc, method, params, false);
|
|
1160
|
+
},
|
|
1161
|
+
invokeAndTransfer(method, ...params) {
|
|
1162
|
+
return invokeHelper(callbacks, ipc, method, params, true);
|
|
1163
|
+
},
|
|
1190
1164
|
// @ts-ignore
|
|
1191
1165
|
ipc,
|
|
1192
1166
|
/**
|
|
1193
1167
|
* @deprecated
|
|
1194
1168
|
*/
|
|
1195
1169
|
send(method, ...params) {
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
invoke(method, ...params) {
|
|
1199
|
-
return invoke$3(ipc, method, ...params);
|
|
1200
|
-
},
|
|
1201
|
-
invokeAndTransfer(method, ...params) {
|
|
1202
|
-
return invokeAndTransfer$2(ipc, method, ...params);
|
|
1203
|
-
},
|
|
1204
|
-
async dispose() {
|
|
1205
|
-
await ipc?.dispose();
|
|
1170
|
+
const message = create$t(method, params);
|
|
1171
|
+
ipc.send(message);
|
|
1206
1172
|
}
|
|
1207
1173
|
};
|
|
1208
1174
|
return rpc;
|
|
@@ -1219,7 +1185,7 @@ const logError = () => {
|
|
|
1219
1185
|
const handleMessage = event => {
|
|
1220
1186
|
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
1221
1187
|
const actualExecute = event?.target?.execute || execute;
|
|
1222
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute,
|
|
1188
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
1223
1189
|
};
|
|
1224
1190
|
const handleIpc = ipc => {
|
|
1225
1191
|
if ('addEventListener' in ipc) {
|
|
@@ -1237,7 +1203,7 @@ const listen$2 = async (module, options) => {
|
|
|
1237
1203
|
const ipc = module.wrap(rawIpc);
|
|
1238
1204
|
return ipc;
|
|
1239
1205
|
};
|
|
1240
|
-
const create$
|
|
1206
|
+
const create$q = async ({
|
|
1241
1207
|
commandMap,
|
|
1242
1208
|
messagePort,
|
|
1243
1209
|
requiresSocket
|
|
@@ -1256,9 +1222,9 @@ const create$k = async ({
|
|
|
1256
1222
|
};
|
|
1257
1223
|
const ElectronMessagePortRpcClient = {
|
|
1258
1224
|
__proto__: null,
|
|
1259
|
-
create: create$
|
|
1225
|
+
create: create$q
|
|
1260
1226
|
};
|
|
1261
|
-
const create$
|
|
1227
|
+
const create$p = async ({
|
|
1262
1228
|
commandMap
|
|
1263
1229
|
}) => {
|
|
1264
1230
|
// TODO create a commandMap per rpc instance
|
|
@@ -1270,7 +1236,7 @@ const create$j = async ({
|
|
|
1270
1236
|
};
|
|
1271
1237
|
const ElectronUtilityProcessRpcClient = {
|
|
1272
1238
|
__proto__: null,
|
|
1273
|
-
create: create$
|
|
1239
|
+
create: create$p
|
|
1274
1240
|
};
|
|
1275
1241
|
const create$a = async ({
|
|
1276
1242
|
commandMap
|
|
@@ -1288,15 +1254,15 @@ const NodeForkedProcessRpcClient = {
|
|
|
1288
1254
|
};
|
|
1289
1255
|
const create$8 = async ({
|
|
1290
1256
|
commandMap,
|
|
1291
|
-
request,
|
|
1292
1257
|
handle,
|
|
1258
|
+
request,
|
|
1293
1259
|
requiresSocket
|
|
1294
1260
|
}) => {
|
|
1295
1261
|
// TODO create a commandMap per rpc instance
|
|
1296
1262
|
register(commandMap);
|
|
1297
1263
|
const ipc = await listen$2(IpcChildWithWebSocket, {
|
|
1298
|
-
|
|
1299
|
-
|
|
1264
|
+
handle,
|
|
1265
|
+
request
|
|
1300
1266
|
});
|
|
1301
1267
|
if (requiresSocket) {
|
|
1302
1268
|
ipc.requiresSocket = requiresSocket;
|
|
@@ -1323,34 +1289,91 @@ const NodeWorkerRpcClient = {
|
|
|
1323
1289
|
__proto__: null,
|
|
1324
1290
|
create: create$7
|
|
1325
1291
|
};
|
|
1292
|
+
const createMockRpc = ({
|
|
1293
|
+
commandMap
|
|
1294
|
+
}) => {
|
|
1295
|
+
const invocations = [];
|
|
1296
|
+
const invoke = (method, ...params) => {
|
|
1297
|
+
invocations.push([method, ...params]);
|
|
1298
|
+
const command = commandMap[method];
|
|
1299
|
+
if (!command) {
|
|
1300
|
+
throw new Error(`command ${method} not found`);
|
|
1301
|
+
}
|
|
1302
|
+
return command(...params);
|
|
1303
|
+
};
|
|
1304
|
+
const mockRpc = {
|
|
1305
|
+
invocations,
|
|
1306
|
+
invoke,
|
|
1307
|
+
invokeAndTransfer: invoke
|
|
1308
|
+
};
|
|
1309
|
+
return mockRpc;
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
const rpcs = Object.create(null);
|
|
1313
|
+
const set$4 = (id, rpc) => {
|
|
1314
|
+
rpcs[id] = rpc;
|
|
1315
|
+
};
|
|
1316
|
+
const get = id => {
|
|
1317
|
+
return rpcs[id];
|
|
1318
|
+
};
|
|
1319
|
+
const remove = id => {
|
|
1320
|
+
delete rpcs[id];
|
|
1321
|
+
};
|
|
1322
|
+
|
|
1323
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
1324
|
+
const create = rpcId => {
|
|
1325
|
+
return {
|
|
1326
|
+
async dispose() {
|
|
1327
|
+
const rpc = get(rpcId);
|
|
1328
|
+
await rpc.dispose();
|
|
1329
|
+
},
|
|
1330
|
+
// @ts-ignore
|
|
1331
|
+
invoke(method, ...params) {
|
|
1332
|
+
const rpc = get(rpcId);
|
|
1333
|
+
// @ts-ignore
|
|
1334
|
+
return rpc.invoke(method, ...params);
|
|
1335
|
+
},
|
|
1336
|
+
// @ts-ignore
|
|
1337
|
+
invokeAndTransfer(method, ...params) {
|
|
1338
|
+
const rpc = get(rpcId);
|
|
1339
|
+
// @ts-ignore
|
|
1340
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1341
|
+
},
|
|
1342
|
+
registerMockRpc(commandMap) {
|
|
1343
|
+
const mockRpc = createMockRpc({
|
|
1344
|
+
commandMap
|
|
1345
|
+
});
|
|
1346
|
+
set$4(rpcId, mockRpc);
|
|
1347
|
+
// @ts-ignore
|
|
1348
|
+
mockRpc[Symbol.dispose] = () => {
|
|
1349
|
+
remove(rpcId);
|
|
1350
|
+
};
|
|
1351
|
+
// @ts-ignore
|
|
1352
|
+
return mockRpc;
|
|
1353
|
+
},
|
|
1354
|
+
set(rpc) {
|
|
1355
|
+
set$4(rpcId, rpc);
|
|
1356
|
+
}
|
|
1357
|
+
};
|
|
1358
|
+
};
|
|
1326
1359
|
|
|
1327
1360
|
const {
|
|
1328
|
-
invoke: invoke$
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
dispose: dispose$2
|
|
1332
|
-
} = create$5(MainProcess$2);
|
|
1361
|
+
invoke: invoke$1,
|
|
1362
|
+
set: set$3
|
|
1363
|
+
} = create(MainProcess$2);
|
|
1333
1364
|
|
|
1334
1365
|
const MainProcess$1 = {
|
|
1335
1366
|
__proto__: null,
|
|
1336
|
-
|
|
1337
|
-
invoke: invoke$2,
|
|
1338
|
-
invokeAndTransfer: invokeAndTransfer$1,
|
|
1367
|
+
invoke: invoke$1,
|
|
1339
1368
|
set: set$3
|
|
1340
1369
|
};
|
|
1341
1370
|
|
|
1342
1371
|
const {
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
set: set$2,
|
|
1346
|
-
dispose: dispose$1
|
|
1347
|
-
} = create$5(SharedProcess$2);
|
|
1372
|
+
set: set$2
|
|
1373
|
+
} = create(SharedProcess$2);
|
|
1348
1374
|
|
|
1349
1375
|
const SharedProcess$1 = {
|
|
1350
1376
|
__proto__: null,
|
|
1351
|
-
dispose: dispose$1,
|
|
1352
|
-
invoke: invoke$1,
|
|
1353
|
-
invokeAndTransfer,
|
|
1354
1377
|
set: set$2
|
|
1355
1378
|
};
|
|
1356
1379
|
|
|
@@ -1461,8 +1484,8 @@ const handleIncomingIpcMessagePort = async (module, handle, message) => {
|
|
|
1461
1484
|
const target = await module.targetMessagePort(handle, message);
|
|
1462
1485
|
const response = module.upgradeMessagePort(handle, message);
|
|
1463
1486
|
return {
|
|
1464
|
-
|
|
1465
|
-
|
|
1487
|
+
response,
|
|
1488
|
+
target
|
|
1466
1489
|
};
|
|
1467
1490
|
};
|
|
1468
1491
|
|
|
@@ -1481,7 +1504,7 @@ const getIdsToDispose = ipc => {
|
|
|
1481
1504
|
const handleIpcClosed = async event => {
|
|
1482
1505
|
const idsToDispose = getIdsToDispose(event.target);
|
|
1483
1506
|
for (const id of idsToDispose) {
|
|
1484
|
-
remove$
|
|
1507
|
+
remove$2(id);
|
|
1485
1508
|
await disposeWebContentsView(id);
|
|
1486
1509
|
}
|
|
1487
1510
|
// SharedProcessIpc.send('HandleMessagePortForEmbedsProcess.handleEmbedsProcessIpcClosed')
|
|
@@ -1507,14 +1530,14 @@ const Auto = argv => {
|
|
|
1507
1530
|
|
|
1508
1531
|
const getModule$1 = method => {
|
|
1509
1532
|
switch (method) {
|
|
1533
|
+
case ElectronMessagePort:
|
|
1534
|
+
return ElectronMessagePortRpcClient.create;
|
|
1535
|
+
case ElectronUtilityProcess:
|
|
1536
|
+
return ElectronUtilityProcessRpcClient.create;
|
|
1510
1537
|
case NodeForkedProcess:
|
|
1511
1538
|
return NodeForkedProcessRpcClient.create;
|
|
1512
1539
|
case NodeWorker:
|
|
1513
1540
|
return NodeWorkerRpcClient.create;
|
|
1514
|
-
case ElectronUtilityProcess:
|
|
1515
|
-
return ElectronUtilityProcessRpcClient.create;
|
|
1516
|
-
case ElectronMessagePort:
|
|
1517
|
-
return ElectronMessagePortRpcClient.create;
|
|
1518
1541
|
case WebSocket:
|
|
1519
1542
|
return NodeWebSocketRpcClient.create;
|
|
1520
1543
|
default:
|
|
@@ -1534,9 +1557,9 @@ const listen$1 = async ({
|
|
|
1534
1557
|
const targetMessagePort$2 = async (messagePort, message) => {
|
|
1535
1558
|
object(messagePort);
|
|
1536
1559
|
const rpc = await listen$1({
|
|
1537
|
-
|
|
1560
|
+
commandMap: commandMapRef,
|
|
1538
1561
|
messagePort,
|
|
1539
|
-
|
|
1562
|
+
method: ElectronMessagePort
|
|
1540
1563
|
});
|
|
1541
1564
|
// @ts-ignore
|
|
1542
1565
|
const {
|
|
@@ -1560,8 +1583,8 @@ const HandleIpcEmbedsWorker = {
|
|
|
1560
1583
|
const targetMessagePort$1 = async (messagePort, message) => {
|
|
1561
1584
|
object(messagePort);
|
|
1562
1585
|
const rpc = await listen$1({
|
|
1563
|
-
|
|
1564
|
-
|
|
1586
|
+
messagePort,
|
|
1587
|
+
method: ElectronMessagePort
|
|
1565
1588
|
});
|
|
1566
1589
|
set$1(rpc);
|
|
1567
1590
|
return rpc;
|
|
@@ -1585,8 +1608,8 @@ const {
|
|
|
1585
1608
|
const targetMessagePort = async (messagePort, message) => {
|
|
1586
1609
|
object(messagePort);
|
|
1587
1610
|
const rpc = await ElectronMessagePortRpcClient.create({
|
|
1588
|
-
|
|
1589
|
-
|
|
1611
|
+
commandMap: commandMapRef,
|
|
1612
|
+
messagePort
|
|
1590
1613
|
});
|
|
1591
1614
|
set(rpc);
|
|
1592
1615
|
return rpc;
|
|
@@ -1612,16 +1635,16 @@ const EmbedsWorkerAlt = 208;
|
|
|
1612
1635
|
const getModule = ipcId => {
|
|
1613
1636
|
number(ipcId);
|
|
1614
1637
|
switch (ipcId) {
|
|
1615
|
-
case SharedProcess:
|
|
1616
|
-
case SharedProcessAlt:
|
|
1617
|
-
return HandleIpcSharedProcess;
|
|
1618
|
-
// deprecated
|
|
1619
1638
|
case EmbedsWorker:
|
|
1620
1639
|
case EmbedsWorkerAlt:
|
|
1621
1640
|
return HandleIpcEmbedsWorker;
|
|
1622
1641
|
case MainProcess:
|
|
1623
1642
|
return HandleIpcMainProcess;
|
|
1624
1643
|
// deprecated
|
|
1644
|
+
case SharedProcess:
|
|
1645
|
+
case SharedProcessAlt:
|
|
1646
|
+
return HandleIpcSharedProcess;
|
|
1647
|
+
// deprecated
|
|
1625
1648
|
default:
|
|
1626
1649
|
throw new Error(`Embeds process encountered unexpected incoming ipc ${ipcId}`);
|
|
1627
1650
|
}
|
|
@@ -1634,8 +1657,8 @@ const handleIncomingIpc = async (ipcId, handle, message) => {
|
|
|
1634
1657
|
number(ipcId);
|
|
1635
1658
|
const module = getModule(ipcId);
|
|
1636
1659
|
const {
|
|
1637
|
-
|
|
1638
|
-
|
|
1660
|
+
response,
|
|
1661
|
+
target
|
|
1639
1662
|
} = await getIpcAndResponse(module, handle, message);
|
|
1640
1663
|
await applyIncomingIpcResponse(target, response);
|
|
1641
1664
|
};
|
|
@@ -1694,8 +1717,8 @@ const commandMap = {
|
|
|
1694
1717
|
const listen = async argv => {
|
|
1695
1718
|
Object.assign(commandMapRef, commandMap);
|
|
1696
1719
|
await listen$1({
|
|
1697
|
-
|
|
1698
|
-
|
|
1720
|
+
commandMap: commandMap,
|
|
1721
|
+
method: Auto(argv)
|
|
1699
1722
|
});
|
|
1700
1723
|
};
|
|
1701
1724
|
|