@@ -9,19 +9,15 @@ import { Disposable } from 'vs/base/common/lifecycle';
99import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
1010import { ITaskService , IWorkspaceFolderTaskResult } from 'vs/workbench/contrib/tasks/common/taskService' ;
1111import { RunOnOptions , Task , TaskRunSource , TaskSource , TaskSourceKind , TASKS_CATEGORY , WorkspaceFileTaskSource , IWorkspaceTaskSource } from 'vs/workbench/contrib/tasks/common/tasks' ;
12- import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
13- import { INotificationService , Severity } from 'vs/platform/notification/common/notification' ;
1412import { IQuickPickItem , IQuickInputService } from 'vs/platform/quickinput/common/quickInput' ;
1513import { Action2 } from 'vs/platform/actions/common/actions' ;
1614import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
1715import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust' ;
1816import { ConfigurationTarget , IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
19- import { IOpenerService } from 'vs/platform/opener/common/opener' ;
2017import { URI } from 'vs/base/common/uri' ;
2118import { Event } from 'vs/base/common/event' ;
2219import { ILogService } from 'vs/platform/log/common/log' ;
2320
24- const HAS_PROMPTED_FOR_AUTOMATIC_TASKS = 'task.hasPromptedForAutomaticTasks' ;
2521const ALLOW_AUTOMATIC_TASKS = 'task.allowAutomaticTasks' ;
2622
2723export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution {
@@ -30,10 +26,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
3026 @ITaskService private readonly _taskService : ITaskService ,
3127 @IConfigurationService private readonly _configurationService : IConfigurationService ,
3228 @IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService : IWorkspaceTrustManagementService ,
33- @ILogService private readonly _logService : ILogService ,
34- @IStorageService private readonly _storageService : IStorageService ,
35- @IOpenerService private readonly _openerService : IOpenerService ,
36- @INotificationService private readonly _notificationService : INotificationService ) {
29+ @ILogService private readonly _logService : ILogService ) {
3730 super ( ) ;
3831 if ( this . _workspaceTrustManagementService . isWorkspaceTrusted ( ) ) {
3932 this . _tryRunTasks ( ) ;
@@ -58,7 +51,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
5851 }
5952 const workspaceTasks = await this . _taskService . getWorkspaceTasks ( TaskRunSource . FolderOpen ) ;
6053 this . _logService . trace ( `RunAutomaticTasks: Found ${ workspaceTasks . size } automatic tasks` ) ;
61- await this . _runWithPermission ( this . _taskService , this . _storageService , this . _notificationService , this . _workspaceTrustManagementService , this . _openerService , this . _configurationService , workspaceTasks ) ;
54+ await this . _runWithPermission ( this . _taskService , this . _configurationService , workspaceTasks ) ;
6255 }
6356
6457 private _runTasks ( taskService : ITaskService , tasks : Array < Task | Promise < Task | undefined > > ) {
@@ -130,71 +123,24 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
130123 return { tasks, taskNames, locations } ;
131124 }
132125
133- private async _runWithPermission ( taskService : ITaskService , storageService : IStorageService , notificationService : INotificationService , workspaceTrustManagementService : IWorkspaceTrustManagementService ,
134- openerService : IOpenerService , configurationService : IConfigurationService , workspaceTaskResult : Map < string , IWorkspaceFolderTaskResult > ) {
126+ private async _runWithPermission ( taskService : ITaskService , configurationService : IConfigurationService , workspaceTaskResult : Map < string , IWorkspaceFolderTaskResult > ) {
135127
136- const hasShownPromptForAutomaticTasks = storageService . getBoolean ( HAS_PROMPTED_FOR_AUTOMATIC_TASKS , StorageScope . WORKSPACE , false ) ;
137- const { tasks, taskNames, locations } = this . _findAutoTasks ( taskService , workspaceTaskResult ) ;
128+ const { tasks, taskNames } = this . _findAutoTasks ( taskService , workspaceTaskResult ) ;
138129
139130 if ( taskNames . length === 0 ) {
140131 return ;
141132 }
142- if ( configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) === 'on' ) {
143- this . _runTasks ( taskService , tasks ) ;
144- } else if ( configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) === 'auto' && ! hasShownPromptForAutomaticTasks ) {
145- // by default, only prompt once per folder
146- // otherwise, this can be configured via the setting
147- this . _showPrompt ( notificationService , storageService , openerService , configurationService , taskNames , locations ) . then ( allow => {
148- if ( allow ) {
149- storageService . store ( HAS_PROMPTED_FOR_AUTOMATIC_TASKS , true , StorageScope . WORKSPACE , StorageTarget . USER ) ;
150- this . _runTasks ( taskService , tasks ) ;
151- }
152- } ) ;
133+ if ( configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) === 'off' ) {
134+ return ;
153135 }
154- }
155-
156- private _showPrompt ( notificationService : INotificationService , storageService : IStorageService ,
157- openerService : IOpenerService , configurationService : IConfigurationService , taskNames : Array < string > , locations : Map < string , URI > ) : Promise < boolean > {
158- return new Promise < boolean > ( resolve => {
159- notificationService . prompt ( Severity . Info , nls . localize ( 'tasks.run.allowAutomatic' ,
160- "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?" ,
161- taskNames . join ( ', ' ) ,
162- Array . from ( locations . keys ( ) ) . join ( ', ' )
163- ) ,
164- [ {
165- label : nls . localize ( 'allow' , "Allow and run" ) ,
166- run : ( ) => {
167- resolve ( true ) ;
168- configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , 'on' , ConfigurationTarget . WORKSPACE ) ;
169- }
170- } ,
171- {
172- label : nls . localize ( 'disallow' , "Disallow" ) ,
173- run : ( ) => {
174- resolve ( false ) ;
175- configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , 'off' , ConfigurationTarget . WORKSPACE ) ;
176-
177- }
178- } ,
179- {
180- label : locations . size === 1 ? nls . localize ( 'openTask' , "Open file" ) : nls . localize ( 'openTasks' , "Open files" ) ,
181- run : async ( ) => {
182- for ( const location of locations ) {
183- await openerService . open ( location [ 1 ] ) ;
184- }
185- resolve ( false ) ;
186- }
187- } ]
188- ) ;
189- storageService . store ( HAS_PROMPTED_FOR_AUTOMATIC_TASKS , true , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
190- } ) ;
136+ this . _runTasks ( taskService , tasks ) ;
191137 }
192138}
193139
194140export class ManageAutomaticTaskRunning extends Action2 {
195141
196142 public static readonly ID = 'workbench.action.tasks.manageAutomaticRunning' ;
197- public static readonly LABEL = nls . localize ( 'workbench.action.tasks.manageAutomaticRunning' , "Manage Automatic Tasks in Folder " ) ;
143+ public static readonly LABEL = nls . localize ( 'workbench.action.tasks.manageAutomaticRunning' , "Manage Automatic Tasks" ) ;
198144
199145 constructor ( ) {
200146 super ( {
@@ -207,12 +153,12 @@ export class ManageAutomaticTaskRunning extends Action2 {
207153 public async run ( accessor : ServicesAccessor ) : Promise < any > {
208154 const quickInputService = accessor . get ( IQuickInputService ) ;
209155 const configurationService = accessor . get ( IConfigurationService ) ;
210- const allowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.allowAutomaticTasks' , "Allow Automatic Tasks in Folder " ) } ;
211- const disallowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.disallowAutomaticTasks' , "Disallow Automatic Tasks in Folder " ) } ;
156+ const allowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.allowAutomaticTasks' , "Allow Automatic Tasks" ) } ;
157+ const disallowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.disallowAutomaticTasks' , "Disallow Automatic Tasks" ) } ;
212158 const value = await quickInputService . pick ( [ allowItem , disallowItem ] , { canPickMany : false } ) ;
213159 if ( ! value ) {
214160 return ;
215161 }
216- configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , value === allowItem ? 'on' : 'off' , ConfigurationTarget . WORKSPACE ) ;
162+ configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , value === allowItem ? 'on' : 'off' , ConfigurationTarget . USER ) ;
217163 }
218164}
0 commit comments