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