@lvce-editor/update-worker 2.8.0 → 2.10.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 +289 -61
- 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) {
|
|
@@ -443,7 +537,10 @@ const constructError = (message, type, name) => {
|
|
|
443
537
|
if (ErrorConstructor === Error) {
|
|
444
538
|
const error = new Error(message);
|
|
445
539
|
if (name && name !== 'VError') {
|
|
446
|
-
error
|
|
540
|
+
Object.defineProperty(error, 'name', {
|
|
541
|
+
configurable: true,
|
|
542
|
+
value: name
|
|
543
|
+
});
|
|
447
544
|
}
|
|
448
545
|
return error;
|
|
449
546
|
}
|
|
@@ -460,8 +557,10 @@ const getCurrentStack = () => {
|
|
|
460
557
|
const currentStack = joinLines(splitLines(new Error().stack || '').slice(stackLinesToSkip));
|
|
461
558
|
return currentStack;
|
|
462
559
|
};
|
|
463
|
-
const getNewLineIndex = (string, startIndex
|
|
464
|
-
|
|
560
|
+
const getNewLineIndex = (string, startIndex) => {
|
|
561
|
+
{
|
|
562
|
+
return string.indexOf(NewLine);
|
|
563
|
+
}
|
|
465
564
|
};
|
|
466
565
|
const getParentStack = error => {
|
|
467
566
|
let parentStack = error.stack || error.data || error.message || '';
|
|
@@ -472,55 +571,91 @@ const getParentStack = error => {
|
|
|
472
571
|
};
|
|
473
572
|
const MethodNotFound = -32601;
|
|
474
573
|
const Custom = -32001;
|
|
574
|
+
const setStack = (error, stack) => {
|
|
575
|
+
const descriptor = Object.getOwnPropertyDescriptor(error, 'stack');
|
|
576
|
+
if (descriptor) {
|
|
577
|
+
if (!descriptor.configurable && !descriptor.writable) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
if (!descriptor.configurable && descriptor.writable) {
|
|
581
|
+
error.stack = stack;
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
Object.defineProperty(error, 'stack', {
|
|
586
|
+
configurable: true,
|
|
587
|
+
value: stack,
|
|
588
|
+
writable: true
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
const restoreExistingError = (error, currentStack) => {
|
|
592
|
+
if (typeof error.stack === 'string') {
|
|
593
|
+
setStack(error, `${error.stack}${NewLine}${currentStack}`);
|
|
594
|
+
}
|
|
595
|
+
return error;
|
|
596
|
+
};
|
|
597
|
+
const restoreMethodNotFoundError = (error, currentStack) => {
|
|
598
|
+
const restoredError = new JsonRpcError(error.message);
|
|
599
|
+
const parentStack = getParentStack(error);
|
|
600
|
+
setStack(restoredError, `${parentStack}${NewLine}${currentStack}`);
|
|
601
|
+
return restoredError;
|
|
602
|
+
};
|
|
603
|
+
const restoreStackFromData = (restoredError, error, currentStack) => {
|
|
604
|
+
if (error.data.stack && error.data.type && error.message) {
|
|
605
|
+
setStack(restoredError, `${error.data.type}: ${error.message}${NewLine}${error.data.stack}${NewLine}${currentStack}`);
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
if (error.data.stack) {
|
|
609
|
+
setStack(restoredError, error.data.stack);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
const applyDataProperties = (restoredError, error) => {
|
|
613
|
+
restoreStackFromData(restoredError, error, getCurrentStack());
|
|
614
|
+
if (error.data.codeFrame) {
|
|
615
|
+
// @ts-ignore
|
|
616
|
+
restoredError.codeFrame = error.data.codeFrame;
|
|
617
|
+
}
|
|
618
|
+
if (error.data.code) {
|
|
619
|
+
// @ts-ignore
|
|
620
|
+
restoredError.code = error.data.code;
|
|
621
|
+
}
|
|
622
|
+
if (error.data.type) {
|
|
623
|
+
// @ts-ignore
|
|
624
|
+
restoredError.name = error.data.type;
|
|
625
|
+
}
|
|
626
|
+
};
|
|
627
|
+
const applyDirectProperties = (restoredError, error) => {
|
|
628
|
+
if (error.stack) {
|
|
629
|
+
const lowerStack = restoredError.stack || '';
|
|
630
|
+
const indexNewLine = getNewLineIndex(lowerStack);
|
|
631
|
+
const parentStack = getParentStack(error);
|
|
632
|
+
// @ts-ignore
|
|
633
|
+
setStack(restoredError, `${parentStack}${lowerStack.slice(indexNewLine)}`);
|
|
634
|
+
}
|
|
635
|
+
if (error.codeFrame) {
|
|
636
|
+
// @ts-ignore
|
|
637
|
+
restoredError.codeFrame = error.codeFrame;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
const restoreMessageError = (error, _currentStack) => {
|
|
641
|
+
const restoredError = constructError(error.message, error.type, error.name);
|
|
642
|
+
if (error.data) {
|
|
643
|
+
applyDataProperties(restoredError, error);
|
|
644
|
+
} else {
|
|
645
|
+
applyDirectProperties(restoredError, error);
|
|
646
|
+
}
|
|
647
|
+
return restoredError;
|
|
648
|
+
};
|
|
475
649
|
const restoreJsonRpcError = error => {
|
|
476
650
|
const currentStack = getCurrentStack();
|
|
477
651
|
if (error && error instanceof Error) {
|
|
478
|
-
|
|
479
|
-
error.stack = error.stack + NewLine + currentStack;
|
|
480
|
-
}
|
|
481
|
-
return error;
|
|
652
|
+
return restoreExistingError(error, currentStack);
|
|
482
653
|
}
|
|
483
654
|
if (error && error.code && error.code === MethodNotFound) {
|
|
484
|
-
|
|
485
|
-
const parentStack = getParentStack(error);
|
|
486
|
-
restoredError.stack = parentStack + NewLine + currentStack;
|
|
487
|
-
return restoredError;
|
|
655
|
+
return restoreMethodNotFoundError(error, currentStack);
|
|
488
656
|
}
|
|
489
657
|
if (error && error.message) {
|
|
490
|
-
|
|
491
|
-
if (error.data) {
|
|
492
|
-
if (error.data.stack && error.data.type && error.message) {
|
|
493
|
-
restoredError.stack = error.data.type + ': ' + error.message + NewLine + error.data.stack + NewLine + currentStack;
|
|
494
|
-
} else if (error.data.stack) {
|
|
495
|
-
restoredError.stack = error.data.stack;
|
|
496
|
-
}
|
|
497
|
-
if (error.data.codeFrame) {
|
|
498
|
-
// @ts-ignore
|
|
499
|
-
restoredError.codeFrame = error.data.codeFrame;
|
|
500
|
-
}
|
|
501
|
-
if (error.data.code) {
|
|
502
|
-
// @ts-ignore
|
|
503
|
-
restoredError.code = error.data.code;
|
|
504
|
-
}
|
|
505
|
-
if (error.data.type) {
|
|
506
|
-
// @ts-ignore
|
|
507
|
-
restoredError.name = error.data.type;
|
|
508
|
-
}
|
|
509
|
-
} else {
|
|
510
|
-
if (error.stack) {
|
|
511
|
-
const lowerStack = restoredError.stack || '';
|
|
512
|
-
// @ts-ignore
|
|
513
|
-
const indexNewLine = getNewLineIndex(lowerStack);
|
|
514
|
-
const parentStack = getParentStack(error);
|
|
515
|
-
// @ts-ignore
|
|
516
|
-
restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
|
|
517
|
-
}
|
|
518
|
-
if (error.codeFrame) {
|
|
519
|
-
// @ts-ignore
|
|
520
|
-
restoredError.codeFrame = error.codeFrame;
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
return restoredError;
|
|
658
|
+
return restoreMessageError(error);
|
|
524
659
|
}
|
|
525
660
|
if (typeof error === 'string') {
|
|
526
661
|
return new Error(`JsonRpc Error: ${error}`);
|
|
@@ -604,7 +739,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
604
739
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
605
740
|
return create$1$1(id, errorProperty);
|
|
606
741
|
};
|
|
607
|
-
const create$
|
|
742
|
+
const create$8 = (message, result) => {
|
|
608
743
|
return {
|
|
609
744
|
id: message.id,
|
|
610
745
|
jsonrpc: Two$1,
|
|
@@ -613,7 +748,7 @@ const create$5 = (message, result) => {
|
|
|
613
748
|
};
|
|
614
749
|
const getSuccessResponse = (message, result) => {
|
|
615
750
|
const resultProperty = result ?? null;
|
|
616
|
-
return create$
|
|
751
|
+
return create$8(message, resultProperty);
|
|
617
752
|
};
|
|
618
753
|
const getErrorResponseSimple = (id, error) => {
|
|
619
754
|
return {
|
|
@@ -707,7 +842,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
707
842
|
|
|
708
843
|
const Two = '2.0';
|
|
709
844
|
|
|
710
|
-
const create$
|
|
845
|
+
const create$7 = (method, params) => {
|
|
711
846
|
return {
|
|
712
847
|
jsonrpc: Two,
|
|
713
848
|
method,
|
|
@@ -715,7 +850,7 @@ const create$4 = (method, params) => {
|
|
|
715
850
|
};
|
|
716
851
|
};
|
|
717
852
|
|
|
718
|
-
const create$
|
|
853
|
+
const create$6 = (id, method, params) => {
|
|
719
854
|
const message = {
|
|
720
855
|
id,
|
|
721
856
|
jsonrpc: Two,
|
|
@@ -726,12 +861,12 @@ const create$3 = (id, method, params) => {
|
|
|
726
861
|
};
|
|
727
862
|
|
|
728
863
|
let id = 0;
|
|
729
|
-
const create$
|
|
864
|
+
const create$5 = () => {
|
|
730
865
|
return ++id;
|
|
731
866
|
};
|
|
732
867
|
|
|
733
868
|
const registerPromise = map => {
|
|
734
|
-
const id = create$
|
|
869
|
+
const id = create$5();
|
|
735
870
|
const {
|
|
736
871
|
promise,
|
|
737
872
|
resolve
|
|
@@ -748,7 +883,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
748
883
|
id,
|
|
749
884
|
promise
|
|
750
885
|
} = registerPromise(callbacks);
|
|
751
|
-
const message = create$
|
|
886
|
+
const message = create$6(id, method, params);
|
|
752
887
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
753
888
|
ipc.sendAndTransfer(message);
|
|
754
889
|
} else {
|
|
@@ -784,7 +919,7 @@ const createRpc = ipc => {
|
|
|
784
919
|
* @deprecated
|
|
785
920
|
*/
|
|
786
921
|
send(method, ...params) {
|
|
787
|
-
const message = create$
|
|
922
|
+
const message = create$7(method, params);
|
|
788
923
|
ipc.send(message);
|
|
789
924
|
}
|
|
790
925
|
};
|
|
@@ -824,6 +959,83 @@ const listen$1 = async (module, options) => {
|
|
|
824
959
|
return ipc;
|
|
825
960
|
};
|
|
826
961
|
|
|
962
|
+
const create$4 = async ({
|
|
963
|
+
commandMap,
|
|
964
|
+
isMessagePortOpen = true,
|
|
965
|
+
messagePort
|
|
966
|
+
}) => {
|
|
967
|
+
// TODO create a commandMap per rpc instance
|
|
968
|
+
register(commandMap);
|
|
969
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
970
|
+
isMessagePortOpen,
|
|
971
|
+
messagePort
|
|
972
|
+
});
|
|
973
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
974
|
+
handleIpc(ipc);
|
|
975
|
+
const rpc = createRpc(ipc);
|
|
976
|
+
messagePort.start();
|
|
977
|
+
return rpc;
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
const create$3 = async ({
|
|
981
|
+
commandMap,
|
|
982
|
+
isMessagePortOpen,
|
|
983
|
+
send
|
|
984
|
+
}) => {
|
|
985
|
+
const {
|
|
986
|
+
port1,
|
|
987
|
+
port2
|
|
988
|
+
} = new MessageChannel();
|
|
989
|
+
await send(port1);
|
|
990
|
+
return create$4({
|
|
991
|
+
commandMap,
|
|
992
|
+
isMessagePortOpen,
|
|
993
|
+
messagePort: port2
|
|
994
|
+
});
|
|
995
|
+
};
|
|
996
|
+
|
|
997
|
+
const createSharedLazyRpc = factory => {
|
|
998
|
+
let rpcPromise;
|
|
999
|
+
const getOrCreate = () => {
|
|
1000
|
+
if (!rpcPromise) {
|
|
1001
|
+
rpcPromise = factory();
|
|
1002
|
+
}
|
|
1003
|
+
return rpcPromise;
|
|
1004
|
+
};
|
|
1005
|
+
return {
|
|
1006
|
+
async dispose() {
|
|
1007
|
+
const rpc = await getOrCreate();
|
|
1008
|
+
await rpc.dispose();
|
|
1009
|
+
},
|
|
1010
|
+
async invoke(method, ...params) {
|
|
1011
|
+
const rpc = await getOrCreate();
|
|
1012
|
+
return rpc.invoke(method, ...params);
|
|
1013
|
+
},
|
|
1014
|
+
async invokeAndTransfer(method, ...params) {
|
|
1015
|
+
const rpc = await getOrCreate();
|
|
1016
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1017
|
+
},
|
|
1018
|
+
async send(method, ...params) {
|
|
1019
|
+
const rpc = await getOrCreate();
|
|
1020
|
+
rpc.send(method, ...params);
|
|
1021
|
+
}
|
|
1022
|
+
};
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
const create$2 = async ({
|
|
1026
|
+
commandMap,
|
|
1027
|
+
isMessagePortOpen,
|
|
1028
|
+
send
|
|
1029
|
+
}) => {
|
|
1030
|
+
return createSharedLazyRpc(() => {
|
|
1031
|
+
return create$3({
|
|
1032
|
+
commandMap,
|
|
1033
|
+
isMessagePortOpen,
|
|
1034
|
+
send
|
|
1035
|
+
});
|
|
1036
|
+
});
|
|
1037
|
+
};
|
|
1038
|
+
|
|
827
1039
|
const create$1 = async ({
|
|
828
1040
|
commandMap
|
|
829
1041
|
}) => {
|
|
@@ -856,7 +1068,7 @@ const createMockRpc = ({
|
|
|
856
1068
|
};
|
|
857
1069
|
|
|
858
1070
|
const rpcs = Object.create(null);
|
|
859
|
-
const set$
|
|
1071
|
+
const set$2 = (id, rpc) => {
|
|
860
1072
|
rpcs[id] = rpc;
|
|
861
1073
|
};
|
|
862
1074
|
const get = id => {
|
|
@@ -889,7 +1101,7 @@ const create = rpcId => {
|
|
|
889
1101
|
const mockRpc = createMockRpc({
|
|
890
1102
|
commandMap
|
|
891
1103
|
});
|
|
892
|
-
set$
|
|
1104
|
+
set$2(rpcId, mockRpc);
|
|
893
1105
|
// @ts-ignore
|
|
894
1106
|
mockRpc[Symbol.dispose] = () => {
|
|
895
1107
|
remove(rpcId);
|
|
@@ -898,22 +1110,33 @@ const create = rpcId => {
|
|
|
898
1110
|
return mockRpc;
|
|
899
1111
|
},
|
|
900
1112
|
set(rpc) {
|
|
901
|
-
set$
|
|
1113
|
+
set$2(rpcId, rpc);
|
|
902
1114
|
}
|
|
903
1115
|
};
|
|
904
1116
|
};
|
|
905
1117
|
|
|
906
|
-
const
|
|
907
|
-
|
|
1118
|
+
const DialogWorker = 7014;
|
|
908
1119
|
const RendererWorker = 1;
|
|
909
1120
|
|
|
910
|
-
const
|
|
911
|
-
|
|
1121
|
+
const {
|
|
1122
|
+
invoke: invoke$1,
|
|
1123
|
+
set: set$1
|
|
1124
|
+
} = create(DialogWorker);
|
|
912
1125
|
|
|
913
1126
|
const {
|
|
914
1127
|
invoke,
|
|
1128
|
+
invokeAndTransfer,
|
|
915
1129
|
set
|
|
916
1130
|
} = create(RendererWorker);
|
|
1131
|
+
const sendMessagePortToDialogWorker = async port => {
|
|
1132
|
+
const command = 'HandleMessagePort.handleMessagePort';
|
|
1133
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToDialogWorker', port, command);
|
|
1134
|
+
};
|
|
1135
|
+
|
|
1136
|
+
const Electron = 2;
|
|
1137
|
+
|
|
1138
|
+
const DownloadingUpdate = 2;
|
|
1139
|
+
const DownloadedUpdate = 3;
|
|
917
1140
|
|
|
918
1141
|
const emptyObject = {};
|
|
919
1142
|
const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
|
|
@@ -940,7 +1163,7 @@ const promptRestart = () => {
|
|
|
940
1163
|
};
|
|
941
1164
|
|
|
942
1165
|
const confirmPrompt = async message => {
|
|
943
|
-
const result = await invoke('ConfirmPrompt.prompt', message, {
|
|
1166
|
+
const result = await invoke$1('ConfirmPrompt.prompt', message, {
|
|
944
1167
|
// @ts-ignore
|
|
945
1168
|
platform: Electron
|
|
946
1169
|
});
|
|
@@ -1242,6 +1465,11 @@ const listen = async () => {
|
|
|
1242
1465
|
commandMap: commandMap
|
|
1243
1466
|
});
|
|
1244
1467
|
set(rpc);
|
|
1468
|
+
const dialogRpc = await create$2({
|
|
1469
|
+
commandMap: {},
|
|
1470
|
+
send: sendMessagePortToDialogWorker
|
|
1471
|
+
});
|
|
1472
|
+
set$1(dialogRpc);
|
|
1245
1473
|
};
|
|
1246
1474
|
|
|
1247
1475
|
const main = async () => {
|