@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
78 lines • 3.34 kB
JavaScript
// *****************************************************************************
// Copyright (C) 2019 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { __decorate } from "tslib";
import { injectable, inject } from 'inversify';
import { ProgressMessage } from '../common/index.js';
import { StatusBar, StatusBarAlignment } from './status-bar/index.js';
import { Deferred } from '../common/promise-util.js';
import throttle from '../../shared/lodash.throttle/index.cjs';
let ProgressStatusBarItem = class ProgressStatusBarItem {
constructor() {
this.id = 'theia-progress-status-bar-item';
this.messagesByProgress = new Map();
this.incomingQueue = new Array();
this.triggerUpdate = throttle(() => this.update(this.currentProgress), 250, { leading: true, trailing: true });
}
get currentProgress() {
return this.incomingQueue.slice(-1)[0];
}
showProgress(progressId, message, cancellationToken) {
const result = new Deferred();
cancellationToken.onCancellationRequested(() => {
this.processEvent(progressId, 'done');
result.resolve(ProgressMessage.Cancel);
});
this.processEvent(progressId, 'start', message.text);
return result.promise;
}
processEvent(progressId, event, message) {
if (event === 'start') {
this.incomingQueue.push(progressId);
this.messagesByProgress.set(progressId, message);
}
else {
this.incomingQueue = this.incomingQueue.filter(id => id !== progressId);
this.messagesByProgress.delete(progressId);
}
this.triggerUpdate();
}
async reportProgress(progressId, update, originalMessage, _cancellationToken) {
const newMessage = update.message ? `${originalMessage.text}: ${update.message}` : originalMessage.text;
this.messagesByProgress.set(progressId, newMessage);
this.triggerUpdate();
}
update(progressId) {
const message = progressId && this.messagesByProgress.get(progressId);
if (!progressId || !message) {
this.statusBar.removeElement(this.id);
return;
}
const text = `$(codicon-sync~spin) ${message}`;
this.statusBar.setElement(this.id, {
text,
alignment: StatusBarAlignment.LEFT,
priority: 1
});
}
};
__decorate([
inject(StatusBar)
], ProgressStatusBarItem.prototype, "statusBar", void 0);
ProgressStatusBarItem = __decorate([
injectable()
], ProgressStatusBarItem);
export { ProgressStatusBarItem };
//# sourceMappingURL=progress-status-bar-item.js.map