@lvce-editor/opener-worker 1.5.0 → 1.8.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/openerWorkerMain.js +105 -104
- package/package.json +1 -1
package/dist/openerWorkerMain.js
CHANGED
|
@@ -463,6 +463,27 @@ const IpcParentWithMessagePort$1 = {
|
|
|
463
463
|
wrap: wrap$5
|
|
464
464
|
};
|
|
465
465
|
|
|
466
|
+
class CommandNotFoundError extends Error {
|
|
467
|
+
constructor(command) {
|
|
468
|
+
super(`Command not found ${command}`);
|
|
469
|
+
this.name = 'CommandNotFoundError';
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
const commands = Object.create(null);
|
|
473
|
+
const register = commandMap => {
|
|
474
|
+
Object.assign(commands, commandMap);
|
|
475
|
+
};
|
|
476
|
+
const getCommand = key => {
|
|
477
|
+
return commands[key];
|
|
478
|
+
};
|
|
479
|
+
const execute = (command, ...args) => {
|
|
480
|
+
const fn = getCommand(command);
|
|
481
|
+
if (!fn) {
|
|
482
|
+
throw new CommandNotFoundError(command);
|
|
483
|
+
}
|
|
484
|
+
return fn(...args);
|
|
485
|
+
};
|
|
486
|
+
|
|
466
487
|
const Two$1 = '2.0';
|
|
467
488
|
const callbacks = Object.create(null);
|
|
468
489
|
const get$2 = id => {
|
|
@@ -487,12 +508,12 @@ const getErrorConstructor = (message, type) => {
|
|
|
487
508
|
switch (type) {
|
|
488
509
|
case DomException:
|
|
489
510
|
return DOMException;
|
|
490
|
-
case TypeError$1:
|
|
491
|
-
return TypeError;
|
|
492
|
-
case SyntaxError$1:
|
|
493
|
-
return SyntaxError;
|
|
494
511
|
case ReferenceError$1:
|
|
495
512
|
return ReferenceError;
|
|
513
|
+
case SyntaxError$1:
|
|
514
|
+
return SyntaxError;
|
|
515
|
+
case TypeError$1:
|
|
516
|
+
return TypeError;
|
|
496
517
|
default:
|
|
497
518
|
return Error;
|
|
498
519
|
}
|
|
@@ -648,56 +669,56 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
648
669
|
if (error && error.code === E_COMMAND_NOT_FOUND) {
|
|
649
670
|
return {
|
|
650
671
|
code: MethodNotFound,
|
|
651
|
-
|
|
652
|
-
|
|
672
|
+
data: error.stack,
|
|
673
|
+
message: error.message
|
|
653
674
|
};
|
|
654
675
|
}
|
|
655
676
|
return {
|
|
656
677
|
code: Custom,
|
|
657
|
-
message: prettyError.message,
|
|
658
678
|
data: {
|
|
659
|
-
stack: getStack(prettyError),
|
|
660
|
-
codeFrame: prettyError.codeFrame,
|
|
661
|
-
type: getErrorType(prettyError),
|
|
662
679
|
code: prettyError.code,
|
|
663
|
-
|
|
664
|
-
|
|
680
|
+
codeFrame: prettyError.codeFrame,
|
|
681
|
+
name: prettyError.name,
|
|
682
|
+
stack: getStack(prettyError),
|
|
683
|
+
type: getErrorType(prettyError)
|
|
684
|
+
},
|
|
685
|
+
message: prettyError.message
|
|
665
686
|
};
|
|
666
687
|
};
|
|
667
|
-
const create$1 = (id, error) => {
|
|
688
|
+
const create$1$1 = (id, error) => {
|
|
668
689
|
return {
|
|
669
|
-
|
|
690
|
+
error,
|
|
670
691
|
id,
|
|
671
|
-
|
|
692
|
+
jsonrpc: Two$1
|
|
672
693
|
};
|
|
673
694
|
};
|
|
674
695
|
const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
675
696
|
const prettyError = preparePrettyError(error);
|
|
676
697
|
logError(error, prettyError);
|
|
677
698
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
678
|
-
return create$1(id, errorProperty);
|
|
699
|
+
return create$1$1(id, errorProperty);
|
|
679
700
|
};
|
|
680
|
-
const create$
|
|
701
|
+
const create$8 = (message, result) => {
|
|
681
702
|
return {
|
|
682
|
-
jsonrpc: Two$1,
|
|
683
703
|
id: message.id,
|
|
704
|
+
jsonrpc: Two$1,
|
|
684
705
|
result: result ?? null
|
|
685
706
|
};
|
|
686
707
|
};
|
|
687
708
|
const getSuccessResponse = (message, result) => {
|
|
688
709
|
const resultProperty = result ?? null;
|
|
689
|
-
return create$
|
|
710
|
+
return create$8(message, resultProperty);
|
|
690
711
|
};
|
|
691
712
|
const getErrorResponseSimple = (id, error) => {
|
|
692
713
|
return {
|
|
693
|
-
jsonrpc: Two$1,
|
|
694
|
-
id,
|
|
695
714
|
error: {
|
|
696
715
|
code: Custom,
|
|
716
|
+
data: error,
|
|
697
717
|
// @ts-ignore
|
|
698
|
-
message: error.message
|
|
699
|
-
|
|
700
|
-
|
|
718
|
+
message: error.message
|
|
719
|
+
},
|
|
720
|
+
id,
|
|
721
|
+
jsonrpc: Two$1
|
|
701
722
|
};
|
|
702
723
|
};
|
|
703
724
|
const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
|
|
@@ -727,35 +748,35 @@ const normalizeParams = args => {
|
|
|
727
748
|
if (args.length === 1) {
|
|
728
749
|
const options = args[0];
|
|
729
750
|
return {
|
|
751
|
+
execute: options.execute,
|
|
730
752
|
ipc: options.ipc,
|
|
753
|
+
logError: options.logError || defaultLogError,
|
|
731
754
|
message: options.message,
|
|
732
|
-
execute: options.execute,
|
|
733
|
-
resolve: options.resolve || defaultResolve,
|
|
734
755
|
preparePrettyError: options.preparePrettyError || defaultPreparePrettyError,
|
|
735
|
-
|
|
736
|
-
|
|
756
|
+
requiresSocket: options.requiresSocket || defaultRequiresSocket,
|
|
757
|
+
resolve: options.resolve || defaultResolve
|
|
737
758
|
};
|
|
738
759
|
}
|
|
739
760
|
return {
|
|
761
|
+
execute: args[2],
|
|
740
762
|
ipc: args[0],
|
|
763
|
+
logError: args[5],
|
|
741
764
|
message: args[1],
|
|
742
|
-
execute: args[2],
|
|
743
|
-
resolve: args[3],
|
|
744
765
|
preparePrettyError: args[4],
|
|
745
|
-
|
|
746
|
-
|
|
766
|
+
requiresSocket: args[6],
|
|
767
|
+
resolve: args[3]
|
|
747
768
|
};
|
|
748
769
|
};
|
|
749
770
|
const handleJsonRpcMessage = async (...args) => {
|
|
750
771
|
const options = normalizeParams(args);
|
|
751
772
|
const {
|
|
752
|
-
message,
|
|
753
|
-
ipc,
|
|
754
773
|
execute,
|
|
755
|
-
|
|
756
|
-
preparePrettyError,
|
|
774
|
+
ipc,
|
|
757
775
|
logError,
|
|
758
|
-
|
|
776
|
+
message,
|
|
777
|
+
preparePrettyError,
|
|
778
|
+
requiresSocket,
|
|
779
|
+
resolve
|
|
759
780
|
} = options;
|
|
760
781
|
if ('id' in message) {
|
|
761
782
|
if ('method' in message) {
|
|
@@ -778,36 +799,17 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
778
799
|
throw new JsonRpcError('unexpected message');
|
|
779
800
|
};
|
|
780
801
|
|
|
781
|
-
class CommandNotFoundError extends Error {
|
|
782
|
-
constructor(command) {
|
|
783
|
-
super(`Command not found ${command}`);
|
|
784
|
-
this.name = 'CommandNotFoundError';
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
const commands = Object.create(null);
|
|
788
|
-
const register = commandMap => {
|
|
789
|
-
Object.assign(commands, commandMap);
|
|
790
|
-
};
|
|
791
|
-
const getCommand = key => {
|
|
792
|
-
return commands[key];
|
|
793
|
-
};
|
|
794
|
-
const execute = (command, ...args) => {
|
|
795
|
-
const fn = getCommand(command);
|
|
796
|
-
if (!fn) {
|
|
797
|
-
throw new CommandNotFoundError(command);
|
|
798
|
-
}
|
|
799
|
-
return fn(...args);
|
|
800
|
-
};
|
|
801
|
-
|
|
802
802
|
const Two = '2.0';
|
|
803
|
-
|
|
803
|
+
|
|
804
|
+
const create$7 = (method, params) => {
|
|
804
805
|
return {
|
|
805
806
|
jsonrpc: Two,
|
|
806
807
|
method,
|
|
807
808
|
params
|
|
808
809
|
};
|
|
809
810
|
};
|
|
810
|
-
|
|
811
|
+
|
|
812
|
+
const create$6 = (id, method, params) => {
|
|
811
813
|
const message = {
|
|
812
814
|
id,
|
|
813
815
|
jsonrpc: Two,
|
|
@@ -816,15 +818,14 @@ const create$s = (id, method, params) => {
|
|
|
816
818
|
};
|
|
817
819
|
return message;
|
|
818
820
|
};
|
|
821
|
+
|
|
819
822
|
let id = 0;
|
|
820
|
-
const create$
|
|
823
|
+
const create$5 = () => {
|
|
821
824
|
return ++id;
|
|
822
825
|
};
|
|
823
826
|
|
|
824
|
-
/* eslint-disable n/no-unsupported-features/es-syntax */
|
|
825
|
-
|
|
826
827
|
const registerPromise = map => {
|
|
827
|
-
const id = create$
|
|
828
|
+
const id = create$5();
|
|
828
829
|
const {
|
|
829
830
|
promise,
|
|
830
831
|
resolve
|
|
@@ -836,13 +837,12 @@ const registerPromise = map => {
|
|
|
836
837
|
};
|
|
837
838
|
};
|
|
838
839
|
|
|
839
|
-
// @ts-ignore
|
|
840
840
|
const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer) => {
|
|
841
841
|
const {
|
|
842
842
|
id,
|
|
843
843
|
promise
|
|
844
844
|
} = registerPromise(callbacks);
|
|
845
|
-
const message = create$
|
|
845
|
+
const message = create$6(id, method, params);
|
|
846
846
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
847
847
|
ipc.sendAndTransfer(message);
|
|
848
848
|
} else {
|
|
@@ -878,12 +878,13 @@ const createRpc = ipc => {
|
|
|
878
878
|
* @deprecated
|
|
879
879
|
*/
|
|
880
880
|
send(method, ...params) {
|
|
881
|
-
const message = create$
|
|
881
|
+
const message = create$7(method, params);
|
|
882
882
|
ipc.send(message);
|
|
883
883
|
}
|
|
884
884
|
};
|
|
885
885
|
return rpc;
|
|
886
886
|
};
|
|
887
|
+
|
|
887
888
|
const requiresSocket = () => {
|
|
888
889
|
return false;
|
|
889
890
|
};
|
|
@@ -898,6 +899,7 @@ const handleMessage = event => {
|
|
|
898
899
|
const actualExecute = event?.target?.execute || execute;
|
|
899
900
|
return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
900
901
|
};
|
|
902
|
+
|
|
901
903
|
const handleIpc = ipc => {
|
|
902
904
|
if ('addEventListener' in ipc) {
|
|
903
905
|
ipc.addEventListener('message', handleMessage);
|
|
@@ -906,6 +908,7 @@ const handleIpc = ipc => {
|
|
|
906
908
|
ipc.on('message', handleMessage);
|
|
907
909
|
}
|
|
908
910
|
};
|
|
911
|
+
|
|
909
912
|
const listen$1 = async (module, options) => {
|
|
910
913
|
const rawIpc = await module.listen(options);
|
|
911
914
|
if (module.signal) {
|
|
@@ -914,7 +917,8 @@ const listen$1 = async (module, options) => {
|
|
|
914
917
|
const ipc = module.wrap(rawIpc);
|
|
915
918
|
return ipc;
|
|
916
919
|
};
|
|
917
|
-
|
|
920
|
+
|
|
921
|
+
const create$4 = async ({
|
|
918
922
|
commandMap,
|
|
919
923
|
isMessagePortOpen = true,
|
|
920
924
|
messagePort
|
|
@@ -931,19 +935,7 @@ const create$5 = async ({
|
|
|
931
935
|
messagePort.start();
|
|
932
936
|
return rpc;
|
|
933
937
|
};
|
|
934
|
-
|
|
935
|
-
commandMap,
|
|
936
|
-
messagePort
|
|
937
|
-
}) => {
|
|
938
|
-
return create$5({
|
|
939
|
-
commandMap,
|
|
940
|
-
messagePort
|
|
941
|
-
});
|
|
942
|
-
};
|
|
943
|
-
const PlainMessagePortRpcParent = {
|
|
944
|
-
__proto__: null,
|
|
945
|
-
create: create$4
|
|
946
|
-
};
|
|
938
|
+
|
|
947
939
|
const create$3 = async ({
|
|
948
940
|
commandMap,
|
|
949
941
|
isMessagePortOpen,
|
|
@@ -954,17 +946,24 @@ const create$3 = async ({
|
|
|
954
946
|
port2
|
|
955
947
|
} = new MessageChannel();
|
|
956
948
|
await send(port1);
|
|
957
|
-
return create$
|
|
949
|
+
return create$4({
|
|
958
950
|
commandMap,
|
|
959
951
|
isMessagePortOpen,
|
|
960
952
|
messagePort: port2
|
|
961
953
|
});
|
|
962
954
|
};
|
|
963
|
-
|
|
964
|
-
__proto__: null,
|
|
965
|
-
create: create$3
|
|
966
|
-
};
|
|
955
|
+
|
|
967
956
|
const create$2 = async ({
|
|
957
|
+
commandMap,
|
|
958
|
+
messagePort
|
|
959
|
+
}) => {
|
|
960
|
+
return create$4({
|
|
961
|
+
commandMap,
|
|
962
|
+
messagePort
|
|
963
|
+
});
|
|
964
|
+
};
|
|
965
|
+
|
|
966
|
+
const create$1 = async ({
|
|
968
967
|
commandMap
|
|
969
968
|
}) => {
|
|
970
969
|
// TODO create a commandMap per rpc instance
|
|
@@ -974,10 +973,7 @@ const create$2 = async ({
|
|
|
974
973
|
const rpc = createRpc(ipc);
|
|
975
974
|
return rpc;
|
|
976
975
|
};
|
|
977
|
-
|
|
978
|
-
__proto__: null,
|
|
979
|
-
create: create$2
|
|
980
|
-
};
|
|
976
|
+
|
|
981
977
|
const createMockRpc = ({
|
|
982
978
|
commandMap
|
|
983
979
|
}) => {
|
|
@@ -998,11 +994,6 @@ const createMockRpc = ({
|
|
|
998
994
|
return mockRpc;
|
|
999
995
|
};
|
|
1000
996
|
|
|
1001
|
-
const Electron = 2;
|
|
1002
|
-
|
|
1003
|
-
const RendererWorker = 1;
|
|
1004
|
-
const SharedProcess = 1492;
|
|
1005
|
-
|
|
1006
997
|
const rpcs = Object.create(null);
|
|
1007
998
|
const set$3 = (id, rpc) => {
|
|
1008
999
|
rpcs[id] = rpc;
|
|
@@ -1051,6 +1042,11 @@ const create = rpcId => {
|
|
|
1051
1042
|
};
|
|
1052
1043
|
};
|
|
1053
1044
|
|
|
1045
|
+
const Electron = 2;
|
|
1046
|
+
|
|
1047
|
+
const RendererWorker = 1;
|
|
1048
|
+
const SharedProcess = 1492;
|
|
1049
|
+
|
|
1054
1050
|
const {
|
|
1055
1051
|
invoke: invoke$2,
|
|
1056
1052
|
invokeAndTransfer,
|
|
@@ -1058,7 +1054,6 @@ const {
|
|
|
1058
1054
|
} = create(RendererWorker);
|
|
1059
1055
|
const sendMessagePortToSharedProcess = async port => {
|
|
1060
1056
|
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1061
|
-
// @ts-ignore
|
|
1062
1057
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1063
1058
|
};
|
|
1064
1059
|
|
|
@@ -1068,7 +1063,7 @@ const {
|
|
|
1068
1063
|
} = create(SharedProcess);
|
|
1069
1064
|
|
|
1070
1065
|
const handleMessagePort = async (port, rpcId) => {
|
|
1071
|
-
const rpc = await
|
|
1066
|
+
const rpc = await create$2({
|
|
1072
1067
|
commandMap: {},
|
|
1073
1068
|
messagePort: port
|
|
1074
1069
|
});
|
|
@@ -1077,6 +1072,12 @@ const handleMessagePort = async (port, rpcId) => {
|
|
|
1077
1072
|
}
|
|
1078
1073
|
};
|
|
1079
1074
|
|
|
1075
|
+
const initialize = async platform => {
|
|
1076
|
+
if (platform === Electron) {
|
|
1077
|
+
await initializeMainProcess();
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
|
|
1080
1081
|
const openNew = async url => {
|
|
1081
1082
|
await invoke$1('OpenExternal.openExternal', url);
|
|
1082
1083
|
};
|
|
@@ -1113,10 +1114,10 @@ const OpenExternal = {
|
|
|
1113
1114
|
openExternal: openExternal$1
|
|
1114
1115
|
};
|
|
1115
1116
|
|
|
1116
|
-
const openUrlWeb = async url => {
|
|
1117
|
+
const openUrlWeb = async (url, useRedirect) => {
|
|
1117
1118
|
try {
|
|
1118
1119
|
// TODO make platform argument required
|
|
1119
|
-
await invoke$2('Open.openUrl', url);
|
|
1120
|
+
await invoke$2('Open.openUrl', url, useRedirect);
|
|
1120
1121
|
} catch (error) {
|
|
1121
1122
|
throw new VError(error, `Failed to open url ${url}`);
|
|
1122
1123
|
}
|
|
@@ -1126,7 +1127,7 @@ const openUrlElectron = async url => {
|
|
|
1126
1127
|
};
|
|
1127
1128
|
|
|
1128
1129
|
// TODO add required platform argument
|
|
1129
|
-
const openUrl = async (url, platform) => {
|
|
1130
|
+
const openUrl = async (url, platform, useRedirect = false) => {
|
|
1130
1131
|
if (get()) {
|
|
1131
1132
|
writeUrl(url);
|
|
1132
1133
|
return;
|
|
@@ -1135,7 +1136,7 @@ const openUrl = async (url, platform) => {
|
|
|
1135
1136
|
case Electron:
|
|
1136
1137
|
return openUrlElectron(url);
|
|
1137
1138
|
default:
|
|
1138
|
-
return openUrlWeb(url);
|
|
1139
|
+
return openUrlWeb(url, useRedirect);
|
|
1139
1140
|
}
|
|
1140
1141
|
};
|
|
1141
1142
|
const {
|
|
@@ -1167,7 +1168,6 @@ const showSaveDialog = async (title, properties, platform) => {
|
|
|
1167
1168
|
if (platform === Electron) {
|
|
1168
1169
|
return invoke$1('ElectronDialog.showSaveDialog', title, properties);
|
|
1169
1170
|
}
|
|
1170
|
-
// When running in web, prompt for filename and combine with workspace path
|
|
1171
1171
|
const fileName = await invoke$2('Prompt.prompt', title);
|
|
1172
1172
|
if (!fileName) {
|
|
1173
1173
|
return {
|
|
@@ -1185,6 +1185,7 @@ const showSaveDialog = async (title, properties, platform) => {
|
|
|
1185
1185
|
const commandMap = {
|
|
1186
1186
|
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
1187
1187
|
'Open.enableMemoryOpener': enable,
|
|
1188
|
+
'Open.initialize': initialize,
|
|
1188
1189
|
'Open.openExternal': openExternal,
|
|
1189
1190
|
'Open.openUrl': openUrl,
|
|
1190
1191
|
'Open.readOpenedUrl': readOpenedMemory,
|
|
@@ -1197,7 +1198,7 @@ const send = async port => {
|
|
|
1197
1198
|
await sendMessagePortToSharedProcess(port);
|
|
1198
1199
|
};
|
|
1199
1200
|
const initializeMainProcess = async () => {
|
|
1200
|
-
const rpc = await
|
|
1201
|
+
const rpc = await create$3({
|
|
1201
1202
|
commandMap: commandMap,
|
|
1202
1203
|
send
|
|
1203
1204
|
});
|
|
@@ -1205,7 +1206,7 @@ const initializeMainProcess = async () => {
|
|
|
1205
1206
|
};
|
|
1206
1207
|
|
|
1207
1208
|
const initializeRendererWorker = async () => {
|
|
1208
|
-
const rpc = await
|
|
1209
|
+
const rpc = await create$1({
|
|
1209
1210
|
commandMap: commandMap
|
|
1210
1211
|
});
|
|
1211
1212
|
set$2(rpc);
|