提交 3e61d5b7 编写于 作者: W Wade Anderson

Pull down install count from marketplace API. Order by install count.

上级 cf459844
......@@ -15,6 +15,7 @@ export interface IExtensionManifest {
version: string;
displayName?: string;
description?: string;
installCount: number;
}
export interface IGalleryInformation {
......
......@@ -79,10 +79,11 @@ function extensionEquals(one: IExtension, other: IExtension): boolean {
return one.publisher === other.publisher && one.name === other.name;
}
/**
* Compare by Install count descending.
*/
function extensionEntryCompare(one: IExtensionEntry, other: IExtensionEntry): number {
const oneName = one.extension.displayName || one.extension.name;
const otherName = other.extension.displayName || other.extension.name;
return oneName.localeCompare(otherName);
return other.extension.installCount - one.extension.installCount;
}
class OpenInGalleryAction extends Action {
......
......@@ -33,6 +33,12 @@ export interface IGalleryExtension {
publisher: { displayName: string, publisherId: string, publisherName: string; };
versions: IGalleryExtensionVersion[];
galleryApiUrl: string;
statistics: IGalleryExtensionStatistic[];
}
export interface IGalleryExtensionStatistic {
statisticName: string;
value: number;
}
export class GalleryService implements IGalleryService {
......@@ -53,10 +59,28 @@ export class GalleryService implements IGalleryService {
return `${ this.extensionsGalleryUrl }${ path }`;
}
/**
* Extracts install count statistic.
*/
private extractInstallCount(statistics: IGalleryExtensionStatistic[]): number {
var result = 0;
statistics.forEach(stat => {
if (stat.statisticName === 'install') {
result = stat.value;
}
})
return result;
}
public isEnabled(): boolean {
return !!this.extensionsGalleryUrl;
}
/**
* Queries VS Code Extension marketplace for extensions.
*
* Sorts by install count.
*/
public query(): TPromise<IExtension[]> {
if (!this.extensionsGalleryUrl) {
return TPromise.wrapError(new Error('No extension gallery service configured.'));
......@@ -69,7 +93,7 @@ export class GalleryService implements IGalleryService {
value: 'vscode'
}]
}],
flags: 0x1 | 0x4 | 0x80
flags: 0x1 | 0x4 | 0x80 | 0x100
});
const request = {
......@@ -92,13 +116,14 @@ export class GalleryService implements IGalleryService {
publisher: extension.publisher.publisherName,
version: extension.versions[0].version,
description: extension.shortDescription || '',
installCount: this.extractInstallCount(extension.statistics),
galleryInformation: {
galleryApiUrl: this.extensionsGalleryUrl,
id: extension.extensionId,
downloadUrl: `${ extension.versions[0].assetUri }/Microsoft.VisualStudio.Services.VSIXPackage?install=true`,
publisherId: extension.publisher.publisherId,
publisherDisplayName: extension.publisher.displayName,
date: extension.versions[0].lastUpdated
date: extension.versions[0].lastUpdated,
}
}));
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册