From b6dd9807a98cb5172bd92c61ef9372dbd410d650 Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Mon, 23 Jul 2018 18:12:09 -0700 Subject: [PATCH] Refactoring --- src/vs/platform/actions/common/offlineMode.ts | 21 ++++++++++++------- .../electron-main/abstractUpdateService.ts | 8 +++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/vs/platform/actions/common/offlineMode.ts b/src/vs/platform/actions/common/offlineMode.ts index cb7371f1b3813..ba9de94a897dd 100644 --- a/src/vs/platform/actions/common/offlineMode.ts +++ b/src/vs/platform/actions/common/offlineMode.ts @@ -5,10 +5,10 @@ 'use strict'; -import { Action } from 'vs/base/common/actions'; import { localize } from 'vs/nls'; -import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; +import { Action } from 'vs/base/common/actions'; import { TPromise } from 'vs/base/common/winjs.base'; +import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { MenuRegistry, MenuId } from 'vs/platform/actions/common/actions'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; @@ -25,14 +25,18 @@ export class EnableOfflineMode extends Action { @IConfigurationService private configurationService: IConfigurationService ) { super(id, label); - this.enabled = this.configurationService.getValue(offlineModeSetting) !== true; + this.updateEnabled(); this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(offlineModeSetting)) { - this.enabled = this.configurationService.getValue(offlineModeSetting) !== true; + this.updateEnabled(); } }); } + private updateEnabled() { + this.enabled = this.configurationService.getValue(offlineModeSetting) !== true; + } + run(): TPromise { return this.configurationService.updateValue(offlineModeSetting, true); } @@ -48,20 +52,23 @@ export class DisableOfflineMode extends Action { @IConfigurationService private configurationService: IConfigurationService ) { super(id, label); - this.enabled = this.configurationService.getValue(offlineModeSetting) === true; + this.updateEnabled(); this.configurationService.onDidChangeConfiguration(e => { if (e.affectsConfiguration(offlineModeSetting)) { - this.enabled = this.configurationService.getValue(offlineModeSetting) === true; + this.updateEnabled(); } }); } + private updateEnabled() { + this.enabled = this.configurationService.getValue(offlineModeSetting) === true; + } + run(): TPromise { return this.configurationService.updateValue(offlineModeSetting, false); } } - export class NotifyUnsupportedFeatureInOfflineMode extends Action { static readonly ID = 'workbench.action.notifyUnsupportedFeatureInOfflineMode'; diff --git a/src/vs/platform/update/electron-main/abstractUpdateService.ts b/src/vs/platform/update/electron-main/abstractUpdateService.ts index 50cb3c5acd1ba..e37a8141a412f 100644 --- a/src/vs/platform/update/electron-main/abstractUpdateService.ts +++ b/src/vs/platform/update/electron-main/abstractUpdateService.ts @@ -61,8 +61,7 @@ export abstract class AbstractUpdateService implements IUpdateService { } const quality = this.getProductQuality(); - const offlineMode = this.configurationService.getValue(offlineModeSetting); - if (!quality || offlineMode === true) { + if (!quality) { this.logService.info('update#ctor - updates are disabled'); return; } @@ -75,6 +74,11 @@ export abstract class AbstractUpdateService implements IUpdateService { this.setState(State.Idle(this.getUpdateType())); + if (this.configurationService.getValue(offlineModeSetting) === true) { + this.logService.info('update#ctor - updates are disabled due to offline mode'); + return; + } + // Start checking for updates after 30 seconds this.scheduleCheckForUpdates(30 * 1000) .done(null, err => this.logService.error(err));