提交 aac718a2 编写于 作者: S Sandeep Somavarapu

Fix #25246

上级 b4615a8f
......@@ -31,6 +31,7 @@ import { IWindowService } from 'vs/platform/windows/common/windows';
import { IExtensionService, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import URI from 'vs/base/common/uri';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
export class InstallAction extends Action {
......@@ -681,6 +682,59 @@ export class CheckForUpdatesAction extends Action {
}
}
export class ToggleAutoUpdateAction extends Action {
constructor(
id: string,
label: string,
private autoUpdateValue: boolean,
@IConfigurationService configurationService: IConfigurationService,
@IExtensionsWorkbenchService private extensionsWorkbenchService: IExtensionsWorkbenchService
) {
super(id, label, '', true);
this.updateEnablement();
configurationService.onDidUpdateConfiguration(() => this.updateEnablement());
}
private updateEnablement(): void {
this.enabled = this.extensionsWorkbenchService.isAutoUpdateEnabled !== this.autoUpdateValue;
}
run(): TPromise<any> {
return this.extensionsWorkbenchService.setAutoUpdate(this.autoUpdateValue);
}
}
export class EnableAutoUpdateAction extends ToggleAutoUpdateAction {
static ID = 'workbench.extensions.action.enableAutoUpdate';
static LABEL = localize('enableAutoUpdate', "Enable Auto Updating Extensions");
constructor(
id = EnableAutoUpdateAction.ID,
label = EnableAutoUpdateAction.LABEL,
@IConfigurationService configurationService: IConfigurationService,
@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService
) {
super(id, label, true, configurationService, extensionsWorkbenchService);
}
}
export class DisableAutoUpdateAction extends ToggleAutoUpdateAction {
static ID = 'workbench.extensions.action.disableAutoUpdate';
static LABEL = localize('disableAutoUpdate', "Disable Auto Updating Extensions");
constructor(
id = EnableAutoUpdateAction.ID,
label = EnableAutoUpdateAction.LABEL,
@IConfigurationService configurationService: IConfigurationService,
@IExtensionsWorkbenchService extensionsWorkbenchService: IExtensionsWorkbenchService
) {
super(id, label, false, configurationService, extensionsWorkbenchService);
}
}
export class UpdateAllAction extends Action {
static ID = 'workbench.extensions.action.updateAllExtensions';
......
......@@ -67,6 +67,7 @@ export interface IExtensionsWorkbenchService {
_serviceBrand: any;
onChange: Event<void>;
local: IExtension[];
isAutoUpdateEnabled: boolean;
queryLocal(): TPromise<IExtension[]>;
queryGallery(options?: IQueryOptions): TPromise<IPager<IExtension>>;
canInstall(extension: IExtension): boolean;
......@@ -77,6 +78,7 @@ export interface IExtensionsWorkbenchService {
loadDependencies(extension: IExtension): TPromise<IExtensionDependencies>;
open(extension: IExtension, sideByside?: boolean): TPromise<any>;
checkForUpdates(): TPromise<void>;
setAutoUpdate(autoUpdate: boolean): TPromise<void>;
}
export const ConfigurationKey = 'extensions';
......
......@@ -24,7 +24,7 @@ import { ExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/node/e
import {
OpenExtensionsViewletAction, InstallExtensionsAction, ShowOutdatedExtensionsAction, ShowRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowPopularExtensionsAction,
ShowInstalledExtensionsAction, ShowDisabledExtensionsAction, UpdateAllAction, ConfigureWorkspaceRecommendedExtensionsAction,
EnableAllAction, EnableAllWorkpsaceAction, DisableAllAction, DisableAllWorkpsaceAction, CheckForUpdatesAction, ShowExtensionPacksAction
EnableAllAction, EnableAllWorkpsaceAction, DisableAllAction, DisableAllWorkpsaceAction, CheckForUpdatesAction, ShowExtensionPacksAction, EnableAutoUpdateAction, DisableAutoUpdateAction
} from 'vs/workbench/parts/extensions/browser/extensionsActions';
import { OpenExtensionsFolderAction, InstallVSIXAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
import { ExtensionsInput } from 'vs/workbench/parts/extensions/common/extensionsInput';
......@@ -157,6 +157,9 @@ actionRegistry.registerWorkbenchAction(enableAllWorkspaceAction, 'Extensions: En
const checkForUpdatesAction = new SyncActionDescriptor(CheckForUpdatesAction, CheckForUpdatesAction.ID, CheckForUpdatesAction.LABEL);
actionRegistry.registerWorkbenchAction(checkForUpdatesAction, `Extensions: Check for Updates`, ExtensionsLabel);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(EnableAutoUpdateAction, EnableAutoUpdateAction.ID, EnableAutoUpdateAction.LABEL), `Extensions: Enable Auto Updating Extensions`, ExtensionsLabel);
actionRegistry.registerWorkbenchAction(new SyncActionDescriptor(DisableAutoUpdateAction, DisableAutoUpdateAction.ID, DisableAutoUpdateAction.LABEL), `Extensions: Disable Auto Updating Extensions`, ExtensionsLabel);
Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
.registerConfiguration({
id: 'extensions',
......
......@@ -32,7 +32,8 @@ import { Delegate, Renderer } from 'vs/workbench/parts/extensions/browser/extens
import { IExtensionsWorkbenchService, IExtension, IExtensionsViewlet, VIEWLET_ID, ExtensionState } from '../common/extensions';
import {
ShowRecommendedExtensionsAction, ShowWorkspaceRecommendedExtensionsAction, ShowRecommendedKeymapExtensionsAction, ShowPopularExtensionsAction, ShowInstalledExtensionsAction, ShowDisabledExtensionsAction,
ShowOutdatedExtensionsAction, ClearExtensionsInputAction, ChangeSortAction, UpdateAllAction, CheckForUpdatesAction, DisableAllAction, EnableAllAction
ShowOutdatedExtensionsAction, ClearExtensionsInputAction, ChangeSortAction, UpdateAllAction, CheckForUpdatesAction, DisableAllAction, EnableAllAction,
EnableAutoUpdateAction, DisableAutoUpdateAction
} from 'vs/workbench/parts/extensions/browser/extensionsActions';
import { InstallVSIXAction } from 'vs/workbench/parts/extensions/electron-browser/extensionsActions';
import { IExtensionManagementService, IExtensionGalleryService, IExtensionTipsService, SortBy, SortOrder, IQueryOptions, LocalExtensionType } from 'vs/platform/extensionManagement/common/extensionManagement';
......@@ -52,6 +53,7 @@ import { IModeService } from 'vs/editor/common/services/modeService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { inputForeground, inputBackground, inputBorder } from 'vs/platform/theme/common/colorRegistry';
import { attachListStyler } from 'vs/platform/theme/common/styler';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
interface SearchInputEvent extends Event {
target: HTMLInputElement;
......@@ -71,6 +73,8 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
private secondaryActions: IAction[];
private disposables: IDisposable[] = [];
private isAutoUpdateEnabled: boolean;
constructor(
@ITelemetryService telemetryService: ITelemetryService,
@IExtensionGalleryService private galleryService: IExtensionGalleryService,
......@@ -86,12 +90,23 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
@IViewletService private viewletService: IViewletService,
@IExtensionService private extensionService: IExtensionService,
@IModeService private modeService: IModeService,
@IThemeService themeService: IThemeService
@IThemeService themeService: IThemeService,
@IConfigurationService private configurationService: IConfigurationService,
) {
super(VIEWLET_ID, telemetryService, themeService);
this.searchDelayer = new ThrottledDelayer(500);
this.disposables.push(viewletService.onDidViewletOpen(this.onViewletOpen, this, this.disposables));
this.isAutoUpdateEnabled = this.extensionsWorkbenchService.isAutoUpdateEnabled;
this.configurationService.onDidUpdateConfiguration(() => {
const isAutoUpdateEnabled = this.extensionsWorkbenchService.isAutoUpdateEnabled;
if (this.isAutoUpdateEnabled !== isAutoUpdateEnabled) {
this.isAutoUpdateEnabled = isAutoUpdateEnabled;
this.secondaryActions = null;
this.updateTitleArea();
}
}, this, this.disposables);
}
create(parent: Builder): TPromise<void> {
......@@ -206,7 +221,7 @@ export class ExtensionsViewlet extends Viewlet implements IExtensionsViewlet {
this.instantiationService.createInstance(ChangeSortAction, 'extensions.sort.name', localize('sort by name', "Sort By: Name"), this.onSearchChange, 'name'),
new Separator(),
this.instantiationService.createInstance(CheckForUpdatesAction, CheckForUpdatesAction.ID, CheckForUpdatesAction.LABEL),
this.instantiationService.createInstance(UpdateAllAction, UpdateAllAction.ID, UpdateAllAction.LABEL),
...(this.isAutoUpdateEnabled ? [this.instantiationService.createInstance(DisableAutoUpdateAction, DisableAutoUpdateAction.ID, DisableAutoUpdateAction.LABEL)] : [this.instantiationService.createInstance(UpdateAllAction, UpdateAllAction.ID, UpdateAllAction.LABEL), this.instantiationService.createInstance(EnableAutoUpdateAction, EnableAutoUpdateAction.ID, EnableAutoUpdateAction.LABEL)]),
this.instantiationService.createInstance(InstallVSIXAction, InstallVSIXAction.ID, InstallVSIXAction.LABEL),
new Separator(),
this.instantiationService.createInstance(DisableAllAction, DisableAllAction.ID, DisableAllAction.LABEL),
......
......@@ -26,6 +26,7 @@ import {
import { getGalleryExtensionIdFromLocal, getGalleryExtensionTelemetryData, getLocalExtensionTelemetryData } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IConfigurationEditingService, ConfigurationTarget } from 'vs/workbench/services/configuration/common/configurationEditing';
import { IChoiceService, IMessageService } from 'vs/platform/message/common/message';
import Severity from 'vs/base/common/severity';
import URI from 'vs/base/common/uri';
......@@ -308,12 +309,15 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
private _onChange: Emitter<void> = new Emitter<void>();
get onChange(): Event<void> { return this._onChange.event; }
private _isAutoUpdateEnabled: boolean;
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@IExtensionManagementService private extensionService: IExtensionManagementService,
@IExtensionGalleryService private galleryService: IExtensionGalleryService,
@IConfigurationService private configurationService: IConfigurationService,
@IConfigurationEditingService private configurationEditingService: IConfigurationEditingService,
@ITelemetryService private telemetryService: ITelemetryService,
@IMessageService private messageService: IMessageService,
@IChoiceService private choiceService: IChoiceService,
......@@ -337,6 +341,17 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
.filter(uri => /^extension/.test(uri.path))
.on(this.onOpenExtensionUrl, this, this.disposables);
this._isAutoUpdateEnabled = this.configurationService.getConfiguration<IExtensionsConfiguration>(ConfigurationKey).autoUpdate;
this.configurationService.onDidUpdateConfiguration(() => {
const isAutoUpdateEnabled = this.configurationService.getConfiguration<IExtensionsConfiguration>(ConfigurationKey).autoUpdate;
if (this._isAutoUpdateEnabled !== isAutoUpdateEnabled) {
this._isAutoUpdateEnabled = isAutoUpdateEnabled;
if (this._isAutoUpdateEnabled) {
this.checkForUpdates();
}
}
}, this, this.disposables);
this.queryLocal().done(() => this.eventuallySyncWithGallery(true));
}
......@@ -426,6 +441,17 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
return this.syncDelayer.trigger(() => this.syncWithGallery(), 0);
}
get isAutoUpdateEnabled(): boolean {
return this._isAutoUpdateEnabled;
}
setAutoUpdate(autoUpdate: boolean): TPromise<void> {
if (this.isAutoUpdateEnabled === autoUpdate) {
return TPromise.as(null);
}
return this.configurationEditingService.writeConfiguration(ConfigurationTarget.USER, { key: 'extensions.autoUpdate', value: autoUpdate });
}
private eventuallySyncWithGallery(immediate = false): void {
const loop = () => this.syncWithGallery().then(() => this.eventuallySyncWithGallery());
const delay = immediate ? 0 : ExtensionsWorkbenchService.SyncPeriod;
......@@ -452,9 +478,7 @@ export class ExtensionsWorkbenchService implements IExtensionsWorkbenchService {
}
private autoUpdateExtensions(): TPromise<any> {
const config = this.configurationService.getConfiguration<IExtensionsConfiguration>(ConfigurationKey);
if (!config.autoUpdate) {
if (!this.isAutoUpdateEnabled) {
return TPromise.as(null);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册