Skip to content

Commit e1131f9

Browse files
authored
prompt once for each folder when automatic task setting is auto and in a trusted workspace (microsoft#159504)
1 parent d72455b commit e1131f9

File tree

3 files changed

+28
-35
lines changed

3 files changed

+28
-35
lines changed

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
12281228
}
12291229
if (runSource === TaskRunSource.User) {
12301230
const workspaceTasks = await this.getWorkspaceTasks();
1231-
RunAutomaticTasks.promptForPermission(this, this._storageService, this._notificationService, this._workspaceTrustManagementService, this._openerService, this._configurationService, workspaceTasks);
1231+
RunAutomaticTasks.runWithPermission(this, this._storageService, this._notificationService, this._workspaceTrustManagementService, this._openerService, this._configurationService, workspaceTasks);
12321232
}
12331233
return executeTaskResult;
12341234
} catch (error) {

src/vs/workbench/contrib/tasks/browser/runAutomaticTasks.ts

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
2929
@ITaskService private readonly _taskService: ITaskService,
3030
@IConfigurationService private readonly _configurationService: IConfigurationService,
3131
@IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService: IWorkspaceTrustManagementService,
32-
@ILogService private readonly _logService: ILogService) {
32+
@ILogService private readonly _logService: ILogService,
33+
@IStorageService private readonly _storageService: IStorageService,
34+
@IOpenerService private readonly _openerService: IOpenerService,
35+
@INotificationService private readonly _notificationService: INotificationService) {
3336
super();
3437
this._tryRunTasks();
3538
}
@@ -42,21 +45,9 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
4245
await Event.toPromise(Event.once(this._taskService.onDidChangeTaskSystemInfo));
4346
}
4447

45-
this._logService.trace('RunAutomaticTasks: Checking if automatic tasks should run.');
46-
const isFolderAutomaticAllowed = this._configurationService.getValue(ALLOW_AUTOMATIC_TASKS) !== 'off';
47-
await this._workspaceTrustManagementService.workspaceTrustInitialized;
48-
const isWorkspaceTrusted = this._workspaceTrustManagementService.isWorkspaceTrusted();
49-
// Only run if allowed. Prompting for permission occurs when a user first tries to run a task.
50-
if (isFolderAutomaticAllowed && isWorkspaceTrusted) {
51-
this._taskService.getWorkspaceTasks(TaskRunSource.FolderOpen).then(workspaceTaskResult => {
52-
const { tasks } = RunAutomaticTasks._findAutoTasks(this._taskService, workspaceTaskResult);
53-
this._logService.trace(`RunAutomaticTasks: Found ${tasks.length} automatic tasks tasks`);
54-
55-
if (tasks.length > 0) {
56-
RunAutomaticTasks._runTasks(this._taskService, tasks);
57-
}
58-
});
59-
}
48+
const workspaceTasks = await this._taskService.getWorkspaceTasks(TaskRunSource.FolderOpen);
49+
this._logService.trace(`RunAutomaticTasks: Found ${workspaceTasks.size} automatic tasks`);
50+
await RunAutomaticTasks.runWithPermission(this._taskService, this._storageService, this._notificationService, this._workspaceTrustManagementService, this._openerService, this._configurationService, workspaceTasks);
6051
}
6152

6253
private static _runTasks(taskService: ITaskService, tasks: Array<Task | Promise<Task | undefined>>) {
@@ -128,29 +119,31 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
128119
return { tasks, taskNames, locations };
129120
}
130121

131-
public static async promptForPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustManagementService: IWorkspaceTrustManagementService,
122+
public static async runWithPermission(taskService: ITaskService, storageService: IStorageService, notificationService: INotificationService, workspaceTrustManagementService: IWorkspaceTrustManagementService,
132123
openerService: IOpenerService, configurationService: IConfigurationService, workspaceTaskResult: Map<string, IWorkspaceFolderTaskResult>) {
133124
const isWorkspaceTrusted = workspaceTrustManagementService.isWorkspaceTrusted;
134-
if (!isWorkspaceTrusted) {
125+
if (!isWorkspaceTrusted || configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'off') {
135126
return;
136127
}
137-
if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'off') {
128+
129+
const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, false);
130+
const { tasks, taskNames, locations } = RunAutomaticTasks._findAutoTasks(taskService, workspaceTaskResult);
131+
132+
if (taskNames.length === 0) {
138133
return;
139134
}
140135

141-
const hasShownPromptForAutomaticTasks = storageService.getBoolean(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, StorageScope.WORKSPACE, undefined);
142-
const { tasks, taskNames, locations } = RunAutomaticTasks._findAutoTasks(taskService, workspaceTaskResult);
143-
if (taskNames.length > 0) {
144-
if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'on') {
145-
RunAutomaticTasks._runTasks(taskService, tasks);
146-
} else if (!hasShownPromptForAutomaticTasks) {
147-
// We have automatic tasks, prompt to allow.
148-
this._showPrompt(notificationService, storageService, openerService, configurationService, taskNames, locations).then(allow => {
149-
if (allow) {
150-
RunAutomaticTasks._runTasks(taskService, tasks);
151-
}
152-
});
153-
}
136+
if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'on') {
137+
RunAutomaticTasks._runTasks(taskService, tasks);
138+
} else if (configurationService.getValue(ALLOW_AUTOMATIC_TASKS) === 'auto' && !hasShownPromptForAutomaticTasks) {
139+
// by default, only prompt once per folder
140+
// otherwise, this can be configured via the setting
141+
this._showPrompt(notificationService, storageService, openerService, configurationService, taskNames, locations).then(allow => {
142+
if (allow) {
143+
storageService.store(HAS_PROMPTED_FOR_AUTOMATIC_TASKS, true, StorageScope.WORKSPACE, StorageTarget.USER);
144+
RunAutomaticTasks._runTasks(taskService, tasks);
145+
}
146+
});
154147
}
155148
}
156149

src/vs/workbench/contrib/tasks/browser/task.contribution.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,11 @@ configurationRegistry.registerConfiguration({
500500
type: 'string',
501501
enum: ['on', 'auto', 'off'],
502502
enumDescriptions: [
503-
nls.localize('ttask.allowAutomaticTasks.on', "Always"),
503+
nls.localize('task.allowAutomaticTasks.on', "Always"),
504504
nls.localize('task.allowAutomaticTasks.auto', "Prompt for permission for each folder"),
505505
nls.localize('task.allowAutomaticTasks.off', "Never"),
506506
],
507-
description: nls.localize('task.allowAutomaticTasks', "Enable automatic tasks in the folder."),
507+
description: nls.localize('task.allowAutomaticTasks', "Enable automatic tasks in the folder - note that tasks won't run in an untrusted workspace."),
508508
default: 'auto',
509509
restricted: true
510510
},

0 commit comments

Comments
 (0)