@@ -9,19 +9,15 @@ import { Disposable } from 'vs/base/common/lifecycle';
9
9
import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
10
10
import { ITaskService , IWorkspaceFolderTaskResult } from 'vs/workbench/contrib/tasks/common/taskService' ;
11
11
import { 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' ;
14
12
import { IQuickPickItem , IQuickInputService } from 'vs/platform/quickinput/common/quickInput' ;
15
13
import { Action2 } from 'vs/platform/actions/common/actions' ;
16
14
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
17
15
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust' ;
18
16
import { ConfigurationTarget , IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
19
- import { IOpenerService } from 'vs/platform/opener/common/opener' ;
20
17
import { URI } from 'vs/base/common/uri' ;
21
18
import { Event } from 'vs/base/common/event' ;
22
19
import { ILogService } from 'vs/platform/log/common/log' ;
23
20
24
- const HAS_PROMPTED_FOR_AUTOMATIC_TASKS = 'task.hasPromptedForAutomaticTasks' ;
25
21
const ALLOW_AUTOMATIC_TASKS = 'task.allowAutomaticTasks' ;
26
22
27
23
export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution {
@@ -30,10 +26,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
30
26
@ITaskService private readonly _taskService : ITaskService ,
31
27
@IConfigurationService private readonly _configurationService : IConfigurationService ,
32
28
@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 ) {
37
30
super ( ) ;
38
31
if ( this . _workspaceTrustManagementService . isWorkspaceTrusted ( ) ) {
39
32
this . _tryRunTasks ( ) ;
@@ -58,7 +51,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
58
51
}
59
52
const workspaceTasks = await this . _taskService . getWorkspaceTasks ( TaskRunSource . FolderOpen ) ;
60
53
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 ) ;
62
55
}
63
56
64
57
private _runTasks ( taskService : ITaskService , tasks : Array < Task | Promise < Task | undefined > > ) {
@@ -130,71 +123,24 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
130
123
return { tasks, taskNames, locations } ;
131
124
}
132
125
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 > ) {
135
127
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 ) ;
138
129
139
130
if ( taskNames . length === 0 ) {
140
131
return ;
141
132
}
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 ;
153
135
}
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 ) ;
191
137
}
192
138
}
193
139
194
140
export class ManageAutomaticTaskRunning extends Action2 {
195
141
196
142
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" ) ;
198
144
199
145
constructor ( ) {
200
146
super ( {
@@ -207,12 +153,12 @@ export class ManageAutomaticTaskRunning extends Action2 {
207
153
public async run ( accessor : ServicesAccessor ) : Promise < any > {
208
154
const quickInputService = accessor . get ( IQuickInputService ) ;
209
155
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" ) } ;
212
158
const value = await quickInputService . pick ( [ allowItem , disallowItem ] , { canPickMany : false } ) ;
213
159
if ( ! value ) {
214
160
return ;
215
161
}
216
- configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , value === allowItem ? 'on' : 'off' , ConfigurationTarget . WORKSPACE ) ;
162
+ configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , value === allowItem ? 'on' : 'off' , ConfigurationTarget . USER ) ;
217
163
}
218
164
}
0 commit comments