@lvce-editor/update-worker 2.8.0 → 2.9.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/updateWorkerMain.js +199 -12
- package/package.json +1 -1
package/dist/updateWorkerMain.js
CHANGED
|
@@ -368,6 +368,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
368
368
|
listen: listen$6,
|
|
369
369
|
wrap: wrap$e
|
|
370
370
|
};
|
|
371
|
+
const addListener = (emitter, type, callback) => {
|
|
372
|
+
if ('addEventListener' in emitter) {
|
|
373
|
+
emitter.addEventListener(type, callback);
|
|
374
|
+
} else {
|
|
375
|
+
emitter.on(type, callback);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const removeListener = (emitter, type, callback) => {
|
|
379
|
+
if ('removeEventListener' in emitter) {
|
|
380
|
+
emitter.removeEventListener(type, callback);
|
|
381
|
+
} else {
|
|
382
|
+
emitter.off(type, callback);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
386
|
+
const {
|
|
387
|
+
promise,
|
|
388
|
+
resolve
|
|
389
|
+
} = Promise.withResolvers();
|
|
390
|
+
const listenerMap = Object.create(null);
|
|
391
|
+
const cleanup = value => {
|
|
392
|
+
for (const event of Object.keys(eventMap)) {
|
|
393
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
394
|
+
}
|
|
395
|
+
resolve(value);
|
|
396
|
+
};
|
|
397
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
398
|
+
const listener = event => {
|
|
399
|
+
cleanup({
|
|
400
|
+
event,
|
|
401
|
+
type
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
addListener(eventEmitter, event, listener);
|
|
405
|
+
listenerMap[event] = listener;
|
|
406
|
+
}
|
|
407
|
+
return promise;
|
|
408
|
+
};
|
|
409
|
+
const Message$1 = 3;
|
|
410
|
+
const create$5$1 = async ({
|
|
411
|
+
isMessagePortOpen,
|
|
412
|
+
messagePort
|
|
413
|
+
}) => {
|
|
414
|
+
if (!isMessagePort(messagePort)) {
|
|
415
|
+
throw new IpcError('port must be of type MessagePort');
|
|
416
|
+
}
|
|
417
|
+
if (isMessagePortOpen) {
|
|
418
|
+
return messagePort;
|
|
419
|
+
}
|
|
420
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
421
|
+
message: Message$1
|
|
422
|
+
});
|
|
423
|
+
messagePort.start();
|
|
424
|
+
const {
|
|
425
|
+
event,
|
|
426
|
+
type
|
|
427
|
+
} = await eventPromise;
|
|
428
|
+
if (type !== Message$1) {
|
|
429
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
430
|
+
}
|
|
431
|
+
if (event.data !== readyMessage) {
|
|
432
|
+
throw new IpcError('unexpected first message');
|
|
433
|
+
}
|
|
434
|
+
return messagePort;
|
|
435
|
+
};
|
|
436
|
+
const signal$1 = messagePort => {
|
|
437
|
+
messagePort.start();
|
|
438
|
+
};
|
|
439
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
440
|
+
getData = getData$2;
|
|
441
|
+
send(message) {
|
|
442
|
+
this._rawIpc.postMessage(message);
|
|
443
|
+
}
|
|
444
|
+
sendAndTransfer(message) {
|
|
445
|
+
const transfer = getTransferrables(message);
|
|
446
|
+
this._rawIpc.postMessage(message, transfer);
|
|
447
|
+
}
|
|
448
|
+
dispose() {
|
|
449
|
+
this._rawIpc.close();
|
|
450
|
+
}
|
|
451
|
+
onMessage(callback) {
|
|
452
|
+
this._rawIpc.addEventListener('message', callback);
|
|
453
|
+
}
|
|
454
|
+
onClose(callback) {}
|
|
455
|
+
}
|
|
456
|
+
const wrap$5 = messagePort => {
|
|
457
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
458
|
+
};
|
|
459
|
+
const IpcParentWithMessagePort$1 = {
|
|
460
|
+
__proto__: null,
|
|
461
|
+
create: create$5$1,
|
|
462
|
+
signal: signal$1,
|
|
463
|
+
wrap: wrap$5
|
|
464
|
+
};
|
|
371
465
|
|
|
372
466
|
class CommandNotFoundError extends Error {
|
|
373
467
|
constructor(command) {
|
|
@@ -604,7 +698,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
604
698
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
605
699
|
return create$1$1(id, errorProperty);
|
|
606
700
|
};
|
|
607
|
-
const create$
|
|
701
|
+
const create$8 = (message, result) => {
|
|
608
702
|
return {
|
|
609
703
|
id: message.id,
|
|
610
704
|
jsonrpc: Two$1,
|
|
@@ -613,7 +707,7 @@ const create$5 = (message, result) => {
|
|
|
613
707
|
};
|
|
614
708
|
const getSuccessResponse = (message, result) => {
|
|
615
709
|
const resultProperty = result ?? null;
|
|
616
|
-
return create$
|
|
710
|
+
return create$8(message, resultProperty);
|
|
617
711
|
};
|
|
618
712
|
const getErrorResponseSimple = (id, error) => {
|
|
619
713
|
return {
|
|
@@ -707,7 +801,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
707
801
|
|
|
708
802
|
const Two = '2.0';
|
|
709
803
|
|
|
710
|
-
const create$
|
|
804
|
+
const create$7 = (method, params) => {
|
|
711
805
|
return {
|
|
712
806
|
jsonrpc: Two,
|
|
713
807
|
method,
|
|
@@ -715,7 +809,7 @@ const create$4 = (method, params) => {
|
|
|
715
809
|
};
|
|
716
810
|
};
|
|
717
811
|
|
|
718
|
-
const create$
|
|
812
|
+
const create$6 = (id, method, params) => {
|
|
719
813
|
const message = {
|
|
720
814
|
id,
|
|
721
815
|
jsonrpc: Two,
|
|
@@ -726,12 +820,12 @@ const create$3 = (id, method, params) => {
|
|
|
726
820
|
};
|
|
727
821
|
|
|
728
822
|
let id = 0;
|
|
729
|
-
const create$
|
|
823
|
+
const create$5 = () => {
|
|
730
824
|
return ++id;
|
|
731
825
|
};
|
|
732
826
|
|
|
733
827
|
const registerPromise = map => {
|
|
734
|
-
const id = create$
|
|
828
|
+
const id = create$5();
|
|
735
829
|
const {
|
|
736
830
|
promise,
|
|
737
831
|
resolve
|
|
@@ -748,7 +842,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
748
842
|
id,
|
|
749
843
|
promise
|
|
750
844
|
} = registerPromise(callbacks);
|
|
751
|
-
const message = create$
|
|
845
|
+
const message = create$6(id, method, params);
|
|
752
846
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
847
|
ipc.sendAndTransfer(message);
|
|
754
848
|
} else {
|
|
@@ -784,7 +878,7 @@ const createRpc = ipc => {
|
|
|
784
878
|
* @deprecated
|
|
785
879
|
*/
|
|
786
880
|
send(method, ...params) {
|
|
787
|
-
const message = create$
|
|
881
|
+
const message = create$7(method, params);
|
|
788
882
|
ipc.send(message);
|
|
789
883
|
}
|
|
790
884
|
};
|
|
@@ -824,6 +918,83 @@ const listen$1 = async (module, options) => {
|
|
|
824
918
|
return ipc;
|
|
825
919
|
};
|
|
826
920
|
|
|
921
|
+
const create$4 = async ({
|
|
922
|
+
commandMap,
|
|
923
|
+
isMessagePortOpen = true,
|
|
924
|
+
messagePort
|
|
925
|
+
}) => {
|
|
926
|
+
// TODO create a commandMap per rpc instance
|
|
927
|
+
register(commandMap);
|
|
928
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
929
|
+
isMessagePortOpen,
|
|
930
|
+
messagePort
|
|
931
|
+
});
|
|
932
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
933
|
+
handleIpc(ipc);
|
|
934
|
+
const rpc = createRpc(ipc);
|
|
935
|
+
messagePort.start();
|
|
936
|
+
return rpc;
|
|
937
|
+
};
|
|
938
|
+
|
|
939
|
+
const create$3 = async ({
|
|
940
|
+
commandMap,
|
|
941
|
+
isMessagePortOpen,
|
|
942
|
+
send
|
|
943
|
+
}) => {
|
|
944
|
+
const {
|
|
945
|
+
port1,
|
|
946
|
+
port2
|
|
947
|
+
} = new MessageChannel();
|
|
948
|
+
await send(port1);
|
|
949
|
+
return create$4({
|
|
950
|
+
commandMap,
|
|
951
|
+
isMessagePortOpen,
|
|
952
|
+
messagePort: port2
|
|
953
|
+
});
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
const createSharedLazyRpc = factory => {
|
|
957
|
+
let rpcPromise;
|
|
958
|
+
const getOrCreate = () => {
|
|
959
|
+
if (!rpcPromise) {
|
|
960
|
+
rpcPromise = factory();
|
|
961
|
+
}
|
|
962
|
+
return rpcPromise;
|
|
963
|
+
};
|
|
964
|
+
return {
|
|
965
|
+
async dispose() {
|
|
966
|
+
const rpc = await getOrCreate();
|
|
967
|
+
await rpc.dispose();
|
|
968
|
+
},
|
|
969
|
+
async invoke(method, ...params) {
|
|
970
|
+
const rpc = await getOrCreate();
|
|
971
|
+
return rpc.invoke(method, ...params);
|
|
972
|
+
},
|
|
973
|
+
async invokeAndTransfer(method, ...params) {
|
|
974
|
+
const rpc = await getOrCreate();
|
|
975
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
976
|
+
},
|
|
977
|
+
async send(method, ...params) {
|
|
978
|
+
const rpc = await getOrCreate();
|
|
979
|
+
rpc.send(method, ...params);
|
|
980
|
+
}
|
|
981
|
+
};
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
const create$2 = async ({
|
|
985
|
+
commandMap,
|
|
986
|
+
isMessagePortOpen,
|
|
987
|
+
send
|
|
988
|
+
}) => {
|
|
989
|
+
return createSharedLazyRpc(() => {
|
|
990
|
+
return create$3({
|
|
991
|
+
commandMap,
|
|
992
|
+
isMessagePortOpen,
|
|
993
|
+
send
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
};
|
|
997
|
+
|
|
827
998
|
const create$1 = async ({
|
|
828
999
|
commandMap
|
|
829
1000
|
}) => {
|
|
@@ -856,7 +1027,7 @@ const createMockRpc = ({
|
|
|
856
1027
|
};
|
|
857
1028
|
|
|
858
1029
|
const rpcs = Object.create(null);
|
|
859
|
-
const set$
|
|
1030
|
+
const set$2 = (id, rpc) => {
|
|
860
1031
|
rpcs[id] = rpc;
|
|
861
1032
|
};
|
|
862
1033
|
const get = id => {
|
|
@@ -889,7 +1060,7 @@ const create = rpcId => {
|
|
|
889
1060
|
const mockRpc = createMockRpc({
|
|
890
1061
|
commandMap
|
|
891
1062
|
});
|
|
892
|
-
set$
|
|
1063
|
+
set$2(rpcId, mockRpc);
|
|
893
1064
|
// @ts-ignore
|
|
894
1065
|
mockRpc[Symbol.dispose] = () => {
|
|
895
1066
|
remove(rpcId);
|
|
@@ -898,22 +1069,33 @@ const create = rpcId => {
|
|
|
898
1069
|
return mockRpc;
|
|
899
1070
|
},
|
|
900
1071
|
set(rpc) {
|
|
901
|
-
set$
|
|
1072
|
+
set$2(rpcId, rpc);
|
|
902
1073
|
}
|
|
903
1074
|
};
|
|
904
1075
|
};
|
|
905
1076
|
|
|
906
1077
|
const Electron = 2;
|
|
907
1078
|
|
|
1079
|
+
const DialogWorker = 7014;
|
|
908
1080
|
const RendererWorker = 1;
|
|
909
1081
|
|
|
910
1082
|
const DownloadingUpdate = 2;
|
|
911
1083
|
const DownloadedUpdate = 3;
|
|
912
1084
|
|
|
1085
|
+
const {
|
|
1086
|
+
invoke: invoke$1,
|
|
1087
|
+
set: set$1
|
|
1088
|
+
} = create(DialogWorker);
|
|
1089
|
+
|
|
913
1090
|
const {
|
|
914
1091
|
invoke,
|
|
1092
|
+
invokeAndTransfer,
|
|
915
1093
|
set
|
|
916
1094
|
} = create(RendererWorker);
|
|
1095
|
+
const sendMessagePortToDialogWorker = async port => {
|
|
1096
|
+
const command = 'HandleMessagePort.handleMessagePort';
|
|
1097
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
|
|
1098
|
+
};
|
|
917
1099
|
|
|
918
1100
|
const emptyObject = {};
|
|
919
1101
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
@@ -940,7 +1122,7 @@ const promptRestart = () => {
|
|
|
940
1122
|
};
|
|
941
1123
|
|
|
942
1124
|
const confirmPrompt = async message => {
|
|
943
|
-
const result = await invoke('ConfirmPrompt.prompt', message, {
|
|
1125
|
+
const result = await invoke$1('ConfirmPrompt.prompt', message, {
|
|
944
1126
|
// @ts-ignore
|
|
945
1127
|
platform: Electron
|
|
946
1128
|
});
|
|
@@ -1242,6 +1424,11 @@ const listen = async () => {
|
|
|
1242
1424
|
commandMap: commandMap
|
|
1243
1425
|
});
|
|
1244
1426
|
set(rpc);
|
|
1427
|
+
const dialogRpc = await create$2({
|
|
1428
|
+
commandMap: {},
|
|
1429
|
+
send: sendMessagePortToDialogWorker
|
|
1430
|
+
});
|
|
1431
|
+
set$1(dialogRpc);
|
|
1245
1432
|
};
|
|
1246
1433
|
|
|
1247
1434
|
const main = async () => {
|