Path: blob/main/src/vs/workbench/contrib/meteredConnection/browser/meteredConnectionStatus.ts
5241 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { Disposable, MutableDisposable } from '../../../../base/common/lifecycle.js';6import { localize } from '../../../../nls.js';7import { IMeteredConnectionService, METERED_CONNECTION_SETTING_KEY } from '../../../../platform/meteredConnection/common/meteredConnection.js';8import { IStatusbarEntry, IStatusbarEntryAccessor, IStatusbarService, StatusbarAlignment } from '../../../services/statusbar/browser/statusbar.js';9import { IWorkbenchContribution } from '../../../common/contributions.js';1011export class MeteredConnectionStatusContribution extends Disposable implements IWorkbenchContribution {1213static readonly ID = 'workbench.contrib.meteredConnectionStatus';1415private readonly statusBarEntry = this._register(new MutableDisposable<IStatusbarEntryAccessor>());1617constructor(18@IMeteredConnectionService private readonly meteredConnectionService: IMeteredConnectionService,19@IStatusbarService private readonly statusbarService: IStatusbarService,20) {21super();2223this.updateStatusBarEntry(this.meteredConnectionService.isConnectionMetered);2425this._register(this.meteredConnectionService.onDidChangeIsConnectionMetered(isMetered => {26this.updateStatusBarEntry(isMetered);27}));28}2930private updateStatusBarEntry(isMetered: boolean): void {31if (isMetered) {32if (!this.statusBarEntry.value) {33this.statusBarEntry.value = this.statusbarService.addEntry(34this.getStatusBarEntry(),35MeteredConnectionStatusContribution.ID,36StatusbarAlignment.RIGHT,37-Number.MAX_VALUE // Show at the far right38);39}40} else {41this.statusBarEntry.clear();42}43}4445private getStatusBarEntry(): IStatusbarEntry {46return {47name: localize('status.meteredConnection', "Metered Connection"),48text: '$(radio-tower)',49ariaLabel: localize('status.meteredConnection.ariaLabel', "Metered Connection Detected"),50tooltip: 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."),51command: {52id: 'workbench.action.openSettings',53title: localize('status.meteredConnection.configure', "Configure"),54arguments: [`@id:${METERED_CONNECTION_SETTING_KEY}`]55},56showInAllWindows: true57};58}59}606162