diff --git a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts index f022fbcede25c..0aaa08a838dbb 100644 --- a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts +++ b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts @@ -9,19 +9,15 @@ import { Disposable } from 'vs/base/common/lifecycle'; import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; import { ITaskService, IWorkspaceFolderTaskResult } from 'vs/workbench/contrib/tasks/common/taskService'; import { RunOnOptions, Task, TaskRunSource, TaskSource, TaskSourceKind, TASKS_CATEGORY, WorkspaceFileTaskSource, IWorkspaceTaskSource } from 'vs/workbench/contrib/tasks/common/tasks'; -import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage'; -import { INotificationService, Severity } from 'vs/platform/notification/common/notification'; import { IQuickPickItem, IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; import { Action2 } from 'vs/platform/actions/common/actions'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust'; import { ConfigurationTarget, IConfigurationService } from 'vs/platform/configuration/common/configuration'; -import { IOpenerService } from 'vs/platform/opener/common/opener'; import { URI } from 'vs/base/common/uri'; import { Event } from 'vs/base/common/event'; import { ILogService } from 'vs/platform/log/common/log'; -const HAS_PROMPTED_FOR_AUTOMATIC_TASKS = 'task.hasPromptedForAutomaticTasks'; const ALLOW_AUTOMATIC_TASKS = 'task.allowAutomaticTasks'; export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution { @@ -30,10 +26,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut @ITaskService private readonly _taskService: ITaskService, @IConfigurationService private readonly _configurationService: IConfigurationService, @IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService, - @ILogService private readonly _logService: ILogService, - @IStorageService private readonly _storageService: IStorageService, - @IOpenerService private readonly _openerService: IOpenerService, - @INotificationService private readonly _notificationService: INotificationService) { + @ILogService private readonly _logService: ILogService) { super(); if (this._workspaceTrustManagementService.isWorkspaceTrusted()) { this._tryRunTasks(); @@ -58,7 +51,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut } const workspaceTasks = await this._taskService.getWorkspaceTasks(TaskRunSource.FolderOpen); this._logService.trace(`RunAutomaticTasks: Found ${workspaceTasks.size} automatic tasks`); - await this._runWithPermission(this._taskService, this._storageService, this._notificationService, this._workspaceTrustManagementService, this._openerService, this._configurationService, workspaceTasks); + await this._runWithPermission(this._taskService, this._configurationService, workspaceTasks); } private _runTasks(taskService: ITaskService, tasks: Array>) { @@ -130,71 +123,24 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut return { tasks, taskNames, locations }; } - private async _runWithPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustManagementService: IWorkspaceTrustManagementService, - openerService: IOpenerService, configurationService: IConfigurationService, workspaceTaskResult: Map) { + private async _runWithPermission(taskService: ITaskService, configurationService: IConfigurationService, workspaceTaskResult: Map) { - const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, false); - const { tasks, taskNames, locations } = this._findAutoTasks(taskService, workspaceTaskResult); + const { tasks, taskNames } = this._findAutoTasks(taskService, workspaceTaskResult); if (taskNames.length === 0) { return; } - if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'on') { - this._runTasks(taskService, tasks); - } else if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'auto' && !hasShownPromptForAutomaticTasks) { - // by default, only prompt once per folder - // otherwise, this can be configured via the setting - this._showPrompt(notificationService, storageService, openerService, configurationService, taskNames, locations).then(allow => { - if (allow) { - storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.WORKSPACE, StorageTarget.USER); - this._runTasks(taskService, tasks); - } - }); + if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'off') { + return; } - } - - private _showPrompt(notificationService: INotificationService, storageService: IStorageService, - openerService: IOpenerService, configurationService: IConfigurationService, taskNames: Array, locations: Map): Promise { - return new Promise(resolve => { - notificationService.prompt(Severity.Info, nls.localize('tasks.run.allowAutomatic', - "This workspace has tasks ({0}) defined ({1}) that run automatically when you open this workspace. Do you allow automatic tasks to run when you open this workspace?", - taskNames.join(', '), - Array.from(locations.keys()).join(', ') - ), - [{ - label: nls.localize('allow', "Allow and run"), - run: () => { - resolve(true); - configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'on', ConfigurationTarget.WORKSPACE); - } - }, - { - label: nls.localize('disallow', "Disallow"), - run: () => { - resolve(false); - configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'off', ConfigurationTarget.WORKSPACE); - - } - }, - { - label: locations.size === 1 ? nls.localize('openTask', "Open file") : nls.localize('openTasks', "Open files"), - run: async () => { - for (const location of locations) { - await openerService.open(location[1]); - } - resolve(false); - } - }] - ); - storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.WORKSPACE, StorageTarget.MACHINE); - }); + this._runTasks(taskService, tasks); } } export class ManageAutomaticTaskRunning extends Action2 { public static readonly ID = 'workbench.action.tasks.manageAutomaticRunning'; - public static readonly LABEL = nls.localize('workbench.action.tasks.manageAutomaticRunning', "Manage Automatic Tasks in Folder"); + public static readonly LABEL = nls.localize('workbench.action.tasks.manageAutomaticRunning', "Manage Automatic Tasks"); constructor() { super({ @@ -207,12 +153,12 @@ export class ManageAutomaticTaskRunning extends Action2 { public async run(accessor: ServicesAccessor): Promise { const quickInputService = accessor.get(IQuickInputService); const configurationService = accessor.get(IConfigurationService); - const allowItem: IQuickPickItem = { label: nls.localize('workbench.action.tasks.allowAutomaticTasks', "Allow Automatic Tasks in Folder") }; - const disallowItem: IQuickPickItem = { label: nls.localize('workbench.action.tasks.disallowAutomaticTasks', "Disallow Automatic Tasks in Folder") }; + const allowItem: IQuickPickItem = { label: nls.localize('workbench.action.tasks.allowAutomaticTasks', "Allow Automatic Tasks") }; + const disallowItem: IQuickPickItem = { label: nls.localize('workbench.action.tasks.disallowAutomaticTasks', "Disallow Automatic Tasks") }; const value = await quickInputService.pick([allowItem, disallowItem], { canPickMany: false }); if (!value) { return; } - configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, value === allowItem ? 'on' : 'off', ConfigurationTarget.WORKSPACE); + configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, value === allowItem ? 'on' : 'off', ConfigurationTarget.USER); } } diff --git a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts index a8b5100b47b74..13662e26c6a78 100644 --- a/src/vs/workbench/contrib/tasks/browser/task.contribution.ts +++ b/src/vs/workbench/contrib/tasks/browser/task.contribution.ts @@ -496,14 +496,13 @@ configurationRegistry.registerConfiguration({ }, [TaskSettingId.AllowAutomaticTasks]: { type: 'string', - enum: ['on', 'auto', 'off'], + enum: ['on', 'off'], enumDescriptions: [ nls.localize('task.allowAutomaticTasks.on', "Always"), - nls.localize('task.allowAutomaticTasks.auto', "Prompt for permission for each folder"), nls.localize('task.allowAutomaticTasks.off', "Never"), ], - description: nls.localize('task.allowAutomaticTasks', "Enable automatic tasks in the folder - note that tasks won't run in an untrusted workspace."), - default: 'auto', + description: nls.localize('task.allowAutomaticTasks', "Enable automatic tasks - note that tasks won't run in an untrusted workspace."), + default: 'on', restricted: true }, [TaskSettingId.ShowDecorations]: {