@@ -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
0 commit comments