UNPKG

3.58 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2019 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.ProgressStatusBarItem = void 0;
19const tslib_1 = require("tslib");
20const inversify_1 = require("inversify");
21const common_1 = require("../common");
22const status_bar_1 = require("./status-bar");
23const promise_util_1 = require("../common/promise-util");
24const throttle = require("lodash.throttle");
25let ProgressStatusBarItem = class ProgressStatusBarItem {
26 constructor() {
27 this.id = 'theia-progress-status-bar-item';
28 this.messagesByProgress = new Map();
29 this.incomingQueue = new Array();
30 this.triggerUpdate = throttle(() => this.update(this.currentProgress), 250, { leading: true, trailing: true });
31 }
32 get currentProgress() {
33 return this.incomingQueue.slice(-1)[0];
34 }
35 showProgress(progressId, message, cancellationToken) {
36 const result = new promise_util_1.Deferred();
37 cancellationToken.onCancellationRequested(() => {
38 this.processEvent(progressId, 'done');
39 result.resolve(common_1.ProgressMessage.Cancel);
40 });
41 this.processEvent(progressId, 'start', message.text);
42 return result.promise;
43 }
44 processEvent(progressId, event, message) {
45 if (event === 'start') {
46 this.incomingQueue.push(progressId);
47 this.messagesByProgress.set(progressId, message);
48 }
49 else {
50 this.incomingQueue = this.incomingQueue.filter(id => id !== progressId);
51 this.messagesByProgress.delete(progressId);
52 }
53 this.triggerUpdate();
54 }
55 async reportProgress(progressId, update, originalMessage, _cancellationToken) {
56 const newMessage = update.message ? `${originalMessage.text}: ${update.message}` : originalMessage.text;
57 this.messagesByProgress.set(progressId, newMessage);
58 this.triggerUpdate();
59 }
60 update(progressId) {
61 const message = progressId && this.messagesByProgress.get(progressId);
62 if (!progressId || !message) {
63 this.statusBar.removeElement(this.id);
64 return;
65 }
66 const text = `$(codicon-sync~spin) ${message}`;
67 this.statusBar.setElement(this.id, {
68 text,
69 alignment: status_bar_1.StatusBarAlignment.LEFT,
70 priority: 1
71 });
72 }
73};
74(0, tslib_1.__decorate)([
75 (0, inversify_1.inject)(status_bar_1.StatusBar),
76 (0, tslib_1.__metadata)("design:type", Object)
77], ProgressStatusBarItem.prototype, "statusBar", void 0);
78ProgressStatusBarItem = (0, tslib_1.__decorate)([
79 (0, inversify_1.injectable)()
80], ProgressStatusBarItem);
81exports.ProgressStatusBarItem = ProgressStatusBarItem;
82//# sourceMappingURL=progress-status-bar-item.js.map
\No newline at end of file