@lvce-editor/embeds-worker 2.4.0 → 3.0.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/embedsWorkerMain.js +279 -167
- package/package.json +1 -1
package/dist/embedsWorkerMain.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
|
+
resolve,
|
|
388
|
+
promise
|
|
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
|
+
type,
|
|
401
|
+
event
|
|
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
|
+
messagePort,
|
|
412
|
+
isMessagePortOpen
|
|
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
|
+
type,
|
|
426
|
+
event
|
|
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
|
const Two = '2.0';
|
|
373
467
|
const create$4 = (method, params) => {
|
|
@@ -378,10 +472,10 @@ const create$4 = (method, params) => {
|
|
|
378
472
|
};
|
|
379
473
|
};
|
|
380
474
|
const callbacks = Object.create(null);
|
|
381
|
-
const set = (id, fn) => {
|
|
475
|
+
const set$3 = (id, fn) => {
|
|
382
476
|
callbacks[id] = fn;
|
|
383
477
|
};
|
|
384
|
-
const get = id => {
|
|
478
|
+
const get$1 = id => {
|
|
385
479
|
return callbacks[id];
|
|
386
480
|
};
|
|
387
481
|
const remove = id => {
|
|
@@ -397,13 +491,13 @@ const registerPromise = () => {
|
|
|
397
491
|
resolve,
|
|
398
492
|
promise
|
|
399
493
|
} = Promise.withResolvers();
|
|
400
|
-
set(id, resolve);
|
|
494
|
+
set$3(id, resolve);
|
|
401
495
|
return {
|
|
402
496
|
id,
|
|
403
497
|
promise
|
|
404
498
|
};
|
|
405
499
|
};
|
|
406
|
-
const create$2
|
|
500
|
+
const create$2 = (method, params) => {
|
|
407
501
|
const {
|
|
408
502
|
id,
|
|
409
503
|
promise
|
|
@@ -554,7 +648,7 @@ const warn = (...args) => {
|
|
|
554
648
|
console.warn(...args);
|
|
555
649
|
};
|
|
556
650
|
const resolve = (id, response) => {
|
|
557
|
-
const fn = get(id);
|
|
651
|
+
const fn = get$1(id);
|
|
558
652
|
if (!fn) {
|
|
559
653
|
console.log(response);
|
|
560
654
|
warn(`callback ${id} may already be disposed`);
|
|
@@ -695,7 +789,7 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
695
789
|
const {
|
|
696
790
|
message,
|
|
697
791
|
promise
|
|
698
|
-
} = create$2
|
|
792
|
+
} = create$2(method, params);
|
|
699
793
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
700
794
|
ipc.sendAndTransfer(message);
|
|
701
795
|
} else {
|
|
@@ -704,11 +798,11 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
|
|
|
704
798
|
const responseMessage = await promise;
|
|
705
799
|
return unwrapJsonRpcResult(responseMessage);
|
|
706
800
|
};
|
|
707
|
-
const send
|
|
801
|
+
const send = (transport, method, ...params) => {
|
|
708
802
|
const message = create$4(method, params);
|
|
709
803
|
transport.send(message);
|
|
710
804
|
};
|
|
711
|
-
const invoke$
|
|
805
|
+
const invoke$3 = (ipc, method, ...params) => {
|
|
712
806
|
return invokeHelper(ipc, method, params, false);
|
|
713
807
|
};
|
|
714
808
|
const invokeAndTransfer$1 = (ipc, method, ...params) => {
|
|
@@ -719,11 +813,11 @@ const commands = Object.create(null);
|
|
|
719
813
|
const register = commandMap => {
|
|
720
814
|
Object.assign(commands, commandMap);
|
|
721
815
|
};
|
|
722
|
-
const getCommand
|
|
816
|
+
const getCommand = key => {
|
|
723
817
|
return commands[key];
|
|
724
818
|
};
|
|
725
|
-
const execute
|
|
726
|
-
const fn = getCommand
|
|
819
|
+
const execute = (command, ...args) => {
|
|
820
|
+
const fn = getCommand(command);
|
|
727
821
|
if (!fn) {
|
|
728
822
|
throw new Error(`command not found ${command}`);
|
|
729
823
|
}
|
|
@@ -738,10 +832,10 @@ const createRpc = ipc => {
|
|
|
738
832
|
* @deprecated
|
|
739
833
|
*/
|
|
740
834
|
send(method, ...params) {
|
|
741
|
-
send
|
|
835
|
+
send(ipc, method, ...params);
|
|
742
836
|
},
|
|
743
837
|
invoke(method, ...params) {
|
|
744
|
-
return invoke$
|
|
838
|
+
return invoke$3(ipc, method, ...params);
|
|
745
839
|
},
|
|
746
840
|
invokeAndTransfer(method, ...params) {
|
|
747
841
|
return invokeAndTransfer$1(ipc, method, ...params);
|
|
@@ -752,26 +846,26 @@ const createRpc = ipc => {
|
|
|
752
846
|
};
|
|
753
847
|
return rpc;
|
|
754
848
|
};
|
|
755
|
-
const requiresSocket
|
|
849
|
+
const requiresSocket = () => {
|
|
756
850
|
return false;
|
|
757
851
|
};
|
|
758
|
-
const preparePrettyError
|
|
852
|
+
const preparePrettyError = error => {
|
|
759
853
|
return error;
|
|
760
854
|
};
|
|
761
|
-
const logError
|
|
855
|
+
const logError = () => {
|
|
762
856
|
// handled by renderer worker
|
|
763
857
|
};
|
|
764
|
-
const handleMessage
|
|
765
|
-
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket
|
|
766
|
-
const actualExecute = event?.target?.execute || execute
|
|
767
|
-
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError
|
|
858
|
+
const handleMessage = event => {
|
|
859
|
+
const actualRequiresSocket = event?.target?.requiresSocket || requiresSocket;
|
|
860
|
+
const actualExecute = event?.target?.execute || execute;
|
|
861
|
+
return handleJsonRpcMessage(event.target, event.data, actualExecute, resolve, preparePrettyError, logError, actualRequiresSocket);
|
|
768
862
|
};
|
|
769
|
-
const handleIpc
|
|
863
|
+
const handleIpc = ipc => {
|
|
770
864
|
if ('addEventListener' in ipc) {
|
|
771
|
-
ipc.addEventListener('message', handleMessage
|
|
865
|
+
ipc.addEventListener('message', handleMessage);
|
|
772
866
|
} else if ('on' in ipc) {
|
|
773
867
|
// deprecated
|
|
774
|
-
ipc.on('message', handleMessage
|
|
868
|
+
ipc.on('message', handleMessage);
|
|
775
869
|
}
|
|
776
870
|
};
|
|
777
871
|
const listen$1 = async (module, options) => {
|
|
@@ -782,176 +876,130 @@ const listen$1 = async (module, options) => {
|
|
|
782
876
|
const ipc = module.wrap(rawIpc);
|
|
783
877
|
return ipc;
|
|
784
878
|
};
|
|
785
|
-
const create$
|
|
879
|
+
const create$9 = async ({
|
|
880
|
+
commandMap,
|
|
881
|
+
messagePort,
|
|
882
|
+
isMessagePortOpen
|
|
883
|
+
}) => {
|
|
884
|
+
// TODO create a commandMap per rpc instance
|
|
885
|
+
register(commandMap);
|
|
886
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
887
|
+
messagePort,
|
|
888
|
+
isMessagePortOpen
|
|
889
|
+
});
|
|
890
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
891
|
+
handleIpc(ipc);
|
|
892
|
+
const rpc = createRpc(ipc);
|
|
893
|
+
return rpc;
|
|
894
|
+
};
|
|
895
|
+
const MessagePortRpcParent = {
|
|
896
|
+
__proto__: null,
|
|
897
|
+
create: create$9
|
|
898
|
+
};
|
|
899
|
+
const create$1 = async ({
|
|
786
900
|
commandMap
|
|
787
901
|
}) => {
|
|
788
902
|
// TODO create a commandMap per rpc instance
|
|
789
903
|
register(commandMap);
|
|
790
904
|
const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
|
|
791
|
-
handleIpc
|
|
905
|
+
handleIpc(ipc);
|
|
792
906
|
const rpc = createRpc(ipc);
|
|
793
907
|
return rpc;
|
|
794
908
|
};
|
|
795
909
|
const WebWorkerRpcClient = {
|
|
796
910
|
__proto__: null,
|
|
797
|
-
create: create$
|
|
911
|
+
create: create$1
|
|
798
912
|
};
|
|
799
913
|
|
|
800
|
-
const
|
|
801
|
-
|
|
914
|
+
const rpcs = Object.create(null);
|
|
915
|
+
const set$7 = (id, rpc) => {
|
|
916
|
+
rpcs[id] = rpc;
|
|
802
917
|
};
|
|
803
|
-
const
|
|
804
|
-
return
|
|
805
|
-
};
|
|
806
|
-
|
|
807
|
-
const processName = 'embeds-worker';
|
|
808
|
-
|
|
809
|
-
const execute = (command, ...args) => {
|
|
810
|
-
const fn = getCommand(command);
|
|
811
|
-
if (!fn) {
|
|
812
|
-
throw new Error(`[${processName}] command not found ${command}`);
|
|
813
|
-
}
|
|
814
|
-
return fn(...args);
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
const requiresSocket = () => {
|
|
818
|
-
return false;
|
|
819
|
-
};
|
|
820
|
-
const preparePrettyError = error => {
|
|
821
|
-
return error;
|
|
822
|
-
};
|
|
823
|
-
const logError = error => {
|
|
824
|
-
console.error(error);
|
|
825
|
-
};
|
|
826
|
-
const handleMessage = event => {
|
|
827
|
-
return handleJsonRpcMessage(event.target, event.data, execute, resolve, preparePrettyError, logError, requiresSocket);
|
|
828
|
-
};
|
|
829
|
-
const handleIpc = ipc => {
|
|
830
|
-
ipc.onmessage = handleMessage;
|
|
831
|
-
};
|
|
832
|
-
|
|
833
|
-
const getPortTuple = () => {
|
|
834
|
-
const {
|
|
835
|
-
port1,
|
|
836
|
-
port2
|
|
837
|
-
} = new MessageChannel();
|
|
838
|
-
return {
|
|
839
|
-
port1,
|
|
840
|
-
port2
|
|
841
|
-
};
|
|
918
|
+
const get = id => {
|
|
919
|
+
return rpcs[id];
|
|
842
920
|
};
|
|
843
921
|
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
const state$1 = {
|
|
847
|
-
rpc: undefined
|
|
848
|
-
};
|
|
849
|
-
const send = (method, ...params) => {
|
|
850
|
-
const rpc = state$1.rpc;
|
|
851
|
-
// @ts-ignore
|
|
852
|
-
return rpc.send(method, ...params);
|
|
853
|
-
};
|
|
854
|
-
const invokeAndTransfer = (method, ...params) => {
|
|
855
|
-
const rpc = state$1.rpc;
|
|
856
|
-
// @ts-ignore
|
|
857
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
858
|
-
};
|
|
859
|
-
const setRpc = rpc => {
|
|
860
|
-
state$1.rpc = rpc;
|
|
861
|
-
};
|
|
922
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
862
923
|
|
|
863
|
-
const create
|
|
864
|
-
initialCommand
|
|
865
|
-
}) => {
|
|
866
|
-
const {
|
|
867
|
-
port1,
|
|
868
|
-
port2
|
|
869
|
-
} = getPortTuple();
|
|
870
|
-
// TODO call sendMessagePortToSharedProcess function instead
|
|
871
|
-
await invokeAndTransfer('IpcParent.create', {
|
|
872
|
-
method: 8,
|
|
873
|
-
type: 1,
|
|
874
|
-
initialCommand,
|
|
875
|
-
port: port1,
|
|
876
|
-
raw: true,
|
|
877
|
-
ipcId: EmbedsWorker
|
|
878
|
-
});
|
|
879
|
-
return port2;
|
|
880
|
-
};
|
|
881
|
-
const wrap = port => {
|
|
924
|
+
const create = rpcId => {
|
|
882
925
|
return {
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
926
|
+
// @ts-ignore
|
|
927
|
+
invoke(method, ...params) {
|
|
928
|
+
const rpc = get(rpcId);
|
|
929
|
+
// @ts-ignore
|
|
930
|
+
return rpc.invoke(method, ...params);
|
|
886
931
|
},
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
};
|
|
893
|
-
listener(syntheticEvent);
|
|
894
|
-
};
|
|
895
|
-
this.port.onmessage = wrappedListener;
|
|
932
|
+
// @ts-ignore
|
|
933
|
+
invokeAndTransfer(method, ...params) {
|
|
934
|
+
const rpc = get(rpcId);
|
|
935
|
+
// @ts-ignore
|
|
936
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
896
937
|
},
|
|
897
|
-
|
|
938
|
+
set(rpc) {
|
|
939
|
+
set$7(rpcId, rpc);
|
|
898
940
|
}
|
|
899
941
|
};
|
|
900
942
|
};
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
943
|
+
const MainProcess$1 = -5;
|
|
944
|
+
const RendererWorker$1 = 1;
|
|
945
|
+
const {
|
|
946
|
+
invoke: invoke$5,
|
|
947
|
+
set: set$5
|
|
948
|
+
} = create(MainProcess$1);
|
|
949
|
+
const EmbedsProcess = {
|
|
950
|
+
__proto__: null,
|
|
951
|
+
invoke: invoke$5,
|
|
952
|
+
set: set$5
|
|
953
|
+
};
|
|
954
|
+
const {
|
|
955
|
+
invoke: invoke$2,
|
|
956
|
+
invokeAndTransfer: invokeAndTransfer$2,
|
|
957
|
+
set: set$2
|
|
958
|
+
} = create(RendererWorker$1);
|
|
959
|
+
const RendererWorker = {
|
|
960
|
+
__proto__: null,
|
|
961
|
+
invoke: invoke$2,
|
|
962
|
+
invokeAndTransfer: invokeAndTransfer$2,
|
|
963
|
+
set: set$2
|
|
906
964
|
};
|
|
907
965
|
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
initialCommand: 'HandleMessagePortForEmbedsProcess.handleMessagePortForEmbedsProcess'
|
|
912
|
-
});
|
|
913
|
-
handleIpc(ipc);
|
|
914
|
-
return ipc;
|
|
915
|
-
} catch (error) {
|
|
916
|
-
throw new VError(error, `Failed to launch embeds process`);
|
|
917
|
-
}
|
|
918
|
-
};
|
|
966
|
+
const {
|
|
967
|
+
set: set$1,
|
|
968
|
+
invoke: invoke$1} = EmbedsProcess;
|
|
919
969
|
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
return state.workerPromise;
|
|
926
|
-
};
|
|
927
|
-
const invoke = async (method, ...params) => {
|
|
928
|
-
const ipc = await getOrCreate();
|
|
929
|
-
return invoke$1(ipc, method, ...params);
|
|
930
|
-
};
|
|
970
|
+
const {
|
|
971
|
+
invoke,
|
|
972
|
+
set,
|
|
973
|
+
invokeAndTransfer
|
|
974
|
+
} = RendererWorker;
|
|
931
975
|
|
|
932
976
|
const ERR_ABORTED = 'ERR_ABORTED';
|
|
933
977
|
const ERR_FAILED = 'ERR_FAILED';
|
|
934
978
|
|
|
935
979
|
const createWebContentsView = async (restoreId, fallThroughKeyBindings) => {
|
|
936
|
-
|
|
980
|
+
// @ts-ignore
|
|
981
|
+
const id = await invoke$1('ElectronWebContentsView.createWebContentsView', restoreId, fallThroughKeyBindings);
|
|
937
982
|
return id;
|
|
938
983
|
};
|
|
939
984
|
const disposeWebContentsView = id => {
|
|
940
|
-
return invoke('ElectronWebContentsView.disposeWebContentsView', id);
|
|
985
|
+
return invoke$1('ElectronWebContentsView.disposeWebContentsView', id);
|
|
941
986
|
};
|
|
942
987
|
const resizeWebContentsView = (id, x, y, width, height) => {
|
|
943
|
-
|
|
988
|
+
// @ts-ignore
|
|
989
|
+
return invoke$1('ElectronWebContentsView.resizeBrowserView', id, x, y, width, height);
|
|
944
990
|
};
|
|
945
991
|
const setIframeSrcFallback = async (id, error) => {
|
|
946
992
|
const {
|
|
947
993
|
code,
|
|
948
994
|
message
|
|
949
995
|
} = error;
|
|
950
|
-
|
|
996
|
+
// @ts-ignore
|
|
997
|
+
await invoke$1('ElectronWebContentsView.setIframeSrcFallback', id, code, message);
|
|
951
998
|
};
|
|
952
999
|
const setIframeSrc = async (id, iframeSrc) => {
|
|
953
1000
|
try {
|
|
954
|
-
|
|
1001
|
+
// @ts-ignore
|
|
1002
|
+
await invoke$1('ElectronWebContentsView.setIframeSrc', id, iframeSrc);
|
|
955
1003
|
} catch (error) {
|
|
956
1004
|
console.log({
|
|
957
1005
|
error
|
|
@@ -977,50 +1025,67 @@ const setIframeSrc = async (id, iframeSrc) => {
|
|
|
977
1025
|
}
|
|
978
1026
|
};
|
|
979
1027
|
const focus = id => {
|
|
980
|
-
|
|
1028
|
+
// @ts-ignore
|
|
1029
|
+
return invoke$1('ElectronWebContentsView.focus', id);
|
|
981
1030
|
};
|
|
982
1031
|
const openDevtools = id => {
|
|
983
|
-
|
|
1032
|
+
// @ts-ignore
|
|
1033
|
+
return invoke$1('ElectronWebContentsView.openDevtools', id);
|
|
984
1034
|
};
|
|
985
1035
|
const reload = id => {
|
|
986
|
-
|
|
1036
|
+
// @ts-ignore
|
|
1037
|
+
return invoke$1('ElectronWebContentsView.reload', id);
|
|
987
1038
|
};
|
|
988
1039
|
const show = id => {
|
|
989
|
-
|
|
1040
|
+
// @ts-ignore
|
|
1041
|
+
return invoke$1('ElectronWebContentsView.show', id);
|
|
990
1042
|
};
|
|
991
1043
|
const hide = id => {
|
|
992
|
-
|
|
1044
|
+
// @ts-ignore
|
|
1045
|
+
return invoke$1('ElectronWebContentsView.hide', id);
|
|
993
1046
|
};
|
|
994
1047
|
const forward = id => {
|
|
995
|
-
|
|
1048
|
+
// @ts-ignore
|
|
1049
|
+
return invoke$1('ElectronWebContentsView.forward', id);
|
|
996
1050
|
};
|
|
997
1051
|
const backward = id => {
|
|
998
|
-
|
|
1052
|
+
// @ts-ignore
|
|
1053
|
+
return invoke$1('ElectronWebContentsView.backward', id);
|
|
999
1054
|
};
|
|
1000
1055
|
const getDomTree = id => {
|
|
1001
|
-
|
|
1056
|
+
// @ts-ignore
|
|
1057
|
+
return invoke$1('ElectronWebContentsView.getDomTree', id);
|
|
1002
1058
|
};
|
|
1003
1059
|
const insertCss = (id, css) => {
|
|
1004
|
-
|
|
1060
|
+
// @ts-ignore
|
|
1061
|
+
return invoke$1('ElectronWebContentsView.insertCss', id, css);
|
|
1062
|
+
};
|
|
1063
|
+
const insertJavaScript = (id, code) => {
|
|
1064
|
+
// @ts-ignore
|
|
1065
|
+
return invoke$1('ElectronWebContentsView.insertJavaScript', id, code);
|
|
1005
1066
|
};
|
|
1006
1067
|
const cancelNavigation = id => {
|
|
1007
|
-
|
|
1068
|
+
// @ts-ignore
|
|
1069
|
+
return invoke$1('ElectronWebContentsView.cancelNavigation', id);
|
|
1008
1070
|
};
|
|
1009
1071
|
const inspectElement = (id, x, y) => {
|
|
1010
|
-
|
|
1072
|
+
// @ts-ignore
|
|
1073
|
+
return invoke$1('ElectronWebContentsView.inspectElement', id, x, y);
|
|
1011
1074
|
};
|
|
1012
1075
|
const copyImageAt = (id, x, y) => {
|
|
1013
|
-
|
|
1076
|
+
// @ts-ignore
|
|
1077
|
+
return invoke$1('ElectronWebContentsView.copyImageAt', id, x, y);
|
|
1014
1078
|
};
|
|
1015
1079
|
const setFallthroughKeyBindings = (id, fallthroughKeybindings) => {
|
|
1016
1080
|
// TODO
|
|
1017
1081
|
// return EmbedsProcess.invoke('ElectronWebContentsView.setFallthroughKeyBindings', id, fallthroughKeybindings)
|
|
1018
1082
|
};
|
|
1019
1083
|
const getStats = (id, fallthroughKeybindings) => {
|
|
1020
|
-
|
|
1084
|
+
// @ts-ignore
|
|
1085
|
+
return invoke$1('ElectronWebContentsView.getStats', id, fallthroughKeybindings);
|
|
1021
1086
|
};
|
|
1022
1087
|
const forwardEvent = key => (id, ...args) => {
|
|
1023
|
-
|
|
1088
|
+
return invoke(key, ...args);
|
|
1024
1089
|
};
|
|
1025
1090
|
const handleDidNavigate = forwardEvent('ElectronBrowserView.handleDidNavigate');
|
|
1026
1091
|
const handleTitleUpdated = forwardEvent('ElectronBrowserView.handleTitleUpdated');
|
|
@@ -1031,6 +1096,51 @@ const exit = () => {
|
|
|
1031
1096
|
self.close();
|
|
1032
1097
|
};
|
|
1033
1098
|
|
|
1099
|
+
const getPortTuple = () => {
|
|
1100
|
+
const {
|
|
1101
|
+
port1,
|
|
1102
|
+
port2
|
|
1103
|
+
} = new MessageChannel();
|
|
1104
|
+
return {
|
|
1105
|
+
port1,
|
|
1106
|
+
port2
|
|
1107
|
+
};
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
const EmbedsWorker = 208;
|
|
1111
|
+
|
|
1112
|
+
const sendMessagePortToEmbedsProcess = async port => {
|
|
1113
|
+
const outerCommand = 'HandleMessagePortForEmbedsProcess.handleMessagePortForEmbedsProcess';
|
|
1114
|
+
// TODO
|
|
1115
|
+
// @ts-ignore
|
|
1116
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, outerCommand, EmbedsWorker);
|
|
1117
|
+
};
|
|
1118
|
+
|
|
1119
|
+
const createEmbedsProcessRpc = async () => {
|
|
1120
|
+
try {
|
|
1121
|
+
const {
|
|
1122
|
+
port1,
|
|
1123
|
+
port2
|
|
1124
|
+
} = getPortTuple();
|
|
1125
|
+
await sendMessagePortToEmbedsProcess(port2);
|
|
1126
|
+
port1.start();
|
|
1127
|
+
const rpc = await MessagePortRpcParent.create({
|
|
1128
|
+
commandMap: {},
|
|
1129
|
+
messagePort: port1,
|
|
1130
|
+
isMessagePortOpen: true
|
|
1131
|
+
});
|
|
1132
|
+
// TODO createMessageportRpcParent should call port start
|
|
1133
|
+
return rpc;
|
|
1134
|
+
} catch (error) {
|
|
1135
|
+
throw new VError(error, `Failed to create embeds process rpc`);
|
|
1136
|
+
}
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
const initialize = async () => {
|
|
1140
|
+
const rpc = await createEmbedsProcessRpc();
|
|
1141
|
+
set$1(rpc);
|
|
1142
|
+
};
|
|
1143
|
+
|
|
1034
1144
|
const commandMap = {
|
|
1035
1145
|
'ElectronWebContentsView.backward': backward,
|
|
1036
1146
|
'ElectronWebContentsView.cancelNavigation': cancelNavigation,
|
|
@@ -1039,14 +1149,15 @@ const commandMap = {
|
|
|
1039
1149
|
'ElectronWebContentsView.disposeWebContentsView': disposeWebContentsView,
|
|
1040
1150
|
'ElectronWebContentsView.focus': focus,
|
|
1041
1151
|
'ElectronWebContentsView.forward': forward,
|
|
1152
|
+
'ElectronWebContentsView.getDomTree': getDomTree,
|
|
1042
1153
|
'ElectronWebContentsView.getStats': getStats,
|
|
1043
1154
|
'ElectronWebContentsView.handleContextMenu': handleContextMenu,
|
|
1044
1155
|
'ElectronWebContentsView.handleDidNavigate': handleDidNavigate,
|
|
1045
1156
|
'ElectronWebContentsView.handleTitleUpdated': handleTitleUpdated,
|
|
1046
|
-
'ElectronWebContentsView.getDomTree': getDomTree,
|
|
1047
|
-
'ElectronWebContentsView.insertCss': insertCss,
|
|
1048
1157
|
'ElectronWebContentsView.handleWillNavigate': handleWillNavigate,
|
|
1049
1158
|
'ElectronWebContentsView.hide': hide,
|
|
1159
|
+
'ElectronWebContentsView.insertCss': insertCss,
|
|
1160
|
+
'ElectronWebContentsView.insertJavaScript': insertJavaScript,
|
|
1050
1161
|
'ElectronWebContentsView.inspectElement': inspectElement,
|
|
1051
1162
|
'ElectronWebContentsView.openDevtools': openDevtools,
|
|
1052
1163
|
'ElectronWebContentsView.reload': reload,
|
|
@@ -1054,14 +1165,15 @@ const commandMap = {
|
|
|
1054
1165
|
'ElectronWebContentsView.setFallthroughKeyBindings': setFallthroughKeyBindings,
|
|
1055
1166
|
'ElectronWebContentsView.setIframeSrc': setIframeSrc,
|
|
1056
1167
|
'ElectronWebContentsView.show': show,
|
|
1057
|
-
'Exit.exit': exit
|
|
1168
|
+
'Exit.exit': exit,
|
|
1169
|
+
'Initialize.initialize': initialize
|
|
1058
1170
|
};
|
|
1059
1171
|
|
|
1060
1172
|
const listen = async () => {
|
|
1061
1173
|
const rpc = await WebWorkerRpcClient.create({
|
|
1062
1174
|
commandMap: commandMap
|
|
1063
1175
|
});
|
|
1064
|
-
|
|
1176
|
+
set(rpc);
|
|
1065
1177
|
};
|
|
1066
1178
|
|
|
1067
1179
|
const main = async () => {
|