Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/meteredConnection/browser/meteredConnectionStatus.ts
5241 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';
7
import { localize } from '../../../../nls.js';
8
import { IMeteredConnectionService, METERED_CONNECTION_SETTING_KEY } from '../../../../platform/meteredConnection/common/meteredConnection.js';
9
import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from '../../../services/statusbar/browser/statusbar.js';
10
import { IWorkbenchContribution } from '../../../common/contributions.js';
11
12
export class MeteredConnectionStatusContribution extends Disposable implements IWorkbenchContribution {
13
14
static readonly ID = 'workbench.contrib.meteredConnectionStatus';
15
16
private readonly statusBarEntry = this._register(new MutableDisposable<IStatusbarEntryAccessor>());
17
18
constructor(
19
@IMeteredConnectionService private readonly meteredConnectionService: IMeteredConnectionService,
20
@IStatusbarService private readonly statusbarService: IStatusbarService,
21
) {
22
super();
23
24
this.updateStatusBarEntry(this.meteredConnectionService.isConnectionMetered);
25
26
this._register(this.meteredConnectionService.onDidChangeIsConnectionMetered(isMetered => {
27
this.updateStatusBarEntry(isMetered);
28
}));
29
}
30
31
private updateStatusBarEntry(isMetered: boolean): void {
32
if (isMetered) {
33
if (!this.statusBarEntry.value) {
34
this.statusBarEntry.value = this.statusbarService.addEntry(
35
this.getStatusBarEntry(),
36
MeteredConnectionStatusContribution.ID,
37
StatusbarAlignment.RIGHT,
38
-Number.MAX_VALUE // Show at the far right
39
);
40
}
41
} else {
42
this.statusBarEntry.clear();
43
}
44
}
45
46
private getStatusBarEntry(): IStatusbarEntry {
47
return {
48
name: localize('status.meteredConnection', "Metered Connection"),
49
text: '$(radio-tower)',
50
ariaLabel: localize('status.meteredConnection.ariaLabel', "Metered Connection Detected"),
51
tooltip: localize('status.meteredConnection.tooltip', "Metered connection detected. Some automatic features like extension updates, Settings Sync, and automatic Git operations are paused to reduce data usage."),
52
command: {
53
id: 'workbench.action.openSettings',
54
title: localize('status.meteredConnection.configure', "Configure"),
55
arguments: [`@id:${METERED_CONNECTION_SETTING_KEY}`]
56
},
57
showInAllWindows: true
58
};
59
}
60
}
61
62