1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.ProgressLocationService = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 | const inversify_1 = require("inversify");
|
21 | const message_service_protocol_1 = require("../common/message-service-protocol");
|
22 | const promise_util_1 = require("../common/promise-util");
|
23 | const event_1 = require("../common/event");
|
24 | let ProgressLocationService = class ProgressLocationService {
|
25 | constructor() {
|
26 | this.emitters = new Map();
|
27 | this.lastEvents = new Map();
|
28 | this.progressByLocation = new Map();
|
29 | }
|
30 | getProgress(locationId) {
|
31 | return this.lastEvents.get(locationId);
|
32 | }
|
33 | onProgress(locationId) {
|
34 | const emitter = this.addEmitter(locationId);
|
35 | return emitter.event;
|
36 | }
|
37 | addEmitter(locationId) {
|
38 | const emitter = new event_1.Emitter();
|
39 | const list = this.emitters.get(locationId) || [];
|
40 | list.push(emitter);
|
41 | this.emitters.set(locationId, list);
|
42 | return emitter;
|
43 | }
|
44 | async showProgress(progressId, message, cancellationToken) {
|
45 | const locationId = this.getLocationId(message);
|
46 | const result = new promise_util_1.Deferred();
|
47 | cancellationToken.onCancellationRequested(() => {
|
48 | this.processEvent(progressId, locationId, 'done');
|
49 | result.resolve(message_service_protocol_1.ProgressMessage.Cancel);
|
50 | });
|
51 | this.processEvent(progressId, locationId, 'start');
|
52 | return result.promise;
|
53 | }
|
54 | processEvent(progressId, locationId, event) {
|
55 | const progressSet = this.progressByLocation.get(locationId) || new Set();
|
56 | if (event === 'start') {
|
57 | progressSet.add(progressId);
|
58 | }
|
59 | else {
|
60 | progressSet.delete(progressId);
|
61 | }
|
62 | this.progressByLocation.set(locationId, progressSet);
|
63 | const show = !!progressSet.size;
|
64 | this.fireEvent(locationId, show);
|
65 | }
|
66 | fireEvent(locationId, show) {
|
67 | const lastEvent = this.lastEvents.get(locationId);
|
68 | const shouldFire = !lastEvent || lastEvent.show !== show;
|
69 | if (shouldFire) {
|
70 | this.lastEvents.set(locationId, { show });
|
71 | this.getOrCreateEmitters(locationId).forEach(e => e.fire({ show }));
|
72 | }
|
73 | }
|
74 | getOrCreateEmitters(locationId) {
|
75 | let emitters = this.emitters.get(locationId);
|
76 | if (!emitters) {
|
77 | emitters = [this.addEmitter(locationId)];
|
78 | }
|
79 | return emitters;
|
80 | }
|
81 | getLocationId(message) {
|
82 | return message.options && message.options.location || 'unknownLocation';
|
83 | }
|
84 | async reportProgress(progressId, update, message, cancellationToken) {
|
85 |
|
86 | }
|
87 | };
|
88 | ProgressLocationService = (0, tslib_1.__decorate)([
|
89 | (0, inversify_1.injectable)()
|
90 | ], ProgressLocationService);
|
91 | exports.ProgressLocationService = ProgressLocationService;
|
92 |
|
\ | No newline at end of file |