Skip to content

Commit

Permalink
fix #160174
Browse files Browse the repository at this point in the history
  • Loading branch information
meganrogge committed Nov 4, 2022
1 parent 285c607 commit 2f1d09c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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._storageService, this._notificationService, this._openerService, this._configurationService, workspaceTasks);
}

private _runTasks(taskService: ITaskService, tasks: Array<Task | Promise<Task | undefined>>) {
Expand Down Expand Up @@ -130,23 +130,24 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
return { tasks, taskNames, locations };
}

private async _runWithPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustManagementService: IWorkspaceTrustManagementService,
private async _runWithPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService,
openerService: IOpenerService, configurationService: IConfigurationService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>) {

const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, false);
const hasShownPromptForAutomaticTasksDeprecated = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, false);
const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.PROFILE, false);
const { tasks, taskNames, locations } = 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
} else if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'auto' && !hasShownPromptForAutomaticTasksDeprecated && !hasShownPromptForAutomaticTasks) {
// by default, only prompt once per folder/profile
// 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);
storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.PROFILE, StorageTarget.USER);
this._runTasks(taskService, tasks);
}
});
Expand All @@ -165,14 +166,14 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
label: nls.localize('allow', "Allow and run"),
run: () => {
resolve(true);
configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'on', ConfigurationTarget.WORKSPACE);
configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'on', ConfigurationTarget.USER);
}
},
{
label: nls.localize('disallow', "Disallow"),
run: () => {
resolve(false);
configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'off', ConfigurationTarget.WORKSPACE);
configurationService.updateValue(ALLOW_AUTOMATIC_TASKS, 'off', ConfigurationTarget.USER);

}
},
Expand All @@ -186,15 +187,15 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
}
}]
);
storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.WORKSPACE, StorageTarget.MACHINE);
storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.PROFILE, StorageTarget.USER);
});
}
}

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({
Expand All @@ -207,12 +208,12 @@ export class ManageAutomaticTaskRunning extends Action2 {
public async run(accessor: ServicesAccessor): Promise<any> {
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);
}
}

0 comments on commit 2f1d09c

Please sign in to comment.