Skip to content

Commit af22336

Browse files
committed
chore: update stars and download count dynamically in extension manager
1 parent e092a72 commit af22336

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"extension_listing_url": "",
1818
"extension_registry": "https://extensions.phcode.dev/registry.json",
1919
"extension_registry_version": "https://extensions.phcode.dev/registry_version.json",
20+
"extension_registry_popularity": "https://extensions.phcode.dev/popularity.json",
2021
"extension_url": "https://extensions.phcode.dev/extensions/",
2122
"extension_store_url": "https://store.core.ai/src/",
2223
"linting.enabled_by_default": true,

src/extensibility/ExtensionManager.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,29 @@ define(function (require, exports, module) {
245245
});
246246
}
247247

248+
function _patchDownloadCounts() {
249+
const registryJson = localStorage.getItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY);
250+
if(!registryJson){
251+
return;
252+
}
253+
$.ajax({
254+
url: brackets.config.extension_registry_popularity,
255+
dataType: "json",
256+
cache: false
257+
}).done(function (popularity) {
258+
let registry = JSON.parse(registryJson);
259+
for(let key of Object.keys(popularity)){
260+
if(registry[key]) {
261+
registry[key].totalDownloads = popularity[key].totalDownloads || registry[key].totalDownloads
262+
|| null; // null to not show the section if the counts are 0 or not present
263+
registry[key].gihubStars = popularity[key].gihubStars || registry[key].gihubStars
264+
|| null;
265+
}
266+
}
267+
localStorage.setItem(EXTENSION_REGISTRY_LOCAL_STORAGE_KEY, JSON.stringify(registry));
268+
});
269+
}
270+
248271
/**
249272
* Downloads the registry of Brackets extensions and stores the information in our
250273
* extension info.
@@ -308,6 +331,7 @@ define(function (require, exports, module) {
308331
.catch(()=>{
309332
pendingDownloadRegistry = null;
310333
});
334+
_patchDownloadCounts();
311335

312336
return pendingDownloadRegistry.promise();
313337
}

src/extensibility/ExtensionManagerView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ define(function (require, exports, module) {
308308
context.requiresNewer = latestVerCompatInfo.requiresNewer;
309309
context.isCompatibleLatest = latestVerCompatInfo.isLatestVersion;
310310
entry.registryInfo.isVerified = isVerified ? 1 : 0;
311-
entry.registryInfo.githubStarCount = context.githubStarCount || 0;
311+
entry.registryInfo.githubStarCount = context.githubStarCount;
312312
if (!context.isCompatibleLatest) {
313313
var installWarningBase = context.requiresNewer ? Strings.EXTENSION_LATEST_INCOMPATIBLE_NEWER : Strings.EXTENSION_LATEST_INCOMPATIBLE_OLDER;
314314
context.installWarning = StringUtils.format(installWarningBase, entry.registryInfo.versions[entry.registryInfo.versions.length - 1].version, latestVerCompatInfo.compatibleVersion);

0 commit comments

Comments
 (0)