@lvce-editor/running-extensions-view 1.0.0 → 1.1.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/runningExtensionsViewMain.js +222 -16
- package/package.json +1 -1
|
@@ -374,6 +374,100 @@ const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
|
374
374
|
listen: listen$6,
|
|
375
375
|
wrap: wrap$e
|
|
376
376
|
};
|
|
377
|
+
const addListener = (emitter, type, callback) => {
|
|
378
|
+
if ('addEventListener' in emitter) {
|
|
379
|
+
emitter.addEventListener(type, callback);
|
|
380
|
+
} else {
|
|
381
|
+
emitter.on(type, callback);
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const removeListener = (emitter, type, callback) => {
|
|
385
|
+
if ('removeEventListener' in emitter) {
|
|
386
|
+
emitter.removeEventListener(type, callback);
|
|
387
|
+
} else {
|
|
388
|
+
emitter.off(type, callback);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
const getFirstEvent = (eventEmitter, eventMap) => {
|
|
392
|
+
const {
|
|
393
|
+
promise,
|
|
394
|
+
resolve
|
|
395
|
+
} = Promise.withResolvers();
|
|
396
|
+
const listenerMap = Object.create(null);
|
|
397
|
+
const cleanup = value => {
|
|
398
|
+
for (const event of Object.keys(eventMap)) {
|
|
399
|
+
removeListener(eventEmitter, event, listenerMap[event]);
|
|
400
|
+
}
|
|
401
|
+
resolve(value);
|
|
402
|
+
};
|
|
403
|
+
for (const [event, type] of Object.entries(eventMap)) {
|
|
404
|
+
const listener = event => {
|
|
405
|
+
cleanup({
|
|
406
|
+
event,
|
|
407
|
+
type
|
|
408
|
+
});
|
|
409
|
+
};
|
|
410
|
+
addListener(eventEmitter, event, listener);
|
|
411
|
+
listenerMap[event] = listener;
|
|
412
|
+
}
|
|
413
|
+
return promise;
|
|
414
|
+
};
|
|
415
|
+
const Message$1 = 3;
|
|
416
|
+
const create$5$1 = async ({
|
|
417
|
+
isMessagePortOpen,
|
|
418
|
+
messagePort
|
|
419
|
+
}) => {
|
|
420
|
+
if (!isMessagePort(messagePort)) {
|
|
421
|
+
throw new IpcError('port must be of type MessagePort');
|
|
422
|
+
}
|
|
423
|
+
if (isMessagePortOpen) {
|
|
424
|
+
return messagePort;
|
|
425
|
+
}
|
|
426
|
+
const eventPromise = getFirstEvent(messagePort, {
|
|
427
|
+
message: Message$1
|
|
428
|
+
});
|
|
429
|
+
messagePort.start();
|
|
430
|
+
const {
|
|
431
|
+
event,
|
|
432
|
+
type
|
|
433
|
+
} = await eventPromise;
|
|
434
|
+
if (type !== Message$1) {
|
|
435
|
+
throw new IpcError('Failed to wait for ipc message');
|
|
436
|
+
}
|
|
437
|
+
if (event.data !== readyMessage) {
|
|
438
|
+
throw new IpcError('unexpected first message');
|
|
439
|
+
}
|
|
440
|
+
return messagePort;
|
|
441
|
+
};
|
|
442
|
+
const signal$1 = messagePort => {
|
|
443
|
+
messagePort.start();
|
|
444
|
+
};
|
|
445
|
+
class IpcParentWithMessagePort extends Ipc {
|
|
446
|
+
getData = getData$2;
|
|
447
|
+
send(message) {
|
|
448
|
+
this._rawIpc.postMessage(message);
|
|
449
|
+
}
|
|
450
|
+
sendAndTransfer(message) {
|
|
451
|
+
const transfer = getTransferrables(message);
|
|
452
|
+
this._rawIpc.postMessage(message, transfer);
|
|
453
|
+
}
|
|
454
|
+
dispose() {
|
|
455
|
+
this._rawIpc.close();
|
|
456
|
+
}
|
|
457
|
+
onMessage(callback) {
|
|
458
|
+
this._rawIpc.addEventListener('message', callback);
|
|
459
|
+
}
|
|
460
|
+
onClose(callback) {}
|
|
461
|
+
}
|
|
462
|
+
const wrap$5 = messagePort => {
|
|
463
|
+
return new IpcParentWithMessagePort(messagePort);
|
|
464
|
+
};
|
|
465
|
+
const IpcParentWithMessagePort$1 = {
|
|
466
|
+
__proto__: null,
|
|
467
|
+
create: create$5$1,
|
|
468
|
+
signal: signal$1,
|
|
469
|
+
wrap: wrap$5
|
|
470
|
+
};
|
|
377
471
|
|
|
378
472
|
class CommandNotFoundError extends Error {
|
|
379
473
|
constructor(command) {
|
|
@@ -634,7 +728,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
634
728
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
635
729
|
return create$1$1(id, errorProperty);
|
|
636
730
|
};
|
|
637
|
-
const create$
|
|
731
|
+
const create$a = (message, result) => {
|
|
638
732
|
return {
|
|
639
733
|
id: message.id,
|
|
640
734
|
jsonrpc: Two$1,
|
|
@@ -643,7 +737,7 @@ const create$7 = (message, result) => {
|
|
|
643
737
|
};
|
|
644
738
|
const getSuccessResponse = (message, result) => {
|
|
645
739
|
const resultProperty = result ?? null;
|
|
646
|
-
return create$
|
|
740
|
+
return create$a(message, resultProperty);
|
|
647
741
|
};
|
|
648
742
|
const getErrorResponseSimple = (id, error) => {
|
|
649
743
|
return {
|
|
@@ -737,7 +831,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
737
831
|
|
|
738
832
|
const Two = '2.0';
|
|
739
833
|
|
|
740
|
-
const create$
|
|
834
|
+
const create$9 = (method, params) => {
|
|
741
835
|
return {
|
|
742
836
|
jsonrpc: Two,
|
|
743
837
|
method,
|
|
@@ -745,7 +839,7 @@ const create$6 = (method, params) => {
|
|
|
745
839
|
};
|
|
746
840
|
};
|
|
747
841
|
|
|
748
|
-
const create$
|
|
842
|
+
const create$8 = (id, method, params) => {
|
|
749
843
|
const message = {
|
|
750
844
|
id,
|
|
751
845
|
jsonrpc: Two,
|
|
@@ -756,12 +850,12 @@ const create$5 = (id, method, params) => {
|
|
|
756
850
|
};
|
|
757
851
|
|
|
758
852
|
let id = 0;
|
|
759
|
-
const create$
|
|
853
|
+
const create$7 = () => {
|
|
760
854
|
return ++id;
|
|
761
855
|
};
|
|
762
856
|
|
|
763
857
|
const registerPromise = map => {
|
|
764
|
-
const id = create$
|
|
858
|
+
const id = create$7();
|
|
765
859
|
const {
|
|
766
860
|
promise,
|
|
767
861
|
resolve
|
|
@@ -778,7 +872,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
778
872
|
id,
|
|
779
873
|
promise
|
|
780
874
|
} = registerPromise(callbacks);
|
|
781
|
-
const message = create$
|
|
875
|
+
const message = create$8(id, method, params);
|
|
782
876
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
783
877
|
ipc.sendAndTransfer(message);
|
|
784
878
|
} else {
|
|
@@ -814,7 +908,7 @@ const createRpc = ipc => {
|
|
|
814
908
|
* @deprecated
|
|
815
909
|
*/
|
|
816
910
|
send(method, ...params) {
|
|
817
|
-
const message = create$
|
|
911
|
+
const message = create$9(method, params);
|
|
818
912
|
ipc.send(message);
|
|
819
913
|
}
|
|
820
914
|
};
|
|
@@ -854,6 +948,83 @@ const listen$1 = async (module, options) => {
|
|
|
854
948
|
return ipc;
|
|
855
949
|
};
|
|
856
950
|
|
|
951
|
+
const create$6 = async ({
|
|
952
|
+
commandMap,
|
|
953
|
+
isMessagePortOpen = true,
|
|
954
|
+
messagePort
|
|
955
|
+
}) => {
|
|
956
|
+
// TODO create a commandMap per rpc instance
|
|
957
|
+
register(commandMap);
|
|
958
|
+
const rawIpc = await IpcParentWithMessagePort$1.create({
|
|
959
|
+
isMessagePortOpen,
|
|
960
|
+
messagePort
|
|
961
|
+
});
|
|
962
|
+
const ipc = IpcParentWithMessagePort$1.wrap(rawIpc);
|
|
963
|
+
handleIpc(ipc);
|
|
964
|
+
const rpc = createRpc(ipc);
|
|
965
|
+
messagePort.start();
|
|
966
|
+
return rpc;
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
const create$5 = async ({
|
|
970
|
+
commandMap,
|
|
971
|
+
isMessagePortOpen,
|
|
972
|
+
send
|
|
973
|
+
}) => {
|
|
974
|
+
const {
|
|
975
|
+
port1,
|
|
976
|
+
port2
|
|
977
|
+
} = new MessageChannel();
|
|
978
|
+
await send(port1);
|
|
979
|
+
return create$6({
|
|
980
|
+
commandMap,
|
|
981
|
+
isMessagePortOpen,
|
|
982
|
+
messagePort: port2
|
|
983
|
+
});
|
|
984
|
+
};
|
|
985
|
+
|
|
986
|
+
const createSharedLazyRpc = factory => {
|
|
987
|
+
let rpcPromise;
|
|
988
|
+
const getOrCreate = () => {
|
|
989
|
+
if (!rpcPromise) {
|
|
990
|
+
rpcPromise = factory();
|
|
991
|
+
}
|
|
992
|
+
return rpcPromise;
|
|
993
|
+
};
|
|
994
|
+
return {
|
|
995
|
+
async dispose() {
|
|
996
|
+
const rpc = await getOrCreate();
|
|
997
|
+
await rpc.dispose();
|
|
998
|
+
},
|
|
999
|
+
async invoke(method, ...params) {
|
|
1000
|
+
const rpc = await getOrCreate();
|
|
1001
|
+
return rpc.invoke(method, ...params);
|
|
1002
|
+
},
|
|
1003
|
+
async invokeAndTransfer(method, ...params) {
|
|
1004
|
+
const rpc = await getOrCreate();
|
|
1005
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1006
|
+
},
|
|
1007
|
+
async send(method, ...params) {
|
|
1008
|
+
const rpc = await getOrCreate();
|
|
1009
|
+
rpc.send(method, ...params);
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
};
|
|
1013
|
+
|
|
1014
|
+
const create$4 = async ({
|
|
1015
|
+
commandMap,
|
|
1016
|
+
isMessagePortOpen,
|
|
1017
|
+
send
|
|
1018
|
+
}) => {
|
|
1019
|
+
return createSharedLazyRpc(() => {
|
|
1020
|
+
return create$5({
|
|
1021
|
+
commandMap,
|
|
1022
|
+
isMessagePortOpen,
|
|
1023
|
+
send
|
|
1024
|
+
});
|
|
1025
|
+
});
|
|
1026
|
+
};
|
|
1027
|
+
|
|
857
1028
|
const create$3 = async ({
|
|
858
1029
|
commandMap
|
|
859
1030
|
}) => {
|
|
@@ -886,7 +1057,7 @@ const createMockRpc = ({
|
|
|
886
1057
|
};
|
|
887
1058
|
|
|
888
1059
|
const rpcs = Object.create(null);
|
|
889
|
-
const set$
|
|
1060
|
+
const set$3 = (id, rpc) => {
|
|
890
1061
|
rpcs[id] = rpc;
|
|
891
1062
|
};
|
|
892
1063
|
const get$1 = id => {
|
|
@@ -919,7 +1090,7 @@ const create$2 = rpcId => {
|
|
|
919
1090
|
const mockRpc = createMockRpc({
|
|
920
1091
|
commandMap
|
|
921
1092
|
});
|
|
922
|
-
set$
|
|
1093
|
+
set$3(rpcId, mockRpc);
|
|
923
1094
|
// @ts-ignore
|
|
924
1095
|
mockRpc[Symbol.dispose] = () => {
|
|
925
1096
|
remove(rpcId);
|
|
@@ -928,7 +1099,7 @@ const create$2 = rpcId => {
|
|
|
928
1099
|
return mockRpc;
|
|
929
1100
|
},
|
|
930
1101
|
set(rpc) {
|
|
931
|
-
set$
|
|
1102
|
+
set$3(rpcId, rpc);
|
|
932
1103
|
}
|
|
933
1104
|
};
|
|
934
1105
|
};
|
|
@@ -1104,6 +1275,7 @@ const VirtualDomElements = {
|
|
|
1104
1275
|
Video
|
|
1105
1276
|
};
|
|
1106
1277
|
|
|
1278
|
+
const ExtensionManagementWorker = 9006;
|
|
1107
1279
|
const RendererWorker = 1;
|
|
1108
1280
|
|
|
1109
1281
|
const SetCss = 'Viewlet.setCss';
|
|
@@ -1111,8 +1283,17 @@ const SetDom2 = 'Viewlet.setDom2';
|
|
|
1111
1283
|
|
|
1112
1284
|
const {
|
|
1113
1285
|
invoke,
|
|
1286
|
+
set: set$2
|
|
1287
|
+
} = create$2(ExtensionManagementWorker);
|
|
1288
|
+
|
|
1289
|
+
const {
|
|
1290
|
+
invokeAndTransfer,
|
|
1114
1291
|
set: set$1
|
|
1115
1292
|
} = create$2(RendererWorker);
|
|
1293
|
+
const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
|
|
1294
|
+
const command = 'Extensions.handleMessagePort';
|
|
1295
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
|
|
1296
|
+
};
|
|
1116
1297
|
|
|
1117
1298
|
const toCommandId = key => {
|
|
1118
1299
|
const dotIndex = key.indexOf('.');
|
|
@@ -1242,11 +1423,13 @@ const {
|
|
|
1242
1423
|
wrapCommand
|
|
1243
1424
|
} = create$1();
|
|
1244
1425
|
|
|
1245
|
-
const create = (uid, uri, x, y, width, height) => {
|
|
1426
|
+
const create = (uid, uri, x, y, width, height, platform, assetDir) => {
|
|
1246
1427
|
const state = {
|
|
1428
|
+
assetDir,
|
|
1247
1429
|
extensions: [],
|
|
1248
1430
|
height,
|
|
1249
1431
|
loaded: false,
|
|
1432
|
+
platform,
|
|
1250
1433
|
uid,
|
|
1251
1434
|
width,
|
|
1252
1435
|
x,
|
|
@@ -1269,12 +1452,16 @@ const diff2 = uid => {
|
|
|
1269
1452
|
return diff(uid, [isDomEqual, isCssEqual], [RenderDom, RenderCss]);
|
|
1270
1453
|
};
|
|
1271
1454
|
|
|
1272
|
-
const getRunningExtensions = async () => {
|
|
1273
|
-
return invoke('
|
|
1455
|
+
const getRunningExtensions = async (assetDir, platform) => {
|
|
1456
|
+
return invoke('Extensions.getRunningExtensions', assetDir, platform);
|
|
1274
1457
|
};
|
|
1275
1458
|
|
|
1276
1459
|
const loadContent = async state => {
|
|
1277
|
-
const
|
|
1460
|
+
const {
|
|
1461
|
+
assetDir,
|
|
1462
|
+
platform
|
|
1463
|
+
} = state;
|
|
1464
|
+
const extensions = await getRunningExtensions(assetDir, platform);
|
|
1278
1465
|
return {
|
|
1279
1466
|
...state,
|
|
1280
1467
|
extensions,
|
|
@@ -1282,8 +1469,13 @@ const loadContent = async state => {
|
|
|
1282
1469
|
};
|
|
1283
1470
|
};
|
|
1284
1471
|
|
|
1472
|
+
const getCss = (width, height) => {
|
|
1473
|
+
return `width: ${width}px; height: ${height}px;`;
|
|
1474
|
+
};
|
|
1475
|
+
|
|
1285
1476
|
const renderCss = (oldState, newState) => {
|
|
1286
|
-
|
|
1477
|
+
const css = getCss(newState.width, newState.height);
|
|
1478
|
+
return [SetCss, newState.uid, css];
|
|
1287
1479
|
};
|
|
1288
1480
|
|
|
1289
1481
|
const text = data => {
|
|
@@ -1312,6 +1504,7 @@ const getIconVirtualDom = extension => {
|
|
|
1312
1504
|
type: Div
|
|
1313
1505
|
}];
|
|
1314
1506
|
};
|
|
1507
|
+
|
|
1315
1508
|
const getExtensionVirtualDom = extension => {
|
|
1316
1509
|
const displayName = extension.name || extension.id;
|
|
1317
1510
|
return [{
|
|
@@ -1345,6 +1538,7 @@ const getExtensionVirtualDom = extension => {
|
|
|
1345
1538
|
type: Div
|
|
1346
1539
|
}, text(`Activation: ${Math.round(extension.activationTime)}ms`)];
|
|
1347
1540
|
};
|
|
1541
|
+
|
|
1348
1542
|
const getRunningExtensionsVirtualDom = (extensions, loaded) => {
|
|
1349
1543
|
const message = loaded ? 'No running extensions' : 'Loading running extensions…';
|
|
1350
1544
|
const children = extensions.length === 0 ? [{
|
|
@@ -1405,12 +1599,24 @@ const commandMap = {
|
|
|
1405
1599
|
'RunningExtensions.resize': wrapCommand(resize)
|
|
1406
1600
|
};
|
|
1407
1601
|
|
|
1602
|
+
const send = async port => {
|
|
1603
|
+
await sendMessagePortToExtensionManagementWorker(port, 0);
|
|
1604
|
+
};
|
|
1605
|
+
const initializeExtensionManagementWorker = async () => {
|
|
1606
|
+
const rpc = await create$4({
|
|
1607
|
+
commandMap: {},
|
|
1608
|
+
send
|
|
1609
|
+
});
|
|
1610
|
+
set$2(rpc);
|
|
1611
|
+
};
|
|
1612
|
+
|
|
1408
1613
|
const listen = async () => {
|
|
1409
1614
|
registerCommands(commandMap);
|
|
1410
1615
|
const rpc = await create$3({
|
|
1411
1616
|
commandMap: commandMap
|
|
1412
1617
|
});
|
|
1413
1618
|
set$1(rpc);
|
|
1619
|
+
await initializeExtensionManagementWorker();
|
|
1414
1620
|
};
|
|
1415
1621
|
|
|
1416
1622
|
const main = async () => {
|