@lvce-editor/extension-management-worker 4.31.2 → 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,7 +2222,11 @@ 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 => {
@@ -2161,7 +2252,7 @@ const addExtension = async extension => {
2161
2252
 
2162
2253
  const getWebExtensionManifest = async (path, manifestPath) => {
2163
2254
  try {
2164
- const manifest = await getJson$1(manifestPath);
2255
+ const manifest = await getJson(manifestPath);
2165
2256
  return {
2166
2257
  ...manifest,
2167
2258
  path,
@@ -2239,44 +2330,6 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
2239
2330
  });
2240
2331
  };
2241
2332
 
2242
- const ContentType = 'Content-Type';
2243
- const ContentLength = 'Content-Length';
2244
-
2245
- const createResponseFromData = data => {
2246
- const responseString = JSON.stringify(data);
2247
- const response = new Response(responseString, {
2248
- headers: {
2249
- [ContentLength]: String(responseString.length),
2250
- [ContentType]: 'application/json'
2251
- }
2252
- });
2253
- return response;
2254
- };
2255
-
2256
- const cacheName = 'Extensions'; // TODO
2257
-
2258
- const getJson = async cacheKey => {
2259
- const response = await caches.match(cacheKey, {
2260
- cacheName
2261
- });
2262
- if (!response) {
2263
- return undefined;
2264
- }
2265
- const json = await response.json();
2266
- return json;
2267
- };
2268
- const setJson = async (cacheKey, data) => {
2269
- try {
2270
- const cache = await caches.open(cacheName);
2271
- const response = createResponseFromData(data);
2272
- await cache.put(cacheKey, response);
2273
- } catch (error) {
2274
- throw new VError(error, `Failed to add to cache`);
2275
- }
2276
- };
2277
-
2278
- const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
2279
-
2280
2333
  const disableExtension2$1 = async (id, platform) => {
2281
2334
  const isTest = platform === Test;
2282
2335
  const isWeb = platform === Web;
@@ -2288,7 +2341,7 @@ const disableExtension2$1 = async (id, platform) => {
2288
2341
  };
2289
2342
  set$4(newState);
2290
2343
  } else if (isWeb) {
2291
- const cached = await getJson(disabledExtensionsCacheKey);
2344
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2292
2345
  const oldDisabled = cached?.disabledExtensions || [];
2293
2346
  const newDisabled = [...oldDisabled, id];
2294
2347
  const newData = {
@@ -2310,7 +2363,7 @@ const enableExtension2$1 = async (id, platform) => {
2310
2363
  };
2311
2364
  set$4(newState);
2312
2365
  } else if (isWeb) {
2313
- const cached = await getJson(disabledExtensionsCacheKey);
2366
+ const cached = await getJson$1(disabledExtensionsCacheKey);
2314
2367
  const oldDisabled = cached?.disabledExtensions || [];
2315
2368
  const newDisabled = oldDisabled.filter(item => item !== id);
2316
2369
  const newData = {
@@ -3137,7 +3190,7 @@ const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
3137
3190
  const getColorThemeJson$1 = (colorThemeId, assetDir) => {
3138
3191
  const url = getColorThemeUrlWeb(assetDir, colorThemeId);
3139
3192
  // TODO handle error ?
3140
- return getJson$1(url);
3193
+ return getJson(url);
3141
3194
  };
3142
3195
 
3143
3196
  const getColorThemeJson = (colorThemeId, platform, assetDir) => {
@@ -3162,6 +3215,9 @@ const getColorThemeCss = (colorThemeId, platform) => {
3162
3215
  };
3163
3216
 
3164
3217
  const getExtensionColorThemeNames = extension => {
3218
+ if (extension.disabled) {
3219
+ return [];
3220
+ }
3165
3221
  return extension.colorThemes || [];
3166
3222
  };
3167
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.2",
3
+ "version": "4.31.3",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"