- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathindexes-update-progress.ts
71 lines (67 loc) · 2.44 KB
/
indexes-update-progress.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import{Progress}from'@theia/core/lib/common/message-service-protocol';
import{ProgressService}from'@theia/core/lib/common/progress-service';
import{inject,injectable}from'@theia/core/shared/inversify';
import{ProgressMessage}from'../../common/protocol';
import{NotificationCenter}from'../notification-center';
import{Contribution}from'./contribution';
@injectable()
exportclassIndexesUpdateProgressextendsContribution{
@inject(NotificationCenter)
privatereadonlynotificationCenter: NotificationCenter;
@inject(ProgressService)
privatereadonlyprogressService: ProgressService;
privatecurrentProgress:
|(Progress&Readonly<{progressId: string}>)
|undefined;
overrideonStart(): void{
this.notificationCenter.onIndexUpdateWillStart(({ progressId })=>
this.getOrCreateProgress(progressId)
);
this.notificationCenter.onIndexUpdateDidProgress((progress)=>{
this.getOrCreateProgress(progress).then((delegate)=>
delegate.report(progress)
);
});
this.notificationCenter.onIndexUpdateDidComplete(({ progressId })=>{
this.cancelProgress(progressId);
});
this.notificationCenter.onIndexUpdateDidFail(({ progressId, message })=>{
this.cancelProgress(progressId);
this.messageService.error(message);
});
}
privateasyncgetOrCreateProgress(
progressOrId: ProgressMessage|string
): Promise<Progress&{progressId: string}>{
constprogressId=ProgressMessage.is(progressOrId)
? progressOrId.progressId
: progressOrId;
if(this.currentProgress?.progressId===progressId){
returnthis.currentProgress;
}
if(this.currentProgress){
this.currentProgress.cancel();
}
this.currentProgress=undefined;
constprogress=awaitthis.progressService.showProgress({
text: '',
options: {location: 'notification'},
});
if(ProgressMessage.is(progressOrId)){
progress.report(progressOrId);
}
this.currentProgress={ ...progress, progressId };
returnthis.currentProgress;
}
privatecancelProgress(progressId: string){
if(this.currentProgress){
if(this.currentProgress.progressId!==progressId){
console.warn(
`Mismatching progress IDs. Expected ${progressId}, got ${this.currentProgress.progressId}. Canceling anyway.`
);
}
this.currentProgress.cancel();
this.currentProgress=undefined;
}
}
}