@@ -29,7 +29,10 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
29
29
@ITaskService private readonly _taskService : ITaskService ,
30
30
@IConfigurationService private readonly _configurationService : IConfigurationService ,
31
31
@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 ) {
33
36
super ( ) ;
34
37
this . _tryRunTasks ( ) ;
35
38
}
@@ -42,21 +45,9 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
42
45
await Event . toPromise ( Event . once ( this . _taskService . onDidChangeTaskSystemInfo ) ) ;
43
46
}
44
47
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 ) ;
60
51
}
61
52
62
53
private static _runTasks ( taskService : ITaskService , tasks : Array < Task | Promise < Task | undefined > > ) {
@@ -128,29 +119,31 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
128
119
return { tasks, taskNames, locations } ;
129
120
}
130
121
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 ,
132
123
openerService : IOpenerService , configurationService : IConfigurationService , workspaceTaskResult : Map < string , IWorkspaceFolderTaskResult > ) {
133
124
const isWorkspaceTrusted = workspaceTrustManagementService . isWorkspaceTrusted ;
134
- if ( ! isWorkspaceTrusted ) {
125
+ if ( ! isWorkspaceTrusted || configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) === 'off' ) {
135
126
return ;
136
127
}
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 ) {
138
133
return ;
139
134
}
140
135
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
+ } ) ;
154
147
}
155
148
}
156
149
0 commit comments