-
-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathnotifications-manager.ts
46 lines (43 loc) · 1.65 KB
/
notifications-manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { injectable } from '@theia/core/shared/inversify';
import { CancellationToken } from '@theia/core/lib/common/cancellation';
import {
ProgressMessage,
ProgressUpdate,
} from '@theia/core/lib/common/message-service-protocol';
import { NotificationManager as TheiaNotificationManager } from '@theia/messages/lib/browser/notifications-manager';
@injectable()
export class NotificationManager extends TheiaNotificationManager {
override async reportProgress(
messageId: string,
update: ProgressUpdate,
originalMessage: ProgressMessage,
cancellationToken: CancellationToken
): Promise<void> {
const notification = this.find(messageId);
if (!notification) {
return;
}
if (cancellationToken.isCancellationRequested) {
this.clear(messageId);
} else {
notification.message =
originalMessage.text && update.message
? `${originalMessage.text}: ${update.message}`
: originalMessage.text || update?.message || notification.message;
// Unlike in Theia, we allow resetting the progress monitor to NaN to enforce unknown progress.
const candidate = this.toPlainProgress(update);
notification.progress =
typeof candidate === 'number' ? candidate : notification.progress;
}
this.fireUpdatedEvent();
}
protected override toPlainProgress(update: ProgressUpdate): number | undefined {
if (!update.work) {
return undefined;
}
if (Number.isNaN(update.work.done) || Number.isNaN(update.work.total)) {
return Number.NaN; // This should trigger the unknown monitor.
}
return Math.min((update.work.done / update.work.total) * 100, 100);
}
}