UNPKG

@theia/core

Version:

Theia is a cloud & desktop IDE framework implemented in TypeScript.

89 lines • 3.53 kB
// ***************************************************************************** // 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 } from 'inversify'; import { ProgressMessage } from '../common/message-service-protocol.js'; import { Deferred } from '../common/promise-util.js'; import { Emitter } from '../common/event.js'; let ProgressLocationService = class ProgressLocationService { constructor() { this.emitters = new Map(); this.lastEvents = new Map(); this.progressByLocation = new Map(); } getProgress(locationId) { return this.lastEvents.get(locationId); } onProgress(locationId) { const emitter = this.addEmitter(locationId); return emitter.event; } addEmitter(locationId) { const emitter = new Emitter(); const list = this.emitters.get(locationId) || []; list.push(emitter); this.emitters.set(locationId, list); return emitter; } async showProgress(progressId, message, cancellationToken) { const locationId = this.getLocationId(message); const result = new Deferred(); cancellationToken.onCancellationRequested(() => { this.processEvent(progressId, locationId, 'done'); result.resolve(ProgressMessage.Cancel); }); this.processEvent(progressId, locationId, 'start'); return result.promise; } processEvent(progressId, locationId, event) { const progressSet = this.progressByLocation.get(locationId) || new Set(); if (event === 'start') { progressSet.add(progressId); } else { progressSet.delete(progressId); } this.progressByLocation.set(locationId, progressSet); const show = !!progressSet.size; this.fireEvent(locationId, show); } fireEvent(locationId, show) { const lastEvent = this.lastEvents.get(locationId); const shouldFire = !lastEvent || lastEvent.show !== show; if (shouldFire) { this.lastEvents.set(locationId, { show }); this.getOrCreateEmitters(locationId).forEach(e => e.fire({ show })); } } getOrCreateEmitters(locationId) { let emitters = this.emitters.get(locationId); if (!emitters) { emitters = [this.addEmitter(locationId)]; } return emitters; } getLocationId(message) { return message.options && message.options.location || 'unknownLocation'; } async reportProgress(progressId, update, message, cancellationToken) { /* NOOP */ } }; ProgressLocationService = __decorate([ injectable() ], ProgressLocationService); export { ProgressLocationService }; //# sourceMappingURL=progress-location-service.js.map