@lvce-editor/extension-management-worker 1.4.0 → 1.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.
|
@@ -368,6 +368,9 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
368
368
|
listen: listen$6,
|
|
369
369
|
wrap: wrap$e
|
|
370
370
|
};
|
|
371
|
+
const Error$3 = 1;
|
|
372
|
+
const Open = 2;
|
|
373
|
+
const Close = 3;
|
|
371
374
|
const addListener = (emitter, type, callback) => {
|
|
372
375
|
if ('addEventListener' in emitter) {
|
|
373
376
|
emitter.addEventListener(type, callback);
|
|
@@ -462,9 +465,69 @@ const IpcParentWithMessagePort$1 = {
|
|
|
462
465
|
signal: signal$1,
|
|
463
466
|
wrap: wrap$5
|
|
464
467
|
};
|
|
468
|
+
const stringifyCompact = value => {
|
|
469
|
+
return JSON.stringify(value);
|
|
470
|
+
};
|
|
471
|
+
const parse = content => {
|
|
472
|
+
if (content === 'undefined') {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
return JSON.parse(content);
|
|
477
|
+
} catch (error) {
|
|
478
|
+
throw new VError(error, 'failed to parse json');
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
const waitForWebSocketToBeOpen = webSocket => {
|
|
482
|
+
return getFirstEvent(webSocket, {
|
|
483
|
+
open: Open,
|
|
484
|
+
close: Close,
|
|
485
|
+
error: Error$3
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
const create$7 = async ({
|
|
489
|
+
webSocket
|
|
490
|
+
}) => {
|
|
491
|
+
const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
|
|
492
|
+
if (firstWebSocketEvent.type === Error$3) {
|
|
493
|
+
throw new IpcError(`WebSocket connection error`);
|
|
494
|
+
}
|
|
495
|
+
if (firstWebSocketEvent.type === Close) {
|
|
496
|
+
throw new IpcError('Websocket connection was immediately closed');
|
|
497
|
+
}
|
|
498
|
+
return webSocket;
|
|
499
|
+
};
|
|
500
|
+
class IpcParentWithWebSocket extends Ipc {
|
|
501
|
+
getData(event) {
|
|
502
|
+
return parse(event.data);
|
|
503
|
+
}
|
|
504
|
+
send(message) {
|
|
505
|
+
this._rawIpc.send(stringifyCompact(message));
|
|
506
|
+
}
|
|
507
|
+
sendAndTransfer(message) {
|
|
508
|
+
throw new Error('sendAndTransfer not supported');
|
|
509
|
+
}
|
|
510
|
+
dispose() {
|
|
511
|
+
this._rawIpc.close();
|
|
512
|
+
}
|
|
513
|
+
onClose(callback) {
|
|
514
|
+
this._rawIpc.addEventListener('close', callback);
|
|
515
|
+
}
|
|
516
|
+
onMessage(callback) {
|
|
517
|
+
this._rawIpc.addEventListener('message', callback);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const wrap = webSocket => {
|
|
521
|
+
return new IpcParentWithWebSocket(webSocket);
|
|
522
|
+
};
|
|
523
|
+
const IpcParentWithWebSocket$1 = {
|
|
524
|
+
__proto__: null,
|
|
525
|
+
create: create$7,
|
|
526
|
+
wrap
|
|
527
|
+
};
|
|
465
528
|
|
|
466
529
|
const Two = '2.0';
|
|
467
|
-
const create$4 = (method, params) => {
|
|
530
|
+
const create$4$1 = (method, params) => {
|
|
468
531
|
return {
|
|
469
532
|
jsonrpc: Two,
|
|
470
533
|
method,
|
|
@@ -472,7 +535,7 @@ const create$4 = (method, params) => {
|
|
|
472
535
|
};
|
|
473
536
|
};
|
|
474
537
|
const callbacks = Object.create(null);
|
|
475
|
-
const set$
|
|
538
|
+
const set$4 = (id, fn) => {
|
|
476
539
|
callbacks[id] = fn;
|
|
477
540
|
};
|
|
478
541
|
const get$2 = id => {
|
|
@@ -482,22 +545,22 @@ const remove = id => {
|
|
|
482
545
|
delete callbacks[id];
|
|
483
546
|
};
|
|
484
547
|
let id = 0;
|
|
485
|
-
const create$3 = () => {
|
|
548
|
+
const create$3$1 = () => {
|
|
486
549
|
return ++id;
|
|
487
550
|
};
|
|
488
551
|
const registerPromise = () => {
|
|
489
|
-
const id = create$3();
|
|
552
|
+
const id = create$3$1();
|
|
490
553
|
const {
|
|
491
554
|
resolve,
|
|
492
555
|
promise
|
|
493
556
|
} = Promise.withResolvers();
|
|
494
|
-
set$
|
|
557
|
+
set$4(id, resolve);
|
|
495
558
|
return {
|
|
496
559
|
id,
|
|
497
560
|
promise
|
|
498
561
|
};
|
|
499
562
|
};
|
|
500
|
-
const create$2 = (method, params) => {
|
|
563
|
+
const create$2$1 = (method, params) => {
|
|
501
564
|
const {
|
|
502
565
|
id,
|
|
503
566
|
promise
|
|
@@ -823,7 +886,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
823
886
|
const {
|
|
824
887
|
message,
|
|
825
888
|
promise
|
|
826
|
-
} = create$2(method, params);
|
|
889
|
+
} = create$2$1(method, params);
|
|
827
890
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
828
891
|
ipc.sendAndTransfer(message);
|
|
829
892
|
} else {
|
|
@@ -833,13 +896,13 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
833
896
|
return unwrapJsonRpcResult(responseMessage);
|
|
834
897
|
};
|
|
835
898
|
const send = (transport, method, ...params) => {
|
|
836
|
-
const message = create$4(method, params);
|
|
899
|
+
const message = create$4$1(method, params);
|
|
837
900
|
transport.send(message);
|
|
838
901
|
};
|
|
839
902
|
const invoke$2 = (ipc, method, ...params) => {
|
|
840
903
|
return invokeHelper(ipc, method, params, false);
|
|
841
904
|
};
|
|
842
|
-
const invokeAndTransfer = (ipc, method, ...params) => {
|
|
905
|
+
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
843
906
|
return invokeHelper(ipc, method, params, true);
|
|
844
907
|
};
|
|
845
908
|
|
|
@@ -878,7 +941,7 @@ const createRpc = ipc => {
|
|
|
878
941
|
return invoke$2(ipc, method, ...params);
|
|
879
942
|
},
|
|
880
943
|
invokeAndTransfer(method, ...params) {
|
|
881
|
-
return invokeAndTransfer(ipc, method, ...params);
|
|
944
|
+
return invokeAndTransfer$1(ipc, method, ...params);
|
|
882
945
|
},
|
|
883
946
|
async dispose() {
|
|
884
947
|
await ipc?.dispose();
|
|
@@ -936,7 +999,73 @@ const PlainMessagePortRpc = {
|
|
|
936
999
|
__proto__: null,
|
|
937
1000
|
create: create$5
|
|
938
1001
|
};
|
|
1002
|
+
const create$3 = async ({
|
|
1003
|
+
commandMap,
|
|
1004
|
+
send
|
|
1005
|
+
}) => {
|
|
1006
|
+
const {
|
|
1007
|
+
port1,
|
|
1008
|
+
port2
|
|
1009
|
+
} = new MessageChannel();
|
|
1010
|
+
await send(port1);
|
|
1011
|
+
return create$5({
|
|
1012
|
+
commandMap,
|
|
1013
|
+
messagePort: port2
|
|
1014
|
+
});
|
|
1015
|
+
};
|
|
1016
|
+
const TransferMessagePortRpcParent = {
|
|
1017
|
+
__proto__: null,
|
|
1018
|
+
create: create$3
|
|
1019
|
+
};
|
|
1020
|
+
const create$2 = async ({
|
|
1021
|
+
commandMap,
|
|
1022
|
+
webSocket
|
|
1023
|
+
}) => {
|
|
1024
|
+
// TODO create a commandMap per rpc instance
|
|
1025
|
+
register(commandMap);
|
|
1026
|
+
const rawIpc = await IpcParentWithWebSocket$1.create({
|
|
1027
|
+
webSocket
|
|
1028
|
+
});
|
|
1029
|
+
const ipc = IpcParentWithWebSocket$1.wrap(rawIpc);
|
|
1030
|
+
handleIpc(ipc);
|
|
1031
|
+
const rpc = createRpc(ipc);
|
|
1032
|
+
return rpc;
|
|
1033
|
+
};
|
|
1034
|
+
const Https = 'https:';
|
|
1035
|
+
const Ws = 'ws:';
|
|
1036
|
+
const Wss = 'wss:';
|
|
1037
|
+
const getWebSocketProtocol = locationProtocol => {
|
|
1038
|
+
return locationProtocol === Https ? Wss : Ws;
|
|
1039
|
+
};
|
|
1040
|
+
const getWebSocketUrl = (type, host, locationProtocol) => {
|
|
1041
|
+
const wsProtocol = getWebSocketProtocol(locationProtocol);
|
|
1042
|
+
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
1043
|
+
};
|
|
1044
|
+
const getHost = () => {
|
|
1045
|
+
return location.host;
|
|
1046
|
+
};
|
|
1047
|
+
const getProtocol = () => {
|
|
1048
|
+
return location.protocol;
|
|
1049
|
+
};
|
|
939
1050
|
const create$1 = async ({
|
|
1051
|
+
commandMap,
|
|
1052
|
+
type
|
|
1053
|
+
}) => {
|
|
1054
|
+
const host = getHost();
|
|
1055
|
+
const protocol = getProtocol();
|
|
1056
|
+
const wsUrl = getWebSocketUrl(type, host, protocol);
|
|
1057
|
+
const webSocket = new WebSocket(wsUrl);
|
|
1058
|
+
const rpc = await create$2({
|
|
1059
|
+
webSocket,
|
|
1060
|
+
commandMap
|
|
1061
|
+
});
|
|
1062
|
+
return rpc;
|
|
1063
|
+
};
|
|
1064
|
+
const WebSocketRpcParent2 = {
|
|
1065
|
+
__proto__: null,
|
|
1066
|
+
create: create$1
|
|
1067
|
+
};
|
|
1068
|
+
const create$4 = async ({
|
|
940
1069
|
commandMap
|
|
941
1070
|
}) => {
|
|
942
1071
|
// TODO create a commandMap per rpc instance
|
|
@@ -948,14 +1077,17 @@ const create$1 = async ({
|
|
|
948
1077
|
};
|
|
949
1078
|
const WebWorkerRpcClient = {
|
|
950
1079
|
__proto__: null,
|
|
951
|
-
create: create$
|
|
1080
|
+
create: create$4
|
|
952
1081
|
};
|
|
953
1082
|
|
|
1083
|
+
const Electron = 2;
|
|
1084
|
+
const Remote = 3;
|
|
1085
|
+
|
|
954
1086
|
const RendererWorker = 1;
|
|
955
1087
|
const SharedProcess = 1;
|
|
956
1088
|
|
|
957
1089
|
const rpcs = Object.create(null);
|
|
958
|
-
const set$
|
|
1090
|
+
const set$3 = (id, rpc) => {
|
|
959
1091
|
rpcs[id] = rpc;
|
|
960
1092
|
};
|
|
961
1093
|
const get$1 = id => {
|
|
@@ -981,33 +1113,49 @@ const create = rpcId => {
|
|
|
981
1113
|
return rpc.invokeAndTransfer(method, ...params);
|
|
982
1114
|
},
|
|
983
1115
|
set(rpc) {
|
|
984
|
-
set$
|
|
1116
|
+
set$3(rpcId, rpc);
|
|
985
1117
|
}
|
|
986
1118
|
};
|
|
987
1119
|
};
|
|
988
1120
|
|
|
989
1121
|
const {
|
|
990
1122
|
invoke: invoke$1,
|
|
991
|
-
|
|
1123
|
+
invokeAndTransfer,
|
|
1124
|
+
set: set$2
|
|
992
1125
|
} = create(RendererWorker);
|
|
1126
|
+
const sendMessagePortToSharedProcess = async port => {
|
|
1127
|
+
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1128
|
+
// @ts-ignore
|
|
1129
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1130
|
+
};
|
|
993
1131
|
const getExtension$1 = async id => {
|
|
994
1132
|
// @ts-ignore
|
|
995
1133
|
return invoke$1('ExtensionManagement.getExtension', id);
|
|
996
1134
|
};
|
|
997
1135
|
|
|
998
1136
|
const {
|
|
999
|
-
invoke
|
|
1137
|
+
invoke,
|
|
1138
|
+
set: set$1
|
|
1139
|
+
} = create(SharedProcess);
|
|
1000
1140
|
|
|
1001
1141
|
const invalidateExtensionsCache = async () => {
|
|
1002
1142
|
await invoke$1('ExtensionManagement.invalidateExtensionsCache');
|
|
1003
1143
|
};
|
|
1004
1144
|
|
|
1005
1145
|
let state = {
|
|
1006
|
-
disabledIds: []
|
|
1146
|
+
disabledIds: [],
|
|
1147
|
+
platform: 0
|
|
1007
1148
|
};
|
|
1008
1149
|
const set = newState => {
|
|
1009
1150
|
state = newState;
|
|
1010
1151
|
};
|
|
1152
|
+
const update = newState => {
|
|
1153
|
+
const fullNewState = {
|
|
1154
|
+
...state,
|
|
1155
|
+
...newState
|
|
1156
|
+
};
|
|
1157
|
+
state = fullNewState;
|
|
1158
|
+
};
|
|
1011
1159
|
const get = () => {
|
|
1012
1160
|
return state;
|
|
1013
1161
|
};
|
|
@@ -1041,7 +1189,7 @@ const enableExtension = async (id, isTest) => {
|
|
|
1041
1189
|
};
|
|
1042
1190
|
set(newState);
|
|
1043
1191
|
} else {
|
|
1044
|
-
await invoke('ExtensionManagement.enable',
|
|
1192
|
+
await invoke('ExtensionManagement.enable', id);
|
|
1045
1193
|
}
|
|
1046
1194
|
await invalidateExtensionsCache();
|
|
1047
1195
|
return undefined;
|
|
@@ -1065,8 +1213,38 @@ const handleMessagePort = async port => {
|
|
|
1065
1213
|
});
|
|
1066
1214
|
};
|
|
1067
1215
|
|
|
1068
|
-
const
|
|
1216
|
+
const getRpc = async platform => {
|
|
1069
1217
|
// TODO create connection to shared process
|
|
1218
|
+
if (platform === Remote) {
|
|
1219
|
+
const rpc = await WebSocketRpcParent2.create({
|
|
1220
|
+
commandMap: commandMapRef,
|
|
1221
|
+
type: 'shared-process'
|
|
1222
|
+
});
|
|
1223
|
+
return rpc;
|
|
1224
|
+
}
|
|
1225
|
+
if (platform === Electron) {
|
|
1226
|
+
const rpc = TransferMessagePortRpcParent.create({
|
|
1227
|
+
commandMap: commandMapRef,
|
|
1228
|
+
async send(port) {
|
|
1229
|
+
await sendMessagePortToSharedProcess(port);
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
return rpc;
|
|
1233
|
+
}
|
|
1234
|
+
return undefined;
|
|
1235
|
+
};
|
|
1236
|
+
const initializeSharedProcess = async platform => {
|
|
1237
|
+
const rpc = await getRpc(platform);
|
|
1238
|
+
if (rpc) {
|
|
1239
|
+
set$1(rpc);
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
const initialize = async platform => {
|
|
1244
|
+
update({
|
|
1245
|
+
platform
|
|
1246
|
+
});
|
|
1247
|
+
await initializeSharedProcess(platform);
|
|
1070
1248
|
};
|
|
1071
1249
|
|
|
1072
1250
|
const installExtension = async () => {
|
|
@@ -1092,7 +1270,7 @@ const listen = async () => {
|
|
|
1092
1270
|
const rpc = await WebWorkerRpcClient.create({
|
|
1093
1271
|
commandMap: commandMap
|
|
1094
1272
|
});
|
|
1095
|
-
set$
|
|
1273
|
+
set$2(rpc);
|
|
1096
1274
|
};
|
|
1097
1275
|
|
|
1098
1276
|
const main = async () => {
|