@lvce-editor/extension-management-worker 4.90.2 → 4.90.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.
@@ -1729,10 +1729,9 @@ const createResponseFromData = data => {
1729
1729
  return response;
1730
1730
  };
1731
1731
 
1732
- const cacheName$1 = 'Extensions'; // TODO
1733
-
1734
- const getJson$1 = async cacheKey => {
1735
- const item = await getCacheStorageItem(cacheKey, cacheName$1);
1732
+ const defaultCacheName = 'Extensions';
1733
+ const getJson$1 = async (cacheKey, cacheName = defaultCacheName) => {
1734
+ const item = await getCacheStorageItem(cacheKey, cacheName);
1736
1735
  if (!item) {
1737
1736
  return undefined;
1738
1737
  }
@@ -1740,11 +1739,11 @@ const getJson$1 = async cacheKey => {
1740
1739
  const json = typeof body === 'string' ? body : new TextDecoder().decode(body);
1741
1740
  return JSON.parse(json);
1742
1741
  };
1743
- const setJson = async (cacheKey, data) => {
1742
+ const setJson = async (cacheKey, data, cacheName = defaultCacheName) => {
1744
1743
  try {
1745
1744
  const response = createResponseFromData(data);
1746
1745
  const headers = Object.fromEntries(response.headers.entries());
1747
- const result = await setCacheStorageItem(cacheKey, await response.arrayBuffer(), cacheName$1, headers);
1746
+ const result = await setCacheStorageItem(cacheKey, await response.arrayBuffer(), cacheName, headers);
1748
1747
  if (!result.success) {
1749
1748
  throw new Error(result.errorMessage);
1750
1749
  }
@@ -3072,7 +3071,7 @@ const hideNotificationsFromExtension = async extensionId => {
3072
3071
  await notifyNotificationsChanged();
3073
3072
  };
3074
3073
 
3075
- const cacheName = 'ExtensionSecrets';
3074
+ const cacheName$1 = 'ExtensionSecrets';
3076
3075
  const getRequestUrl = (extensionId, key) => {
3077
3076
  return `https://secret-storage.invalid/${encodeURIComponent(extensionId)}/${encodeURIComponent(key)}`;
3078
3077
  };
@@ -3086,7 +3085,7 @@ const deleteSecret = async (extensionId, key) => {
3086
3085
  await invoke$5('SecretStorage.delete', extensionId, key);
3087
3086
  return;
3088
3087
  }
3089
- await removeCacheStorageItem(getRequestUrl(extensionId, key), cacheName);
3088
+ await removeCacheStorageItem(getRequestUrl(extensionId, key), cacheName$1);
3090
3089
  };
3091
3090
  const getSecret = async (extensionId, key) => {
3092
3091
  string(extensionId);
@@ -3094,7 +3093,7 @@ const getSecret = async (extensionId, key) => {
3094
3093
  if (isElectron()) {
3095
3094
  return invoke$5('SecretStorage.get', extensionId, key);
3096
3095
  }
3097
- const item = await getCacheStorageItem(getRequestUrl(extensionId, key), cacheName);
3096
+ const item = await getCacheStorageItem(getRequestUrl(extensionId, key), cacheName$1);
3098
3097
  if (!item) {
3099
3098
  return undefined;
3100
3099
  }
@@ -3109,7 +3108,7 @@ const storeSecret = async (extensionId, key, value) => {
3109
3108
  await invoke$5('SecretStorage.store', extensionId, key, value);
3110
3109
  return;
3111
3110
  }
3112
- const result = await setCacheStorageItem(getRequestUrl(extensionId, key), value, cacheName);
3111
+ const result = await setCacheStorageItem(getRequestUrl(extensionId, key), value, cacheName$1);
3113
3112
  if (!result.success) {
3114
3113
  throw new Error(result.errorMessage);
3115
3114
  }
@@ -5529,6 +5528,38 @@ const getColorThemeCssCached = async (colorThemeId, platform, getData) => {
5529
5528
  const readJson = url => {
5530
5529
  return invoke$4('FileSystem.readJson', url);
5531
5530
  };
5531
+ const statWithMetadata = url => {
5532
+ return invoke$4('FileSystem.statWithMetadata', url);
5533
+ };
5534
+
5535
+ const getColorThemeJsonCacheKey = source => {
5536
+ return `https://color-theme.cache/${encodeURIComponent(source)}`;
5537
+ };
5538
+
5539
+ const cacheName = 'ColorThemes';
5540
+ const getColorThemeJsonCached = async (source, validator, getJson, forceReload = false) => {
5541
+ const cacheKey = getColorThemeJsonCacheKey(source);
5542
+ if (!forceReload) {
5543
+ try {
5544
+ const cached = await getJson$1(cacheKey, cacheName);
5545
+ if (cached?.validator === validator) {
5546
+ return cached.json;
5547
+ }
5548
+ } catch {
5549
+ // Persistent cache errors must not prevent loading the theme.
5550
+ }
5551
+ }
5552
+ const json = await getJson();
5553
+ try {
5554
+ await setJson(cacheKey, {
5555
+ json,
5556
+ validator
5557
+ }, cacheName);
5558
+ } catch {
5559
+ // Persistent cache errors must not prevent loading the theme.
5560
+ }
5561
+ return json;
5562
+ };
5532
5563
 
5533
5564
  const join = (pathSeparator, ...parts) => {
5534
5565
  return parts.join(pathSeparator);
@@ -5555,30 +5586,57 @@ const getColorThemeUri = (extensions, colorThemeId) => {
5555
5586
  return '';
5556
5587
  };
5557
5588
 
5558
- const getColorThemeJson$2 = async (colorThemeId, assetDir, platform) => {
5589
+ const getColorThemeJson$2 = async (colorThemeId, assetDir, platform, forceReload = false) => {
5559
5590
  const extensions = await getAllExtensions(assetDir, platform);
5560
5591
  const colorThemeUri = getColorThemeUri(extensions, colorThemeId);
5561
5592
  if (!colorThemeUri) {
5562
5593
  return {};
5563
5594
  }
5564
- const json = await readJson(colorThemeUri);
5565
- return json;
5595
+ try {
5596
+ const stat = await statWithMetadata(colorThemeUri);
5597
+ if (typeof stat?.mtimeMs !== 'number' || typeof stat?.size !== 'number') {
5598
+ return await readJson(colorThemeUri);
5599
+ }
5600
+ const validator = JSON.stringify({
5601
+ mtimeMs: stat.mtimeMs,
5602
+ size: stat.size
5603
+ });
5604
+ return getColorThemeJsonCached(colorThemeUri, validator, () => readJson(colorThemeUri), forceReload);
5605
+ } catch {
5606
+ return readJson(colorThemeUri);
5607
+ }
5566
5608
  };
5567
5609
 
5568
5610
  const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
5569
5611
  return `${assetDir}/extensions/builtin.theme-${colorThemeId}/color-theme.json`;
5570
5612
  };
5571
- const getColorThemeJson$1 = (colorThemeId, assetDir) => {
5613
+ const getColorThemeJson$1 = (colorThemeId, assetDir, forceReload = false) => {
5572
5614
  const url = getColorThemeUrlWeb(assetDir, colorThemeId);
5573
- // TODO handle error ?
5574
- return getJson(url);
5615
+ return getJsonCached(url, forceReload);
5616
+ };
5617
+ const getJsonCached = async (url, forceReload) => {
5618
+ try {
5619
+ const response = await fetch(url, {
5620
+ method: 'HEAD'
5621
+ });
5622
+ if (!response.ok) {
5623
+ return getJson(url);
5624
+ }
5625
+ const etag = response.headers.get('etag');
5626
+ if (!etag) {
5627
+ return getJson(url);
5628
+ }
5629
+ return getColorThemeJsonCached(url, etag, () => getJson(url), forceReload);
5630
+ } catch {
5631
+ return getJson(url);
5632
+ }
5575
5633
  };
5576
5634
 
5577
- const getColorThemeJson = (colorThemeId, platform, assetDir) => {
5635
+ const getColorThemeJson = (colorThemeId, platform, assetDir, forceReload = false) => {
5578
5636
  if (platform === Web) {
5579
- return getColorThemeJson$1(colorThemeId, assetDir);
5637
+ return getColorThemeJson$1(colorThemeId, assetDir, forceReload);
5580
5638
  }
5581
- return getColorThemeJson$2(colorThemeId, assetDir, platform);
5639
+ return getColorThemeJson$2(colorThemeId, assetDir, platform, forceReload);
5582
5640
  };
5583
5641
 
5584
5642
  const getColorThemeCssFromJson = async (colorThemeId, colorThemeJson) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/extension-management-worker",
3
- "version": "4.90.2",
3
+ "version": "4.90.3",
4
4
  "description": "Webworker for the Extension Management functionality in Lvce Editor.",
5
5
  "keywords": [
6
6
  "web-worker"