extensionsViewlet.ts 18.9 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

J
Joao Moreno 已提交
8
import 'vs/css!./media/extensionsViewlet';
J
Joao Moreno 已提交
9 10
import { localize } from 'vs/nls';
import { ThrottledDelayer, always } from 'vs/base/common/async';
J
Joao Moreno 已提交
11
import { TPromise } from 'vs/base/common/winjs.base';
12
import { isPromiseCanceledError, onUnexpectedError, create as createError } from 'vs/base/common/errors';
J
Joao Moreno 已提交
13
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
J
Joao Moreno 已提交
14 15
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { Builder, Dimension } from 'vs/base/browser/builder';
16
import { assign } from 'vs/base/common/objects';
J
Joao Moreno 已提交
17
import EventOf, { mapEvent, chain } from 'vs/base/common/event';
18
import { IAction } from 'vs/base/common/actions';
J
Joao Moreno 已提交
19
import { domEvent } from 'vs/base/browser/event';
J
Joao Moreno 已提交
20
import { Separator } from 'vs/base/browser/ui/actionbar/actionbar';
J
Joao Moreno 已提交
21 22
import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent';
import { KeyCode } from 'vs/base/common/keyCodes';
J
Joao Moreno 已提交
23
import { Viewlet } from 'vs/workbench/browser/viewlet';
24
import { IViewlet } from 'vs/workbench/common/viewlet';
B
Benjamin Pasero 已提交
25
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
J
Joao Moreno 已提交
26
import { append, $, addStandardDisposableListener, EventType, addClass, removeClass, toggleClass } from 'vs/base/browser/dom';
J
Joao Moreno 已提交
27
import { PagedModel, IPagedModel } from 'vs/base/common/paging';
J
Joao Moreno 已提交
28
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
J
Joao Moreno 已提交
29 30
import { PagedList } from 'vs/base/browser/ui/list/listPaging';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
31
import { Delegate, Renderer } from 'vs/workbench/parts/extensions/browser/extensionsList';
32
import { IExtensionsWorkbenchService, IExtension, IExtensionsViewlet, VIEWLET_ID, ExtensionState } from '../common/extensions';
33
import {
34
	ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowDisabledExtensionsAction,
35 36 37
	ShowOutdatedExtensionsAction, ClearExtensionsInputAction, ChangeSortAction, UpdateAllAction
} from 'vs/workbench/parts/extensions/browser/extensionsActions';
import { InstallVSIXAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
J
Joao Moreno 已提交
38
import { IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService, SortBy, SortOrder, IQueryOptions, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
39
import { ExtensionsInput } from 'vs/workbench/parts/extensions/common/extensionsInput';
J
Joao Moreno 已提交
40
import { Query } from '../common/extensionQuery';
41
import { OpenGlobalSettingsAction } from 'vs/workbench/parts/settings/browser/openSettingsActions';
J
Joao Moreno 已提交
42
import { IProgressService } from 'vs/platform/progress/common/progress';
J
Joao Moreno 已提交
43
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
44
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
J
Joao Moreno 已提交
45 46
import { IMessageService, CloseAction } from 'vs/platform/message/common/message';
import Severity from 'vs/base/common/severity';
J
Joao Moreno 已提交
47
import { IActivityService, ProgressBadge, NumberBadge } from 'vs/workbench/services/activity/common/activityService';
S
Sandeep Somavarapu 已提交
48
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
J
Joao Moreno 已提交
49

50 51 52 53
interface SearchInputEvent extends Event {
	target: HTMLInputElement;
	immediate?: boolean;
}
J
Joao Moreno 已提交
54

55
export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
J
Joao Moreno 已提交
56

57
	private onSearchChange: EventOf<string>;
J
Joao Moreno 已提交
58
	private searchDelayer: ThrottledDelayer<any>;
J
Joao Moreno 已提交
59
	private root: HTMLElement;
J
Joao Moreno 已提交
60 61
	private searchBox: HTMLInputElement;
	private extensionsBox: HTMLElement;
J
Joao Moreno 已提交
62
	private messageBox: HTMLElement;
J
Joao Moreno 已提交
63
	private list: PagedList<IExtension>;
J
Joao Moreno 已提交
64 65
	private primaryActions: IAction[];
	private secondaryActions: IAction[];
J
Joao Moreno 已提交
66
	private disposables: IDisposable[] = [];
J
Joao Moreno 已提交
67

J
Joao Moreno 已提交
68 69
	constructor(
		@ITelemetryService telemetryService: ITelemetryService,
70
		@IExtensionGalleryService private galleryService: IExtensionGalleryService,
S
Sandeep Somavarapu 已提交
71
		@IExtensionManagementService private extensionManagementService: IExtensionManagementService,
J
Joao Moreno 已提交
72
		@IProgressService private progressService: IProgressService,
J
Joao Moreno 已提交
73
		@IInstantiationService private instantiationService: IInstantiationService,
74
		@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
75
		@IEditorGroupService private editorInputService: IEditorGroupService,
J
Joao Moreno 已提交
76
		@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService,
J
Joao Moreno 已提交
77
		@IExtensionTipsService private tipsService: IExtensionTipsService,
78
		@IMessageService private messageService: IMessageService,
S
Sandeep Somavarapu 已提交
79
		@IViewletService private viewletService: IViewletService,
S
Sandeep Somavarapu 已提交
80
		@IExtensionService private extensionService: IExtensionService
J
Joao Moreno 已提交
81
	) {
J
Joao Moreno 已提交
82
		super(VIEWLET_ID, telemetryService);
J
Joao Moreno 已提交
83
		this.searchDelayer = new ThrottledDelayer(500);
J
Joao Moreno 已提交
84

85
		this.disposables.push(viewletService.onDidViewletOpen(this.onViewletOpen, this, this.disposables));
J
Joao Moreno 已提交
86 87 88 89
	}

	create(parent: Builder): TPromise<void> {
		super.create(parent);
J
Joao Moreno 已提交
90 91 92
		parent.addClass('extensions-viewlet');
		this.root = parent.getHTMLElement();

J
Joao Moreno 已提交
93 94 95 96
		const header = append(this.root, $('.header'));

		this.searchBox = append(header, $<HTMLInputElement>('input.search-box'));
		this.searchBox.placeholder = localize('searchExtensions', "Search Extensions in Marketplace");
I
isidor 已提交
97 98
		this.disposables.push(addStandardDisposableListener(this.searchBox, EventType.FOCUS, () => addClass(this.searchBox, 'synthetic-focus')));
		this.disposables.push(addStandardDisposableListener(this.searchBox, EventType.BLUR, () => removeClass(this.searchBox, 'synthetic-focus')));
J
Joao Moreno 已提交
99

J
Joao Moreno 已提交
100
		this.extensionsBox = append(this.root, $('.extensions'));
J
Joao Moreno 已提交
101
		this.messageBox = append(this.root, $('.message'));
J
Joao Moreno 已提交
102 103

		const delegate = new Delegate();
104
		const renderer = this.instantiationService.createInstance(Renderer);
J
Joao Moreno 已提交
105
		this.list = new PagedList(this.extensionsBox, delegate, [renderer]);
J
Joao Moreno 已提交
106

J
Joao Moreno 已提交
107 108 109 110 111 112 113 114 115
		const onKeyDown = chain(domEvent(this.searchBox, 'keydown'))
			.map(e => new StandardKeyboardEvent(e));

		onKeyDown.filter(e => e.keyCode === KeyCode.Enter).on(this.onEnter, this, this.disposables);
		onKeyDown.filter(e => e.keyCode === KeyCode.Escape).on(this.onEscape, this, this.disposables);
		onKeyDown.filter(e => e.keyCode === KeyCode.UpArrow).on(this.onUpArrow, this, this.disposables);
		onKeyDown.filter(e => e.keyCode === KeyCode.DownArrow).on(this.onDownArrow, this, this.disposables);
		onKeyDown.filter(e => e.keyCode === KeyCode.PageUp).on(this.onPageUpArrow, this, this.disposables);
		onKeyDown.filter(e => e.keyCode === KeyCode.PageDown).on(this.onPageDownArrow, this, this.disposables);
J
Joao Moreno 已提交
116

117 118 119 120
		const onSearchInput = domEvent(this.searchBox, 'input') as EventOf<SearchInputEvent>;
		onSearchInput(e => this.triggerSearch(e.target.value, e.immediate), null, this.disposables);

		this.onSearchChange = mapEvent(onSearchInput, e => e.target.value);
J
Joao Moreno 已提交
121

J
Joao Moreno 已提交
122 123 124
		chain(this.list.onSelectionChange)
			.map(e => e.elements[0])
			.filter(e => !!e)
125
			.on(this.openExtension, this, this.disposables);
J
Joao Moreno 已提交
126

J
Joao Moreno 已提交
127 128 129
		return TPromise.as(null);
	}

J
Johannes Rieken 已提交
130
	setVisible(visible: boolean): TPromise<void> {
J
Joao Moreno 已提交
131 132
		return super.setVisible(visible).then(() => {
			if (visible) {
J
Joao Moreno 已提交
133
				this.searchBox.focus();
134 135
				this.searchBox.setSelectionRange(0, this.searchBox.value.length);
				this.triggerSearch(this.searchBox.value, true, true);
J
Joao Moreno 已提交
136
			} else {
J
Joao Moreno 已提交
137
				this.setModel(new PagedModel([]));
J
Joao Moreno 已提交
138 139
			}
		});
J
Joao Moreno 已提交
140 141 142
	}

	focus(): void {
J
Joao Moreno 已提交
143
		this.searchBox.focus();
J
Joao Moreno 已提交
144 145
	}

J
Johannes Rieken 已提交
146
	layout({ height, width }: Dimension): void {
J
Joao Moreno 已提交
147
		this.list.layout(height - 38);
J
Joao Moreno 已提交
148 149 150 151 152
		toggleClass(this.root, 'narrow', width <= 300);
	}

	getOptimalWidth(): number {
		return 400;
J
Joao Moreno 已提交
153 154
	}

J
Joao Moreno 已提交
155
	getActions(): IAction[] {
J
Joao Moreno 已提交
156 157 158 159
		if (!this.primaryActions) {
			this.primaryActions = [
				this.instantiationService.createInstance(ClearExtensionsInputAction, ClearExtensionsInputAction.ID, ClearExtensionsInputAction.LABEL, this.onSearchChange)
			];
160 161
		}

J
Joao Moreno 已提交
162
		return this.primaryActions;
J
Joao Moreno 已提交
163 164
	}

165
	getSecondaryActions(): IAction[] {
J
Joao Moreno 已提交
166 167 168 169
		if (!this.secondaryActions) {
			this.secondaryActions = [
				this.instantiationService.createInstance(ShowInstalledExtensionsAction, ShowInstalledExtensionsAction.ID, ShowInstalledExtensionsAction.LABEL),
				this.instantiationService.createInstance(ShowOutdatedExtensionsAction, ShowOutdatedExtensionsAction.ID, ShowOutdatedExtensionsAction.LABEL),
170
				this.instantiationService.createInstance(ShowDisabledExtensionsAction, ShowDisabledExtensionsAction.ID, ShowDisabledExtensionsAction.LABEL),
J
Joao Moreno 已提交
171
				this.instantiationService.createInstance(ShowRecommendedExtensionsAction, ShowRecommendedExtensionsAction.ID, ShowRecommendedExtensionsAction.LABEL),
S
Sandeep Somavarapu 已提交
172
				this.instantiationService.createInstance(ShowWorkspaceRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction.ID, ShowWorkspaceRecommendedExtensionsAction.LABEL),
173
				this.instantiationService.createInstance(ShowRecommendedKeymapExtensionsAction, ShowRecommendedKeymapExtensionsAction.ID, ShowRecommendedKeymapExtensionsAction.LABEL),
J
Joao Moreno 已提交
174 175
				this.instantiationService.createInstance(ShowPopularExtensionsAction, ShowPopularExtensionsAction.ID, ShowPopularExtensionsAction.LABEL),
				new Separator(),
J
Joao Moreno 已提交
176 177
				this.instantiationService.createInstance(ChangeSortAction, 'extensions.sort.install', localize('sort by installs', "Sort By: Install Count"), this.onSearchChange, 'installs', undefined),
				this.instantiationService.createInstance(ChangeSortAction, 'extensions.sort.rating', localize('sort by rating', "Sort By: Rating"), this.onSearchChange, 'rating', undefined),
J
Joao Moreno 已提交
178
				new Separator(),
J
Joao Moreno 已提交
179
				this.instantiationService.createInstance(ChangeSortAction, 'extensions.sort..asc', localize('ascending', "Sort Order: ↑"), this.onSearchChange, undefined, 'asc'),
J
Joao Moreno 已提交
180 181
				this.instantiationService.createInstance(ChangeSortAction, 'extensions.sort..desc', localize('descending', "Sort Order: ↓"), this.onSearchChange, undefined, 'desc'),
				new Separator(),
J
Joao Moreno 已提交
182 183
				this.instantiationService.createInstance(UpdateAllAction, UpdateAllAction.ID, UpdateAllAction.LABEL),
				this.instantiationService.createInstance(InstallVSIXAction, InstallVSIXAction.ID, InstallVSIXAction.LABEL)
J
Joao Moreno 已提交
184 185 186 187
			];
		}

		return this.secondaryActions;
188 189
	}

J
Joao Moreno 已提交
190 191 192 193 194 195 196 197 198 199 200 201 202 203
	private setModel(model: IPagedModel<IExtension>) {
		this.list.model = model;
		this.list.scrollTop = 0;

		toggleClass(this.extensionsBox, 'hidden', model.length === 0);
		toggleClass(this.messageBox, 'hidden', model.length > 0);

		if (model.length === 0 && this.isVisible()) {
			this.messageBox.textContent = localize('no extensions found', "No extensions found.");
		} else {
			this.messageBox.textContent = '';
		}
	}

204
	search(value: string): void {
205
		const event = new Event('input', { bubbles: true }) as SearchInputEvent;
206
		event.immediate = true;
207 208 209

		this.searchBox.value = value;
		this.searchBox.dispatchEvent(event);
J
Joao Moreno 已提交
210 211
	}

212
	private triggerSearch(value: string, immediate = false, suggestPopular = false): void {
J
Joao Moreno 已提交
213 214
		this.searchDelayer.trigger(() => this.doSearch(value, suggestPopular), immediate || !value ? 0 : 500)
			.done(null, err => this.onError(err));
J
Joao Moreno 已提交
215 216
	}

217
	private doSearch(value: string = '', suggestPopular = false): TPromise<any> {
218 219 220
		return this.progress(this.query(value))
			.then(model => {
				if (!value && model.length === 0 && suggestPopular) {
J
Joao Moreno 已提交
221
					return this.search('@sort:installs ');
222 223
				}

J
Joao Moreno 已提交
224
				this.setModel(model);
225 226 227
			});
	}

J
Joao Moreno 已提交
228
	private query(value: string): TPromise<IPagedModel<IExtension>> {
229 230 231
		if (!value) {
			// Show installed extensions
			return this.extensionsWorkbenchService.queryLocal()
232
				.then(result => result.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)))
233 234 235
				.then(result => result.filter(e => e.type === LocalExtensionType.User))
				.then(result => new PagedModel(result));
		}
236

237 238
		if (/@outdated/i.test(value)) {
			return this.extensionsWorkbenchService.queryLocal()
J
Joao Moreno 已提交
239
				.then(result => result.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)))
240
				.then(extensions => extensions.filter(extension => extension.outdated))
241
				.then(result => new PagedModel(result));
242
		}
243

244 245
		if (/@disabled/i.test(value)) {
			return this.extensionsWorkbenchService.queryLocal()
J
Joao Moreno 已提交
246
				.then(result => result.sort((e1, e2) => e1.displayName.localeCompare(e2.displayName)))
S
Sandeep Somavarapu 已提交
247
				.then(result => this.extensionService.getExtensions()
S
Sandeep Somavarapu 已提交
248
					.then(runningExtensions => result.filter(e => runningExtensions.every(r => r.id !== e.identifier))))
249 250 251
				.then(result => new PagedModel(result));
		}

J
Joao Moreno 已提交
252
		const query = Query.parse(value);
253 254
		let options: IQueryOptions = {};

J
Johannes Rieken 已提交
255
		switch (query.sortBy) {
J
Joao Moreno 已提交
256 257 258 259 260 261 262 263 264
			case 'installs': options = assign(options, { sortBy: SortBy.InstallCount }); break;
			case 'rating': options = assign(options, { sortBy: SortBy.AverageRating }); break;
		}

		switch (query.sortOrder) {
			case 'asc': options = assign(options, { sortOrder: SortOrder.Ascending }); break;
			case 'desc': options = assign(options, { sortOrder: SortOrder.Descending }); break;
		}

S
Sandeep Somavarapu 已提交
265
		if (/@recommended:workspace/i.test(query.value)) {
266
			return this.getWorkspaceRecommendationsModel(query, options);
267 268
		} else if (/@recommended:keymaps/i.test(query.value)) {
			return this.getKeymapRecommendationsModel(query, options);
269 270
		} else if (/@recommended/i.test(query.value)) {
			return this.getRecommendationsModel(query, options);
J
Joao Moreno 已提交
271 272
		}

J
Joao Moreno 已提交
273 274 275 276 277 278
		const text = value = query.value
			.replace(/\bext:([^\s]+)\b/g, 'tag:"__ext_$1"')
			.substr(0, 200);

		if (text) {
			options = assign(options, { text });
J
Joao Moreno 已提交
279
		}
280 281 282

		return this.extensionsWorkbenchService.queryGallery(options)
			.then(result => new PagedModel(result));
J
Joao Moreno 已提交
283 284
	}

J
Joao Moreno 已提交
285
	private getRecommendationsModel(query: Query, options: IQueryOptions): TPromise<IPagedModel<IExtension>> {
286 287 288 289 290 291
		const value = query.value.replace(/@recommended/g, '').trim().toLowerCase();

		return this.extensionsWorkbenchService.queryLocal()
			.then(result => result.filter(e => e.type === LocalExtensionType.User))
			.then(local => {
				const names = this.tipsService.getRecommendations()
J
Johannes Rieken 已提交
292
					.filter(name => local.every(ext => `${ext.publisher}.${ext.name}` !== name))
293 294 295 296 297
					.filter(name => name.toLowerCase().indexOf(value) > -1);

				this.telemetryService.publicLog('extensionRecommendations:open', { count: names.length });

				if (!names.length) {
J
Joao Moreno 已提交
298
					return TPromise.as(new PagedModel([]));
299 300 301 302 303 304 305
				}

				return this.extensionsWorkbenchService.queryGallery(assign(options, { names, pageSize: names.length }))
					.then(result => new PagedModel(result));
			});
	}

J
Joao Moreno 已提交
306
	private getWorkspaceRecommendationsModel(query: Query, options: IQueryOptions): TPromise<IPagedModel<IExtension>> {
307
		const value = query.value.replace(/@recommended:workspace/g, '').trim().toLowerCase();
308 309 310 311
		return this.tipsService.getWorkspaceRecommendations()
			.then(recommendations => {
				const names = recommendations.filter(name => name.toLowerCase().indexOf(value) > -1);
				this.telemetryService.publicLog('extensionWorkspaceRecommendations:open', { count: names.length });
312

313 314 315
				if (!names.length) {
					return TPromise.as(new PagedModel([]));
				}
316

317 318 319
				return this.extensionsWorkbenchService.queryGallery(assign(options, { names, pageSize: names.length }))
					.then(result => new PagedModel(result));
			});
S
Sandeep Somavarapu 已提交
320 321
	}

322 323 324 325 326 327 328 329 330 331 332 333 334 335
	private getKeymapRecommendationsModel(query: Query, options: IQueryOptions): TPromise<IPagedModel<IExtension>> {
		const value = query.value.replace(/@recommended:keymaps/g, '').trim().toLowerCase();
		const names = this.tipsService.getKeymapRecommendations()
			.filter(name => name.toLowerCase().indexOf(value) > -1);
		this.telemetryService.publicLog('extensionKeymapRecommendations:open', { count: names.length });

		if (!names.length) {
			return TPromise.as(new PagedModel([]));
		}

		return this.extensionsWorkbenchService.queryGallery(assign(options, { names, pageSize: names.length }))
			.then(result => new PagedModel(result));
	}

336 337 338 339
	private openExtension(extension: IExtension): void {
		this.extensionsWorkbenchService.open(extension).done(null, err => this.onError(err));
	}

J
Joao Moreno 已提交
340 341 342 343 344
	private onEnter(): void {
		this.list.setSelection(...this.list.getFocus());
	}

	private onEscape(): void {
345
		this.search('');
J
Joao Moreno 已提交
346 347 348 349
	}

	private onUpArrow(): void {
		this.list.focusPrevious();
J
Joao Moreno 已提交
350
		this.list.reveal(this.list.getFocus()[0]);
J
Joao Moreno 已提交
351 352 353 354
	}

	private onDownArrow(): void {
		this.list.focusNext();
J
Joao Moreno 已提交
355
		this.list.reveal(this.list.getFocus()[0]);
J
Joao Moreno 已提交
356 357
	}

J
Joao Moreno 已提交
358 359 360 361 362 363 364 365 366 367
	private onPageUpArrow(): void {
		this.list.focusPreviousPage();
		this.list.reveal(this.list.getFocus()[0]);
	}

	private onPageDownArrow(): void {
		this.list.focusNextPage();
		this.list.reveal(this.list.getFocus()[0]);
	}

368 369 370 371 372
	private progress<T>(promise: TPromise<T>): TPromise<T> {
		const progressRunner = this.progressService.show(true);
		return always(promise, () => progressRunner.done());
	}

373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
	private onViewletOpen(viewlet: IViewlet): void {
		if (!viewlet || viewlet.getId() === VIEWLET_ID) {
			return;
		}

		const model = this.editorInputService.getStacksModel();

		const promises = model.groups.map(group => {
			const position = model.positionOfGroup(group);
			const inputs = group.getEditors().filter(input => input instanceof ExtensionsInput);
			const promises = inputs.map(input => this.editorService.closeEditor(position, input));

			return TPromise.join(promises);
		});

		TPromise.join(promises).done(null, onUnexpectedError);
	}

J
Joao Moreno 已提交
391 392 393 394 395 396 397
	private onError(err: any): void {
		if (isPromiseCanceledError(err)) {
			return;
		}

		const message = err && err.message || '';

J
Joao Moreno 已提交
398
		if (/ECONNREFUSED/.test(message)) {
J
Joao Moreno 已提交
399 400
			const error = createError(localize('suggestProxyError', "Marketplace returned 'ECONNREFUSED'. Please check the 'http.proxy' setting."), {
				actions: [
401 402
					this.instantiationService.createInstance(OpenGlobalSettingsAction, OpenGlobalSettingsAction.ID, OpenGlobalSettingsAction.LABEL),
					CloseAction
J
Joao Moreno 已提交
403 404 405 406 407 408 409 410 411 412
				]
			});

			this.messageService.show(Severity.Error, error);
			return;
		}

		this.messageService.show(Severity.Error, err);
	}

J
Joao Moreno 已提交
413
	dispose(): void {
J
Joao Moreno 已提交
414
		this.disposables = dispose(this.disposables);
J
Joao Moreno 已提交
415 416 417
		super.dispose();
	}
}
J
Joao Moreno 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439

export class StatusUpdater implements IWorkbenchContribution {

	private disposables: IDisposable[];

	constructor(
		@IActivityService private activityService: IActivityService,
		@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService
	) {
		extensionsWorkbenchService.onChange(this.onServiceChange, this, this.disposables);
	}

	getId(): string {
		return 'vs.extensions.statusupdater';
	}

	private onServiceChange(): void {
		if (this.extensionsWorkbenchService.local.some(e => e.state === ExtensionState.Installing)) {
			this.activityService.showActivity(VIEWLET_ID, new ProgressBadge(() => localize('extensions', 'Extensions')), 'extensions-badge progress-badge');
			return;
		}

440 441 442 443 444 445 446
		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');
		}
J
Joao Moreno 已提交
447 448 449 450 451 452
	}

	dispose(): void {
		this.disposables = dispose(this.disposables);
	}
}