diff options
Diffstat (limited to 'src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts')
-rw-r--r-- | src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts index 3d91091af90..aa0d0441b79 100644 --- a/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts +++ b/src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts @@ -8,7 +8,6 @@ import * as resources from 'vs/base/common/resources'; 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 { forEach } from 'vs/base/common/collections'; 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'; @@ -16,18 +15,19 @@ import { IQuickPickItem, IQuickInputService } from 'vs/platform/quickinput/commo 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 } from 'vs/platform/configuration/common/configuration'; +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 ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE = 'tasks.run.allowAutomatic'; +const HAS_PROMPTED_FOR_AUTOMATIC_TASKS = 'task.hasPromptedForAutomaticTasks'; +const ALLOW_AUTOMATIC_TASKS = 'task.allowAutomaticTasks'; export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution { constructor( @ITaskService private readonly _taskService: ITaskService, - @IStorageService private readonly _storageService: IStorageService, + @IConfigurationService private readonly _configurationService: IConfigurationService, @IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService, @ILogService private readonly _logService: ILogService) { super(); @@ -43,7 +43,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut } this._logService.trace('RunAutomaticTasks: Checking if automatic tasks should run.'); - const isFolderAutomaticAllowed = this._storageService.getBoolean(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, StorageScope.WORKSPACE, undefined); + const isFolderAutomaticAllowed = this._configurationService.getValue(ALLOW_AUTOMATIC_TASKS) !== 'off'; await this._workspaceTrustManagementService.workspaceTrustInitialized; const isWorkspaceTrusted = this._workspaceTrustManagementService.isWorkspaceTrusted(); // Only run if allowed. Prompting for permission occurs when a user first tries to run a task. @@ -106,22 +106,22 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut }); } if (resultElement.configurations) { - forEach(resultElement.configurations.byIdentifier, (configedTask) => { - if (configedTask.value.runOptions.runOn === RunOnOptions.folderOpen) { + for (const configuredTask of Object.values(resultElement.configurations.byIdentifier)) { + if (configuredTask.runOptions.runOn === RunOnOptions.folderOpen) { tasks.push(new Promise<Task | undefined>(resolve => { - taskService.getTask(resultElement.workspaceFolder, configedTask.value._id, true).then(task => resolve(task)); + taskService.getTask(resultElement.workspaceFolder, configuredTask._id, true).then(task => resolve(task)); })); - if (configedTask.value._label) { - taskNames.push(configedTask.value._label); + if (configuredTask._label) { + taskNames.push(configuredTask._label); } else { - taskNames.push(configedTask.value.configures.task); + taskNames.push(configuredTask.configures.task); } - const location = RunAutomaticTasks._getTaskSource(configedTask.value._source); + const location = RunAutomaticTasks._getTaskSource(configuredTask._source); if (location) { locations.set(location.fsPath, location); } } - }); + } } }); } @@ -129,30 +129,33 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut } public static async promptForPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustManagementService: IWorkspaceTrustManagementService, - openerService: IOpenerService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>) { + openerService: IOpenerService, configurationService: IConfigurationService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>) { const isWorkspaceTrusted = workspaceTrustManagementService.isWorkspaceTrusted; if (!isWorkspaceTrusted) { return; } - - const isFolderAutomaticAllowed = storageService.getBoolean(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, StorageScope.WORKSPACE, undefined); - if (isFolderAutomaticAllowed !== undefined) { + if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'off') { return; } + const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, undefined); const { tasks, taskNames, locations } = RunAutomaticTasks._findAutoTasks(taskService, workspaceTaskResult); if (taskNames.length > 0) { - // We have automatic tasks, prompt to allow. - this._showPrompt(notificationService, storageService, taskService, openerService, taskNames, locations).then(allow => { - if (allow) { - RunAutomaticTasks._runTasks(taskService, tasks); - } - }); + if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'on') { + RunAutomaticTasks._runTasks(taskService, tasks); + } else if (!hasShownPromptForAutomaticTasks) { + // We have automatic tasks, prompt to allow. + this._showPrompt(notificationService, storageService, openerService, configurationService, taskNames, locations).then(allow => { + if (allow) { + RunAutomaticTasks._runTasks(taskService, tasks); + } + }); + } } } - private static _showPrompt(notificationService: INotificationService, storageService: IStorageService, taskService: ITaskService, - openerService: IOpenerService, taskNames: Array<string>, locations: Map<string, URI>): Promise<boolean> { + private static _showPrompt(notificationService: INotificationService, storageService: IStorageService, + openerService: IOpenerService, configurationService: IConfigurationService, taskNames: Array<string>, locations: Map<string, URI>): Promise<boolean> { return new Promise<boolean>(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?", @@ -163,14 +166,15 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut label: nls.localize('allow', "Allow and run"), run: () => { resolve(true); - storageService.store(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, true, StorageScope.WORKSPACE, StorageTarget.MACHINE); + configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, true, ConfigurationTarget.WORKSPACE); } }, { label: nls.localize('disallow', "Disallow"), run: () => { resolve(false); - storageService.store(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, false, StorageScope.WORKSPACE, StorageTarget.MACHINE); + configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, false, ConfigurationTarget.WORKSPACE); + } }, { @@ -183,9 +187,9 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut } }] ); + storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.WORKSPACE, StorageTarget.MACHINE); }); } - } export class ManageAutomaticTaskRunning extends Action2 { @@ -203,14 +207,13 @@ export class ManageAutomaticTaskRunning extends Action2 { public async run(accessor: ServicesAccessor): Promise<any> { const quickInputService = accessor.get(IQuickInputService); - const storageService = accessor.get(IStorageService); + 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 value = await quickInputService.pick([allowItem, disallowItem], { canPickMany: false }); if (!value) { return; } - - storageService.store(ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE, value === allowItem, StorageScope.WORKSPACE, StorageTarget.MACHINE); + configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, value === allowItem, ConfigurationTarget.WORKSPACE); } } |