@lvce-editor/extension-management-worker 2.2.0 → 2.3.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.
|
@@ -1486,7 +1486,7 @@ const clear = () => {
|
|
|
1486
1486
|
delete cache[id];
|
|
1487
1487
|
};
|
|
1488
1488
|
|
|
1489
|
-
const getJson = async url => {
|
|
1489
|
+
const getJson$1 = async url => {
|
|
1490
1490
|
try {
|
|
1491
1491
|
const response = await fetch(url);
|
|
1492
1492
|
if (!response.ok) {
|
|
@@ -1501,7 +1501,7 @@ const getJson = async url => {
|
|
|
1501
1501
|
|
|
1502
1502
|
const getWebExtensionManifest = async (path, manifestPath) => {
|
|
1503
1503
|
try {
|
|
1504
|
-
const manifest = await getJson(manifestPath);
|
|
1504
|
+
const manifest = await getJson$1(manifestPath);
|
|
1505
1505
|
return {
|
|
1506
1506
|
...manifest,
|
|
1507
1507
|
path,
|
|
@@ -1585,10 +1585,44 @@ const createWebViewWorkerRpc = async (rpcInfo, port) => {
|
|
|
1585
1585
|
});
|
|
1586
1586
|
};
|
|
1587
1587
|
|
|
1588
|
-
const
|
|
1589
|
-
|
|
1588
|
+
const ContentType = 'Content-Type';
|
|
1589
|
+
const ContentLength = 'Content-Length';
|
|
1590
|
+
|
|
1591
|
+
const createResponseFromData = data => {
|
|
1592
|
+
const responseString = JSON.stringify(data);
|
|
1593
|
+
const response = new Response(responseString, {
|
|
1594
|
+
headers: {
|
|
1595
|
+
[ContentLength]: `${responseString.length}`,
|
|
1596
|
+
[ContentType]: 'application/json'
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
return response;
|
|
1590
1600
|
};
|
|
1591
1601
|
|
|
1602
|
+
const cacheName = 'Extensions'; // TODO
|
|
1603
|
+
|
|
1604
|
+
const getJson = async cacheKey => {
|
|
1605
|
+
const response = await caches.match(cacheKey, {
|
|
1606
|
+
cacheName
|
|
1607
|
+
});
|
|
1608
|
+
if (!response) {
|
|
1609
|
+
return undefined;
|
|
1610
|
+
}
|
|
1611
|
+
const json = await response.json();
|
|
1612
|
+
return json;
|
|
1613
|
+
};
|
|
1614
|
+
const setJson = async (cacheKey, data) => {
|
|
1615
|
+
try {
|
|
1616
|
+
const cache = await caches.open(cacheName);
|
|
1617
|
+
const response = createResponseFromData(data);
|
|
1618
|
+
await cache.put(cacheKey, response);
|
|
1619
|
+
} catch (error) {
|
|
1620
|
+
throw new VError(error, `Failed to add to cache`);
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
const disabledExtensionsCacheKey = '/cache/disabledExtensions.json';
|
|
1625
|
+
|
|
1592
1626
|
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types */
|
|
1593
1627
|
|
|
1594
1628
|
let state = {
|
|
@@ -1611,19 +1645,58 @@ const get$1 = () => {
|
|
|
1611
1645
|
return state;
|
|
1612
1646
|
};
|
|
1613
1647
|
|
|
1614
|
-
const disableExtension2 = async (id, platform) => {
|
|
1648
|
+
const disableExtension2$1 = async (id, platform) => {
|
|
1615
1649
|
const isTest = platform === Test;
|
|
1650
|
+
const isWeb = platform === Web;
|
|
1651
|
+
const oldState = get$1(); // TODO maybe pass in an application id? Would allow multiple editors with different extensions.
|
|
1652
|
+
if (isTest) {
|
|
1653
|
+
const newState = {
|
|
1654
|
+
...oldState,
|
|
1655
|
+
disabledIds: [...oldState.disabledIds, id]
|
|
1656
|
+
};
|
|
1657
|
+
set$1(newState);
|
|
1658
|
+
} else if (isWeb) {
|
|
1659
|
+
const cached = await getJson(disabledExtensionsCacheKey);
|
|
1660
|
+
const oldDisabled = cached?.disabledExtensions || [];
|
|
1661
|
+
const newDisabled = [...oldDisabled, id];
|
|
1662
|
+
const newData = {
|
|
1663
|
+
disabledExtensions: newDisabled
|
|
1664
|
+
};
|
|
1665
|
+
await setJson(disabledExtensionsCacheKey, newData);
|
|
1666
|
+
} else {
|
|
1667
|
+
await invoke$1('ExtensionManagement.disable', id);
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
const enableExtension2$1 = async (id, platform) => {
|
|
1671
|
+
const isTest = platform === Test;
|
|
1672
|
+
const isWeb = platform === Web;
|
|
1616
1673
|
const oldState = get$1();
|
|
1674
|
+
if (isTest) {
|
|
1675
|
+
const newState = {
|
|
1676
|
+
...oldState,
|
|
1677
|
+
disabledIds: oldState.disabledIds.filter(existing => existing !== id)
|
|
1678
|
+
};
|
|
1679
|
+
set$1(newState);
|
|
1680
|
+
} else if (isWeb) {
|
|
1681
|
+
const cached = await getJson(disabledExtensionsCacheKey);
|
|
1682
|
+
const oldDisabled = cached?.disabledExtensions || [];
|
|
1683
|
+
const newDisabled = oldDisabled.filter(item => item !== id);
|
|
1684
|
+
const newData = {
|
|
1685
|
+
disabledExtensions: newDisabled
|
|
1686
|
+
};
|
|
1687
|
+
await setJson(disabledExtensionsCacheKey, newData);
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
|
|
1691
|
+
const invalidateExtensionsCache = async () => {
|
|
1692
|
+
await invoke$2('ExtensionManagement.invalidateExtensionsCache');
|
|
1693
|
+
};
|
|
1694
|
+
|
|
1695
|
+
const disableExtension2 = async (id, platform) => {
|
|
1696
|
+
string(id);
|
|
1697
|
+
number(platform);
|
|
1617
1698
|
try {
|
|
1618
|
-
|
|
1619
|
-
const newState = {
|
|
1620
|
-
...oldState,
|
|
1621
|
-
disabledIds: [...oldState.disabledIds, id]
|
|
1622
|
-
};
|
|
1623
|
-
set$1(newState);
|
|
1624
|
-
} else {
|
|
1625
|
-
await invoke$1('ExtensionManagement.disable', id);
|
|
1626
|
-
}
|
|
1699
|
+
await disableExtension2$1(id, platform);
|
|
1627
1700
|
await invalidateExtensionsCache();
|
|
1628
1701
|
return undefined;
|
|
1629
1702
|
} catch (error) {
|
|
@@ -1637,10 +1710,10 @@ const disableExtension = async (id, isTest) => {
|
|
|
1637
1710
|
};
|
|
1638
1711
|
|
|
1639
1712
|
const enableExtension2 = async (id, platform) => {
|
|
1640
|
-
|
|
1641
|
-
|
|
1713
|
+
string(id);
|
|
1714
|
+
number(platform);
|
|
1642
1715
|
if (platform === Remote || platform === Electron) {
|
|
1643
|
-
const disabledExtensionsJsonPath = await invoke$2('PlatformPaths.
|
|
1716
|
+
const disabledExtensionsJsonPath = await invoke$2('WebView.compatSharedProcessInvoke', 'PlatformPaths.getDisabledExtensionsJsonUri');
|
|
1644
1717
|
const exists$1 = await exists(disabledExtensionsJsonPath);
|
|
1645
1718
|
if (!exists$1) {
|
|
1646
1719
|
return undefined;
|
|
@@ -1655,14 +1728,7 @@ const enableExtension2 = async (id, platform) => {
|
|
|
1655
1728
|
const newContent = JSON.stringify(newData, null, 2) + '\n';
|
|
1656
1729
|
await writeFile(disabledExtensionsJsonPath, newContent);
|
|
1657
1730
|
}
|
|
1658
|
-
|
|
1659
|
-
const newState = {
|
|
1660
|
-
...oldState,
|
|
1661
|
-
disabledIds: oldState.disabledIds.filter(existing => existing !== id)
|
|
1662
|
-
};
|
|
1663
|
-
set$1(newState);
|
|
1664
|
-
}
|
|
1665
|
-
return undefined;
|
|
1731
|
+
await enableExtension2$1(id, platform);
|
|
1666
1732
|
};
|
|
1667
1733
|
|
|
1668
1734
|
const enableExtension = async (id, isTest) => {
|
|
@@ -1844,13 +1910,19 @@ const getWebExtensionsUrl = assetDir => {
|
|
|
1844
1910
|
|
|
1845
1911
|
const getWebExtensions = async assetDir => {
|
|
1846
1912
|
try {
|
|
1847
|
-
return await getJson(getWebExtensionsUrl(assetDir));
|
|
1913
|
+
return await getJson$1(getWebExtensionsUrl(assetDir));
|
|
1848
1914
|
} catch {
|
|
1849
1915
|
return [];
|
|
1850
1916
|
}
|
|
1851
1917
|
};
|
|
1852
1918
|
|
|
1853
1919
|
const getAllExtensions = async (assetDir, platform) => {
|
|
1920
|
+
if (!assetDir) {
|
|
1921
|
+
assetDir = await invoke$2('Layout.getAssetDir');
|
|
1922
|
+
}
|
|
1923
|
+
if (!platform) {
|
|
1924
|
+
platform = await invoke$2('Layout.getPlatform');
|
|
1925
|
+
}
|
|
1854
1926
|
string(assetDir);
|
|
1855
1927
|
number(platform);
|
|
1856
1928
|
const meta = getDynamicWebExtensions();
|
|
@@ -1878,7 +1950,7 @@ const getColorThemeUrlWeb = (assetDir, colorThemeId) => {
|
|
|
1878
1950
|
const getColorThemeJson$1 = (colorThemeId, assetDir) => {
|
|
1879
1951
|
const url = getColorThemeUrlWeb(assetDir, colorThemeId);
|
|
1880
1952
|
// TODO handle error ?
|
|
1881
|
-
return getJson(url);
|
|
1953
|
+
return getJson$1(url);
|
|
1882
1954
|
};
|
|
1883
1955
|
|
|
1884
1956
|
const getColorThemeJson = (colorThemeId, platform, assetDir) => {
|
|
@@ -1917,6 +1989,8 @@ const getColorThemeNamesFromExtensions = async extensions => {
|
|
|
1917
1989
|
};
|
|
1918
1990
|
|
|
1919
1991
|
const getColorThemeNames = async (assetDir, platform) => {
|
|
1992
|
+
string(assetDir);
|
|
1993
|
+
number(platform);
|
|
1920
1994
|
const extensions = await getAllExtensions(assetDir, platform);
|
|
1921
1995
|
const colorThemeNames = getColorThemeNamesFromExtensions(extensions);
|
|
1922
1996
|
return colorThemeNames;
|