Skip to content

Commit

Permalink
Implement #11573: Use engine property for outdated check
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Sep 26, 2016
1 parent edb7293 commit 1368c67
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
extension.assets.download = `${getAssetSource(rawVersion.files, AssetType.VSIX)}?install=true`;
extension.compatibilityChecked = true;
extension.isCompatible = true;
extension.version = rawVersion.version;
return extension;
});
});
Expand Down Expand Up @@ -498,21 +499,21 @@ export class ExtensionGalleryService implements IExtensionGalleryService {
}

private getLastValidExtensionVersion(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): TPromise<IRawGalleryExtensionVersion> {
const version = this.getLastValidExtensionVersionFromProperties(versions);
const version = this.getLastValidExtensionVersionFromProperties(extension, versions);
if (version) {
return TPromise.wrap(version);
return version;
}
return this.getLastValidExtensionVersionReccursively(extension, versions);
}

private getLastValidExtensionVersionFromProperties(versions: IRawGalleryExtensionVersion[]): IRawGalleryExtensionVersion {
private getLastValidExtensionVersionFromProperties(extension: IRawGalleryExtension, versions: IRawGalleryExtensionVersion[]): TPromise<IRawGalleryExtensionVersion> {
for (const version of versions) {
const engine = getEngine(version);
if (!engine) {
return null;
}
if (validateVersions(pkg.version, engine, [])) {
return version;
return TPromise.wrap(version);
}
}
return null;
Expand Down
13 changes: 12 additions & 1 deletion src/vs/workbench/parts/extensions/electron-browser/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface IExtension {
installCount: number;
rating: number;
ratingCount: number;
outdated: boolean;
isOutdated(): TPromise<boolean>;
telemetryData: any;
getManifest(): TPromise<IExtensionManifest>;
getReadme(): TPromise<string>;
Expand Down Expand Up @@ -68,4 +68,15 @@ export const ConfigurationKey = 'extensions';
export interface IExtensionsConfiguration {
autoUpdate: boolean;
recommendations: string[];
}

export function filterOutdatedExtensions(extensions: IExtension[]): TPromise<IExtension[]> {
const promises: TPromise<IExtension>[] = [];
for (const extension of extensions) {
if (extension.type === LocalExtensionType.User) {
promises.push(extension.isOutdated()
.then(outdated => outdated ? extension : null));
}
}
return TPromise.join(promises).then(outDated => outDated.filter(e => !!e));
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import paths = require('vs/base/common/paths');
import Event from 'vs/base/common/event';
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { ReloadWindowAction } from 'vs/workbench/electron-browser/actions';
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewlet, ConfigurationKey } from './extensions';
import { IExtension, ExtensionState, IExtensionsWorkbenchService, VIEWLET_ID, IExtensionsViewlet, ConfigurationKey, filterOutdatedExtensions } from './extensions';
import { LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IMessageService, LaterAction } from 'vs/platform/message/common/message';
Expand Down Expand Up @@ -234,8 +234,12 @@ export class UpdateAction extends Action {
const isInstalled = this.extension.state === ExtensionState.Installed
|| this.extension.state === ExtensionState.NeedsRestart;

this.enabled = canInstall && isInstalled && this.extension.outdated;
this.class = this.enabled ? UpdateAction.EnabledClass : UpdateAction.DisabledClass;
if (canInstall && isInstalled) {
this.extension.isOutdated().then(outDated => {
this.enabled = outDated;
this.class = this.enabled ? UpdateAction.EnabledClass : UpdateAction.DisabledClass;
});
}
}

run(): TPromise<any> {
Expand Down Expand Up @@ -312,22 +316,21 @@ export class UpdateAllAction extends Action {
this.update();
}

private get outdated(): IExtension[] {
return this.extensionsWorkbenchService.local
.filter(e =>
this.extensionsWorkbenchService.canInstall(e)
&& e.type === LocalExtensionType.User
&& (e.state === ExtensionState.Installed || e.state === ExtensionState.NeedsRestart)
&& e.outdated
);
private getOutdatedExtensions(): TPromise<IExtension[]> {
let extensions = this.extensionsWorkbenchService.local
.filter(e => this.extensionsWorkbenchService.canInstall(e)
&& e.type === LocalExtensionType.User
&& (e.state === ExtensionState.Installed || e.state === ExtensionState.NeedsRestart));

return filterOutdatedExtensions(extensions);
}

private update(): void {
this.enabled = this.outdated.length > 0;
this.getOutdatedExtensions().done(outDated => this.enabled = outDated.length > 0);
}

run(): TPromise<any> {
return TPromise.join(this.outdated.map(e => this.extensionsWorkbenchService.install(e)));
return this.getOutdatedExtensions().then(outdated => TPromise.join(outdated.map(e => this.extensionsWorkbenchService.install(e))));
}

dispose(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { PagedList } from 'vs/base/browser/ui/list/listPaging';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { Delegate, Renderer } from './extensionsList';
import { IExtensionsWorkbenchService, IExtension, IExtensionsViewlet, VIEWLET_ID, ExtensionState } from './extensions';
import { IExtensionsWorkbenchService, IExtension, IExtensionsViewlet, VIEWLET_ID, ExtensionState, filterOutdatedExtensions } from './extensions';
import { ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowOutdatedExtensionsAction, ClearExtensionsInputAction, ChangeSortAction, UpdateAllAction, InstallVSIXAction } from './extensionsActions';
import { IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService, SortBy, SortOrder, IQueryOptions, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionsInput } from './extensionsInput';
Expand Down Expand Up @@ -203,15 +203,17 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
}

private query(value: string): TPromise<PagedModel<IExtension>> {
if (!value || /@outdated/i.test(value)) {
let local = this.extensionsWorkbenchService.queryLocal()
.then(result => result.filter(e => e.type === LocalExtensionType.User));

if (/@outdated/i.test(value)) {
local = local.then(result => result.filter(e => e.outdated));
}
if (!value) {
// Show installed extensions
return this.extensionsWorkbenchService.queryLocal()
.then(result => result.filter(e => e.type === LocalExtensionType.User))
.then(result => new PagedModel(result));
}

return local.then(result => new PagedModel(result));
if (/@outdated/i.test(value)) {
return this.extensionsWorkbenchService.queryLocal()
.then(extensions => filterOutdatedExtensions(extensions))
.then(result => new PagedModel(result));
}

const query = Query.parse(value);
Expand Down Expand Up @@ -377,14 +379,14 @@ export class StatusUpdater implements IWorkbenchContribution {
return;
}

const outdated = this.extensionsWorkbenchService.local.reduce((r, e) => r + (e.outdated ? 1 : 0), 0);

if (outdated > 0) {
const badge = new NumberBadge(outdated, n => localize('outdatedExtensions', '{0} Outdated Extensions', n));
this.activityService.showActivity(VIEWLET_ID, badge, 'extensions-badge count-badge');
} else {
this.activityService.showActivity(VIEWLET_ID, null, 'extensions-badge');
}
filterOutdatedExtensions(this.extensionsWorkbenchService.local).then(outdated => {
if (outdated.length > 0) {
const badge = new NumberBadge(outdated.length, n => localize('outdatedExtensions', '{0} Outdated Extensions', n));
this.activityService.showActivity(VIEWLET_ID, badge, 'extensions-badge count-badge');
} else {
this.activityService.showActivity(VIEWLET_ID, null, 'extensions-badge');
}
});
}

dispose(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Event, { Emitter, chain } from 'vs/base/common/event';
import { index } from 'vs/base/common/arrays';
import { assign } from 'vs/base/common/objects';
import { isUUID } from 'vs/base/common/uuid';
import { memoize } from 'vs/base/common/decorators';
import { ThrottledDelayer } from 'vs/base/common/async';
import { isPromiseCanceledError } from 'vs/base/common/errors';
import { TPromise } from 'vs/base/common/winjs.base';
Expand Down Expand Up @@ -156,8 +157,26 @@ class Extension implements IExtension {
return this.gallery ? this.gallery.ratingCount : null;
}

get outdated(): boolean {
return this.type === LocalExtensionType.User && semver.gt(this.latestVersion, this.version);
isOutdated(): TPromise<boolean> {
if (this.type === LocalExtensionType.User) {
if (this.gallery && this.gallery.properties.engine) {
return this._loadCompatibleGalleryVersion().then(() => this.checkVersion(), () => this.checkVersion());
}
return TPromise.wrap(this.checkVersion());
}
return TPromise.wrap(false);
}

@memoize
private _loadCompatibleGalleryVersion(): TPromise<void> {
return this.galleryService.loadCompatibleVersion(this.gallery).then((compatible) => {
this.gallery = compatible;
return null;
}, error => this.checkVersion());
}

private checkVersion(): boolean {
return semver.gt(this.latestVersion, this.version);
}

get telemetryData(): any {
Expand Down

0 comments on commit 1368c67

Please sign in to comment.