-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathStatusBarObserver.ts
More file actions
93 lines (83 loc) · 3.61 KB
/
Copy pathStatusBarObserver.ts
File metadata and controls
93 lines (83 loc) · 3.61 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*---------------------------------------------------------------------------------------------
* Licensed to the .NET Foundation under one or more agreements.
* The .NET Foundation licenses this file to you under the MIT license.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
import {
DotnetAcquisitionCompleted,
DotnetAcquisitionFinalError,
DotnetAcquisitionStarted,
DotnetInstallExpectedAbort,
} from './EventStreamEvents';
import { EventType } from './EventType';
import { IEvent } from './IEvent';
import { IEventStreamObserver } from './IEventStreamObserver';
enum StatusBarColors {
Red = 'rgb(218,0,0)',
Green = 'rgb(0,218,0)',
}
export class StatusBarObserver implements IEventStreamObserver {
private readonly inProgressDownloads: string[] = [];
constructor(private readonly statusBarItem: vscode.StatusBarItem, private readonly showLogCommand: string) {
}
public post(event: IEvent): void {
switch (event.type) {
case EventType.DotnetAcquisitionStart:
const acquisitionStarted = event as DotnetAcquisitionStarted;
this.inProgressDownloads.push(acquisitionStarted.install.installId);
this.setAndShowStatusBar('$(cloud-download) Downloading .NET...', this.showLogCommand, '', 'Downloading .NET...');
break;
case EventType.DotnetAcquisitionCompleted:
const acquisitionCompleted = event as DotnetAcquisitionCompleted;
this.removeFromInProgress(acquisitionCompleted.install.installId);
if (this.inProgressDownloads.length === 0) {
this.resetAndHideStatusBar();
}
break;
case EventType.DotnetInstallExpectedAbort:
const abortEvent = event as DotnetInstallExpectedAbort;
this.removeFromInProgress(abortEvent.install?.installId);
if (this.inProgressDownloads.length === 0) {
this.resetAndHideStatusBar();
}
break;
case EventType.DotnetAcquisitionFinalError:
const finalError = event as DotnetAcquisitionFinalError;
this.removeFromInProgress(finalError.install?.installId);
if (this.inProgressDownloads.length === 0) {
this.resetAndHideStatusBar();
}
break;
case EventType.DotnetAcquisitionError:
this.setAndShowStatusBar('$(alert) Error acquiring .NET!', this.showLogCommand, StatusBarColors.Red, 'Error acquiring .NET');
break;
}
}
public dispose(): void {
// Nothing to dispose
}
public setAndShowStatusBar(text: string, command: string, color?: string, tooltip?: string) {
this.statusBarItem.text = text;
this.statusBarItem.command = command;
this.statusBarItem.color = color;
this.statusBarItem.tooltip = tooltip;
this.statusBarItem.show();
}
public resetAndHideStatusBar() {
this.statusBarItem.text = '';
this.statusBarItem.command = undefined;
this.statusBarItem.color = undefined;
this.statusBarItem.tooltip = undefined;
this.statusBarItem.hide();
}
private removeFromInProgress(installId: string | null | undefined): void {
if (installId)
{
const index = this.inProgressDownloads.indexOf(installId);
if (index >= 0)
{
this.inProgressDownloads.splice(index, 1);
}
}
}
}