@lvce-editor/extension-management-worker 4.31.1 → 4.31.3

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.
@@ -1868,6 +1868,88 @@ const getExtensionAbsolutePath = (id, isWeb, isBuiltin, path, relativePath, orig
1868
1868
  return new URL('/remote' + path + '/' + relativePath, origin).href;
1869
1869
  };
1870
1870
 
1871
+ const ContentType = 'Content-Type';
1872
+ const ContentLength = 'Content-Length';
1873
+
1874
+ const createResponseFromData = data => {
1875
+ const responseString = JSON.stringify(data);
1876
+ const response = new Response(responseString, {
1877
+ headers: {
1878
+ [ContentLength]: String(responseString.length),
1879
+ [ContentType]: 'application/json'
1880
+ }
1881
+ });
1882
+ return response;
1883
+ };
1884
+
1885
+ const cacheName = 'Extensions'; // TODO
1886
+
1887
+ const getJson$1 = async cacheKey => {
1888
+ const response = await caches.match(cacheKey, {
1889
+ cacheName
1890
+ });
1891
+ if (!response) {
1892
+ return undefined;
1893
+ }
1894
+ const json = await response.json();
1895
+ return json;
1896
+ };
1897
+ const setJson = async (cacheKey, data) => {
1898
+ try {
1899
+ const cache = await caches.open(cacheName);
1900
+ const response = createResponseFromData(data);
1901
+ await cache.put(cacheKey, response);
1902
+ } catch (error) {
1903
+ throw new VError(error, `Failed to add to cache`);
1904
+ }
1905
+ };
1906
+
1907
+ const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
1908
+
1909
+ /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
1910
+
1911
+ const getDisabledExtensionIdsFromData = data => {
1912
+ const disabledExtensions = data?.disabledExtensions;
1913
+ if (!Array.isArray(disabledExtensions)) {
1914
+ return [];
1915
+ }
1916
+ return disabledExtensions.filter(id => typeof id === 'string');
1917
+ };
1918
+ const getWebDisabledExtensionIds = async () => {
1919
+ try {
1920
+ const cached = await getJson$1(disabledExtensionsCacheKey);
1921
+ return getDisabledExtensionIdsFromData(cached);
1922
+ } catch {
1923
+ return [];
1924
+ }
1925
+ };
1926
+ const getRemoteDisabledExtensionIds = async () => {
1927
+ try {
1928
+ const uri = await invoke$2('WebView.compatSharedProcessInvoke', 'PlatformPaths.getDisabledExtensionsJsonUri');
1929
+ const exists$1 = await exists(uri);
1930
+ if (!exists$1) {
1931
+ return [];
1932
+ }
1933
+ const content = await readFile$1(uri);
1934
+ const parsed = JSON.parse(content);
1935
+ return getDisabledExtensionIdsFromData(parsed);
1936
+ } catch {
1937
+ return [];
1938
+ }
1939
+ };
1940
+ const getDisabledExtensionIds = async (extensionsState, platform) => {
1941
+ if (platform === Test) {
1942
+ return extensionsState.disabledIds;
1943
+ }
1944
+ if (platform === Web) {
1945
+ return getWebDisabledExtensionIds();
1946
+ }
1947
+ if (platform === Remote || platform === Electron) {
1948
+ return getRemoteDisabledExtensionIds();
1949
+ }
1950
+ return [];
1951
+ };
1952
+
1871
1953
  const isMissingAssetDir = assetDir => {
1872
1954
  return typeof assetDir !== 'string' || assetDir.length === 0;
1873
1955
  };
@@ -1899,7 +1981,7 @@ const getRuntimeContext = async (assetDir, platform) => {
1899
1981
  const getResponseErrorMessage = response => {
1900
1982
  return response.statusText || String(response.status) || 'Request failed';
1901
1983
  };
1902
- const getJson$1 = async url => {
1984
+ const getJson = async url => {
1903
1985
  try {
1904
1986
  const response = await fetch(url);
1905
1987
  if (!response.ok) {
@@ -1918,7 +2000,7 @@ const getWebExtensionsUrl = assetDir => {
1918
2000
 
1919
2001
  const getWebExtensions = async assetDir => {
1920
2002
  try {
1921
- return await getJson$1(getWebExtensionsUrl(assetDir));
2003
+ return await getJson(getWebExtensionsUrl(assetDir));
1922
2004
  } catch {
1923
2005
  return [];
1924
2006
  }
@@ -2030,7 +2112,7 @@ const enableExtension$1 = async id => {
2030
2112
 
2031
2113
  /* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
2032
2114
 
2033
- const withWorkspaceDisabledState = (extensions, disabledIds) => {
2115
+ const withDisabledState = (extensions, disabledIds) => {
2034
2116
  if (disabledIds.length === 0) {
2035
2117
  return extensions;
2036
2118
  }
@@ -2045,12 +2127,17 @@ const withWorkspaceDisabledState = (extensions, disabledIds) => {
2045
2127
  };
2046
2128
  });
2047
2129
  };
2048
- const getExtensionsWithWorkspaceState = async (extensions, platform) => {
2049
- if (extensions.length === 0 || platform === Test) {
2130
+ const getExtensionsWithState = async (extensions, extensionsState, platform) => {
2131
+ if (extensions.length === 0) {
2050
2132
  return extensions;
2051
2133
  }
2134
+ const disabledIds = await getDisabledExtensionIds(extensionsState, platform);
2135
+ const extensionsWithDisabledState = withDisabledState(extensions, disabledIds);
2136
+ if (platform === Test) {
2137
+ return extensionsWithDisabledState;
2138
+ }
2052
2139
  const workspaceDisabledIds = await readDisabledExtensionIdsSafe();
2053
- return withWorkspaceDisabledState(extensions, workspaceDisabledIds);
2140
+ return withDisabledState(extensionsWithDisabledState, workspaceDisabledIds);
2054
2141
  };
2055
2142
  const getAllExtensionsWithState = async (extensionsState, assetDir, platform) => {
2056
2143
  const {
@@ -2063,10 +2150,10 @@ const getAllExtensionsWithState = async (extensionsState, assetDir, platform) =>
2063
2150
  if (resolvedPlatform === Web) {
2064
2151
  const webExtensions = await getWebExtensions(resolvedAssetDir);
2065
2152
  const compatibleExtensions = [...webExtensions, ...meta].filter(extension => isExtensionCompatible(extension, resolvedPlatform));
2066
- return getExtensionsWithWorkspaceState(compatibleExtensions, resolvedPlatform);
2153
+ return getExtensionsWithState(compatibleExtensions, extensionsState, resolvedPlatform);
2067
2154
  }
2068
2155
  const local = await invoke$1('ExtensionManagement.getAllExtensions');
2069
- return getExtensionsWithWorkspaceState([...local, ...meta], resolvedPlatform);
2156
+ return getExtensionsWithState([...local, ...meta], extensionsState, resolvedPlatform);
2070
2157
  };
2071
2158
 
2072
2159
  const getAllExtensions = async (assetDir, platform) => {
@@ -2135,10 +2222,18 @@ const activateByEvent = async (event, assetDir, platform) => {
2135
2222
  };
2136
2223
 
2137
2224
  const invalidateExtensionsCache = async () => {
2138
- await invoke$2('ExtensionManagement.handleExtensionsCacheInvalidated');
2225
+ try {
2226
+ await invoke$2('ExtensionManagement.handleExtensionsCacheInvalidated');
2227
+ } catch {
2228
+ // Older renderer workers do not expose the cache invalidation notification.
2229
+ }
2139
2230
  };
2140
2231
 
2141
2232
  const handleChange = async _id => {
2233
+ const statusBarVisible = await invoke$2('Layout.getStatusBarVisible');
2234
+ if (!statusBarVisible) {
2235
+ return;
2236
+ }
2142
2237
  await invoke$2('StatusBar.handleItemsChanged');
2143
2238
  };
2144
2239
 
@@ -2157,7 +2252,7 @@ const addExtension = async extension => {
2157
2252
 
2158
2253
  const getWebExtensionManifest = async (path, manifestPath) => {
2159
2254
  try {
2160
- const manifest = await getJson$1(manifestPath);
2255
+ const manifest = await getJson(manifestPath);
2161
2256
  return {
2162
2257
  ...manifest,
2163
2258
  path,
@@ -2235,44 +2330,6 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
2235
2330
  });
2236
2331
  };
2237
2332
 
2238
- const ContentType = 'Content-Type';
2239
- const ContentLength = 'Content-Length';
2240
-
2241
- const createResponseFromData = data => {
2242
- const responseString = JSON.stringify(data);
2243
- const response = new Response(responseString, {
2244
- headers: {
2245
- [ContentLength]: String(responseString.length),
2246
- [ContentType]: 'application/json'
2247
- }
2248
- });
2249
- return response;
2250
- };
2251
-
2252
- const cacheName = 'Extensions'; // TODO
2253
-
2254
- const getJson = async cacheKey => {
2255
- const response = await caches.match(cacheKey, {
2256
- cacheName
2257
- });
2258
- if (!response) {
2259
- return undefined;
2260
- }
2261
- const json = await response.json();
2262
- return json;
2263
- };
2264
- const setJson = async (cacheKey, data) => {
2265
- try {
2266
- const cache = await caches.open(cacheName);
2267
- const response = createResponseFromData(data);
2268
- await cache.put(cacheKey, response);
2269
- } catch (error) {
2270
- throw new VError(error, `Failed to add to cache`);
2271
- }
2272
- };
2273
-
2274
- const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
2275
-
2276
2333
  const disableExtension2$1 = async (id, platform) => {
2277
2334
  const isTest = platform === Test;
2278
2335
  const isWeb = platform === Web;
@@ -2284,7 +2341,7 @@ const disableExtension2$1 = async (id, platform) => {
2284
2341
  };
2285
2342
  set$4(newState);
2286
2343
  } else if (isWeb) {
2287
- const cached = await getJson(disabledExtensionsCacheKey);
2344
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2288
2345
  const oldDisabled = cached?.disabledExtensions || [];
2289
2346
  const newDisabled = [...oldDisabled, id];
2290
2347
  const newData = {
@@ -2306,7 +2363,7 @@ const enableExtension2$1 = async (id, platform) => {
2306
2363
  };
2307
2364
  set$4(newState);
2308
2365
  } else if (isWeb) {
2309
- const cached = await getJson(disabledExtensionsCacheKey);
2366
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2310
2367
  const oldDisabled = cached?.disabledExtensions || [];
2311
2368
  const newDisabled = oldDisabled.filter(item => item !== id);
2312
2369
  const newData = {
@@ -3133,7 +3190,7 @@ const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
3133
3190
  const getColorThemeJson$1 = (colorThemeId, assetDir) => {
3134
3191
  const url = getColorThemeUrlWeb(assetDir, colorThemeId);
3135
3192
  // TODO handle error ?
3136
- return getJson$1(url);
3193
+ return getJson(url);
3137
3194
  };
3138
3195
 
3139
3196
  const getColorThemeJson = (colorThemeId, platform, assetDir) => {
@@ -3158,6 +3215,9 @@ const getColorThemeCss = (colorThemeId, platform) => {
3158
3215
  };
3159
3216
 
3160
3217
  const getExtensionColorThemeNames = extension => {
3218
+ if (extension.disabled) {
3219
+ return [];
3220
+ }
3161
3221
  return extension.colorThemes || [];
3162
3222
  };
3163
3223
  const getColorThemeId = colorTheme => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.31.1",
3
+ "version": "4.31.3",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"