@lvce-editor/extension-management-worker 4.10.0 → 4.12.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.
|
@@ -1578,21 +1578,21 @@ const invokeAndTransfer = (method, ...params) => {
|
|
|
1578
1578
|
return invokeAndTransfer$1(method, ...params);
|
|
1579
1579
|
};
|
|
1580
1580
|
|
|
1581
|
-
const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, createRpc, invokeAndTransfer) => {
|
|
1581
|
+
const createIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName, createRpc, invokeAndTransfer) => {
|
|
1582
1582
|
return createRpc({
|
|
1583
1583
|
commandMap: commandMapRef,
|
|
1584
1584
|
isMessagePortOpen: true,
|
|
1585
1585
|
send(port) {
|
|
1586
|
-
return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath);
|
|
1586
|
+
return invokeAndTransfer('LaunchIsolatedExtensionHostWorker.launchIsolatedExtensionHostWorker', port, extensionId, absolutePath, workerName);
|
|
1587
1587
|
}
|
|
1588
1588
|
});
|
|
1589
1589
|
};
|
|
1590
|
-
const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath) => {
|
|
1590
|
+
const getOrCreateIsolatedExtensionHostWorker = async (extensionId, absolutePath, workerName = '') => {
|
|
1591
1591
|
const existingRpc = get$3(extensionId);
|
|
1592
1592
|
if (existingRpc) {
|
|
1593
1593
|
return existingRpc;
|
|
1594
1594
|
}
|
|
1595
|
-
const rpc = await createIsolatedExtensionHostWorker(extensionId, absolutePath, create$7, invokeAndTransfer);
|
|
1595
|
+
const rpc = await createIsolatedExtensionHostWorker(extensionId, absolutePath, workerName, create$7, invokeAndTransfer);
|
|
1596
1596
|
set$3(extensionId, rpc);
|
|
1597
1597
|
return rpc;
|
|
1598
1598
|
};
|
|
@@ -1696,7 +1696,7 @@ const activateExtension3 = async (extension, absolutePath, activationEvent, plat
|
|
|
1696
1696
|
handleRpcInfos(extension, platform);
|
|
1697
1697
|
const extensionId = extension.id || interExtensionId(extension.uri);
|
|
1698
1698
|
if (isExtensionIsolated(extension)) {
|
|
1699
|
-
await getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath);
|
|
1699
|
+
await getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath, extension.workerName || '');
|
|
1700
1700
|
return;
|
|
1701
1701
|
}
|
|
1702
1702
|
await importExtension(extensionId, absolutePath, activationEvent);
|
|
@@ -1947,6 +1947,10 @@ const getWebManifestPath = path => {
|
|
|
1947
1947
|
return manifestPath;
|
|
1948
1948
|
};
|
|
1949
1949
|
|
|
1950
|
+
const invalidateExtensionsCache = async () => {
|
|
1951
|
+
await invoke$3('ExtensionManagement.invalidateExtensionsCache');
|
|
1952
|
+
};
|
|
1953
|
+
|
|
1950
1954
|
const state = {
|
|
1951
1955
|
rpc: undefined
|
|
1952
1956
|
};
|
|
@@ -1975,6 +1979,7 @@ const addWebExtension = async path => {
|
|
|
1975
1979
|
const manifest = await getWebExtensionManifest(path, manifestPath);
|
|
1976
1980
|
addWebExtension$1(manifest);
|
|
1977
1981
|
clearCachedExtensions();
|
|
1982
|
+
await invalidateExtensionsCache();
|
|
1978
1983
|
if (hasStatusBarItems(manifest)) {
|
|
1979
1984
|
await handleChange(manifest.id || path);
|
|
1980
1985
|
}
|
|
@@ -2112,10 +2117,6 @@ const enableExtension2$1 = async (id, platform) => {
|
|
|
2112
2117
|
}
|
|
2113
2118
|
};
|
|
2114
2119
|
|
|
2115
|
-
const invalidateExtensionsCache = async () => {
|
|
2116
|
-
await invoke$3('ExtensionManagement.invalidateExtensionsCache');
|
|
2117
|
-
};
|
|
2118
|
-
|
|
2119
2120
|
const disableExtension2 = async (id, platform) => {
|
|
2120
2121
|
string(id);
|
|
2121
2122
|
number(platform);
|
|
@@ -2159,6 +2160,7 @@ const enableExtension2 = async (id, platform) => {
|
|
|
2159
2160
|
await writeFile(disabledExtensionsJsonPath, newContent);
|
|
2160
2161
|
}
|
|
2161
2162
|
await enableExtension2$1(id, platform);
|
|
2163
|
+
await invalidateExtensionsCache();
|
|
2162
2164
|
};
|
|
2163
2165
|
|
|
2164
2166
|
const enableExtension = async (id, isTest) => {
|
|
@@ -2245,7 +2247,7 @@ const getRpc$1 = async (extension, assetDir, platform) => {
|
|
|
2245
2247
|
return existingRpc;
|
|
2246
2248
|
}
|
|
2247
2249
|
const absolutePath = getAbsolutePath(extension, assetDir, platform);
|
|
2248
|
-
return getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath);
|
|
2250
|
+
return getOrCreateIsolatedExtensionHostWorker(extensionId, absolutePath, extension.workerName || '');
|
|
2249
2251
|
};
|
|
2250
2252
|
|
|
2251
2253
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
@@ -2364,6 +2366,21 @@ const remove = uid => {
|
|
|
2364
2366
|
delete instances[uid];
|
|
2365
2367
|
};
|
|
2366
2368
|
|
|
2369
|
+
const serializeError = error => {
|
|
2370
|
+
if (error instanceof Error) {
|
|
2371
|
+
return {
|
|
2372
|
+
message: error.message,
|
|
2373
|
+
name: error.name,
|
|
2374
|
+
...(error.stack && {
|
|
2375
|
+
stack: error.stack
|
|
2376
|
+
})
|
|
2377
|
+
};
|
|
2378
|
+
}
|
|
2379
|
+
return {
|
|
2380
|
+
message: String(error),
|
|
2381
|
+
name: 'Error'
|
|
2382
|
+
};
|
|
2383
|
+
};
|
|
2367
2384
|
const hasView = (extension, viewId) => {
|
|
2368
2385
|
return Array.isArray(extension.views) && extension.views.some(view => view.id === viewId);
|
|
2369
2386
|
};
|
|
@@ -2381,36 +2398,79 @@ const getRpcForView = async (viewId, assetDir, platform) => {
|
|
|
2381
2398
|
if (existingRpc) {
|
|
2382
2399
|
return existingRpc;
|
|
2383
2400
|
}
|
|
2384
|
-
await activateByEvent(`onView:${viewId}`, assetDir, platform);
|
|
2401
|
+
const activationResult = await activateByEvent(`onView:${viewId}`, assetDir, platform);
|
|
2402
|
+
if (activationResult.error) {
|
|
2403
|
+
throw activationResult.error;
|
|
2404
|
+
}
|
|
2385
2405
|
return getRpc$1(extension, assetDir, platform);
|
|
2386
2406
|
};
|
|
2387
2407
|
const getRpcForInstance = async (viewId, uid, assetDir, platform) => {
|
|
2388
2408
|
const instance = get$1(uid);
|
|
2389
2409
|
if (instance) {
|
|
2410
|
+
if (instance.status === 'error') {
|
|
2411
|
+
return undefined;
|
|
2412
|
+
}
|
|
2390
2413
|
return instance.rpc;
|
|
2391
2414
|
}
|
|
2392
2415
|
return getRpcForView(viewId, assetDir, platform);
|
|
2393
2416
|
};
|
|
2394
2417
|
const createViewInstance = async (viewId, uid, context, assetDir, platform) => {
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2418
|
+
try {
|
|
2419
|
+
const rpc = await getRpcForView(viewId, assetDir, platform);
|
|
2420
|
+
const result = await rpc.invoke('ExtensionApi.createViewInstance', viewId, uid, context);
|
|
2421
|
+
set$1(uid, {
|
|
2422
|
+
rpc,
|
|
2423
|
+
status: 'ready',
|
|
2424
|
+
viewId
|
|
2425
|
+
});
|
|
2426
|
+
return {
|
|
2427
|
+
ok: true,
|
|
2428
|
+
result
|
|
2429
|
+
};
|
|
2430
|
+
} catch (error) {
|
|
2431
|
+
const serializedError = serializeError(error);
|
|
2432
|
+
set$1(uid, {
|
|
2433
|
+
error: serializedError,
|
|
2434
|
+
status: 'error',
|
|
2435
|
+
viewId
|
|
2436
|
+
});
|
|
2437
|
+
return {
|
|
2438
|
+
error: serializedError,
|
|
2439
|
+
ok: false
|
|
2440
|
+
};
|
|
2441
|
+
}
|
|
2402
2442
|
};
|
|
2403
2443
|
const dispatchViewEvent = async (viewId, uid, event, assetDir, platform) => {
|
|
2404
2444
|
const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
|
|
2445
|
+
if (!rpc) {
|
|
2446
|
+
return undefined;
|
|
2447
|
+
}
|
|
2405
2448
|
return rpc.invoke('ExtensionApi.dispatchViewEvent', uid, event);
|
|
2406
2449
|
};
|
|
2450
|
+
const requestViewRerender = async uid => {
|
|
2451
|
+
await invoke$3('Viewlet.executeViewletCommand', uid, 'rerender');
|
|
2452
|
+
};
|
|
2453
|
+
const renderViewInstance = async (viewId, uid, assetDir, platform) => {
|
|
2454
|
+
const instance = get$1(uid);
|
|
2455
|
+
if (!instance || instance.status === 'error') {
|
|
2456
|
+
return undefined;
|
|
2457
|
+
}
|
|
2458
|
+
return instance.rpc.invoke('ExtensionApi.renderViewInstance', uid);
|
|
2459
|
+
};
|
|
2407
2460
|
const disposeViewInstance = async (viewId, uid, assetDir, platform) => {
|
|
2408
2461
|
const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
|
|
2462
|
+
if (!rpc) {
|
|
2463
|
+
remove(uid);
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2409
2466
|
await rpc.invoke('ExtensionApi.disposeViewInstance', uid);
|
|
2410
2467
|
remove(uid);
|
|
2411
2468
|
};
|
|
2412
2469
|
const saveViewInstanceState = async (viewId, uid, assetDir, platform) => {
|
|
2413
2470
|
const rpc = await getRpcForInstance(viewId, uid, assetDir, platform);
|
|
2471
|
+
if (!rpc) {
|
|
2472
|
+
return undefined;
|
|
2473
|
+
}
|
|
2414
2474
|
return rpc.invoke('ExtensionApi.saveViewInstanceState', uid);
|
|
2415
2475
|
};
|
|
2416
2476
|
|
|
@@ -2525,9 +2585,7 @@ const get = colorThemeId => {
|
|
|
2525
2585
|
const set = (colorThemeId, data) => {
|
|
2526
2586
|
// noop
|
|
2527
2587
|
};
|
|
2528
|
-
|
|
2529
|
-
const GetColorThemeCssCachedNoop = {
|
|
2530
|
-
__proto__: null,
|
|
2588
|
+
const cache = {
|
|
2531
2589
|
get,
|
|
2532
2590
|
set
|
|
2533
2591
|
};
|
|
@@ -2539,7 +2597,7 @@ const GetColorThemeCssCachedNoop = {
|
|
|
2539
2597
|
const getCacheFn = config => {
|
|
2540
2598
|
switch (config) {
|
|
2541
2599
|
default:
|
|
2542
|
-
return
|
|
2600
|
+
return cache;
|
|
2543
2601
|
}
|
|
2544
2602
|
};
|
|
2545
2603
|
const getColorThemeCssCached = async (colorThemeId, platform, getData) => {
|
|
@@ -2753,6 +2811,16 @@ const contributesViews = extension => {
|
|
|
2753
2811
|
const getManifestView = (extension, id) => {
|
|
2754
2812
|
return extension.views?.find(view => view.id === id);
|
|
2755
2813
|
};
|
|
2814
|
+
const getCss = (extension, manifestView, assetDir, platform) => {
|
|
2815
|
+
const css = manifestView?.css;
|
|
2816
|
+
if (typeof css !== 'string' || css.length === 0) {
|
|
2817
|
+
return '';
|
|
2818
|
+
}
|
|
2819
|
+
return getAbsolutePath({
|
|
2820
|
+
...extension,
|
|
2821
|
+
browser: css
|
|
2822
|
+
}, assetDir, platform);
|
|
2823
|
+
};
|
|
2756
2824
|
const getIframe = (extension, manifestView, assetDir, platform) => {
|
|
2757
2825
|
const iframe = manifestView?.iframe;
|
|
2758
2826
|
if (!iframe || typeof iframe.path !== 'string' || iframe.path.length === 0) {
|
|
@@ -2771,7 +2839,11 @@ const getIframe = (extension, manifestView, assetDir, platform) => {
|
|
|
2771
2839
|
const toView = (extension, registeredView, assetDir, platform) => {
|
|
2772
2840
|
const id = registeredView.id || '';
|
|
2773
2841
|
const manifestView = getManifestView(extension, id);
|
|
2842
|
+
const css = getCss(extension, manifestView, assetDir, platform);
|
|
2774
2843
|
return {
|
|
2844
|
+
...(css && {
|
|
2845
|
+
css
|
|
2846
|
+
}),
|
|
2775
2847
|
extensionId: getExtensionId(extension),
|
|
2776
2848
|
icon: registeredView.icon || manifestView?.icon || '',
|
|
2777
2849
|
id,
|
|
@@ -2853,6 +2925,7 @@ const initialize = async platform => {
|
|
|
2853
2925
|
|
|
2854
2926
|
const installExtension = async () => {
|
|
2855
2927
|
// TODO
|
|
2928
|
+
await invalidateExtensionsCache();
|
|
2856
2929
|
};
|
|
2857
2930
|
|
|
2858
2931
|
const getRemoteUrl = uri => {
|
|
@@ -2926,6 +2999,7 @@ const sendMessagePortToFileSystemWorker = async port => {
|
|
|
2926
2999
|
|
|
2927
3000
|
const uninstallExtension = async () => {
|
|
2928
3001
|
// TODO
|
|
3002
|
+
await invalidateExtensionsCache();
|
|
2929
3003
|
};
|
|
2930
3004
|
|
|
2931
3005
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
@@ -2977,6 +3051,8 @@ const commandMap = {
|
|
|
2977
3051
|
'Extensions.initialize': initialize,
|
|
2978
3052
|
'Extensions.install': installExtension,
|
|
2979
3053
|
'Extensions.invalidateExtensionsCache': invalidateExtensionsCache,
|
|
3054
|
+
'Extensions.renderViewInstance': renderViewInstance,
|
|
3055
|
+
'Extensions.requestViewRerender': requestViewRerender,
|
|
2980
3056
|
'Extensions.saveViewInstanceState': saveViewInstanceState,
|
|
2981
3057
|
'Extensions.sendMessagePortToFileSystemWorker': sendMessagePortToFileSystemWorker,
|
|
2982
3058
|
'Extensions.setPreference': setPreference,
|