@@ -15,18 +15,19 @@ import { IQuickPickItem, IQuickInputService } from 'vs/platform/quickinput/commo
15
15
import { Action2 } from 'vs/platform/actions/common/actions' ;
16
16
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation' ;
17
17
import { IWorkspaceTrustManagementService } from 'vs/platform/workspace/common/workspaceTrust' ;
18
- import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration' ;
18
+ import { ConfigurationTarget , IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
19
19
import { IOpenerService } from 'vs/platform/opener/common/opener' ;
20
20
import { URI } from 'vs/base/common/uri' ;
21
21
import { Event } from 'vs/base/common/event' ;
22
22
import { ILogService } from 'vs/platform/log/common/log' ;
23
23
24
- const ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE = 'tasks.run.allowAutomatic' ;
24
+ const HAS_PROMPTED_FOR_AUTOMATIC_TASKS = 'task.hasPromptedForAutomaticTasks' ;
25
+ const ALLOW_AUTOMATIC_TASKS = 'task.allowAutomaticTasks' ;
25
26
26
27
export class RunAutomaticTasks extends Disposable implements IWorkbenchContribution {
27
28
constructor (
28
29
@ITaskService private readonly _taskService : ITaskService ,
29
- @IStorageService private readonly _storageService : IStorageService ,
30
+ @IConfigurationService private readonly _configurationService : IConfigurationService ,
30
31
@IWorkspaceTrustManagementService private readonly _workspaceTrustManagementService : IWorkspaceTrustManagementService ,
31
32
@ILogService private readonly _logService : ILogService ) {
32
33
super ( ) ;
@@ -42,7 +43,7 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
42
43
}
43
44
44
45
this . _logService . trace ( 'RunAutomaticTasks: Checking if automatic tasks should run.' ) ;
45
- const isFolderAutomaticAllowed = this . _storageService . getBoolean ( ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE , StorageScope . WORKSPACE , undefined ) ;
46
+ const isFolderAutomaticAllowed = this . _configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) !== 'off' ;
46
47
await this . _workspaceTrustManagementService . workspaceTrustInitialized ;
47
48
const isWorkspaceTrusted = this . _workspaceTrustManagementService . isWorkspaceTrusted ( ) ;
48
49
// Only run if allowed. Prompting for permission occurs when a user first tries to run a task.
@@ -128,30 +129,33 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
128
129
}
129
130
130
131
public static async promptForPermission ( taskService : ITaskService , storageService : IStorageService , notificationService : INotificationService , workspaceTrustManagementService : IWorkspaceTrustManagementService ,
131
- openerService : IOpenerService , workspaceTaskResult : Map < string , IWorkspaceFolderTaskResult > ) {
132
+ openerService : IOpenerService , configurationService : IConfigurationService , workspaceTaskResult : Map < string , IWorkspaceFolderTaskResult > ) {
132
133
const isWorkspaceTrusted = workspaceTrustManagementService . isWorkspaceTrusted ;
133
134
if ( ! isWorkspaceTrusted ) {
134
135
return ;
135
136
}
136
-
137
- const isFolderAutomaticAllowed = storageService . getBoolean ( ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE , StorageScope . WORKSPACE , undefined ) ;
138
- if ( isFolderAutomaticAllowed !== undefined ) {
137
+ if ( configurationService . getValue ( ALLOW_AUTOMATIC_TASKS ) === 'off' ) {
139
138
return ;
140
139
}
141
140
141
+ const hasShownPromptForAutomaticTasks = storageService . getBoolean ( HAS_PROMPTED_FOR_AUTOMATIC_TASKS , StorageScope . WORKSPACE , undefined ) ;
142
142
const { tasks, taskNames, locations } = RunAutomaticTasks . _findAutoTasks ( taskService , workspaceTaskResult ) ;
143
143
if ( taskNames . length > 0 ) {
144
- // We have automatic tasks, prompt to allow.
145
- this . _showPrompt ( notificationService , storageService , taskService , openerService , taskNames , locations ) . then ( allow => {
146
- if ( allow ) {
147
- RunAutomaticTasks . _runTasks ( taskService , tasks ) ;
148
- }
149
- } ) ;
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
+ }
150
154
}
151
155
}
152
156
153
- private static _showPrompt ( notificationService : INotificationService , storageService : IStorageService , taskService : ITaskService ,
154
- openerService : IOpenerService , taskNames : Array < string > , locations : Map < string , URI > ) : Promise < boolean > {
157
+ private static _showPrompt ( notificationService : INotificationService , storageService : IStorageService ,
158
+ openerService : IOpenerService , configurationService : IConfigurationService , taskNames : Array < string > , locations : Map < string , URI > ) : Promise < boolean > {
155
159
return new Promise < boolean > ( resolve => {
156
160
notificationService . prompt ( Severity . Info , nls . localize ( 'tasks.run.allowAutomatic' ,
157
161
"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?" ,
@@ -162,14 +166,15 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
162
166
label : nls . localize ( 'allow' , "Allow and run" ) ,
163
167
run : ( ) => {
164
168
resolve ( true ) ;
165
- storageService . store ( ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE , true , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
169
+ configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , true , ConfigurationTarget . WORKSPACE ) ;
166
170
}
167
171
} ,
168
172
{
169
173
label : nls . localize ( 'disallow' , "Disallow" ) ,
170
174
run : ( ) => {
171
175
resolve ( false ) ;
172
- storageService . store ( ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE , false , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
176
+ configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , false , ConfigurationTarget . WORKSPACE ) ;
177
+
173
178
}
174
179
} ,
175
180
{
@@ -182,9 +187,9 @@ export class RunAutomaticTasks extends Disposable implements IWorkbenchContribut
182
187
}
183
188
} ]
184
189
) ;
190
+ storageService . store ( HAS_PROMPTED_FOR_AUTOMATIC_TASKS , true , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
185
191
} ) ;
186
192
}
187
-
188
193
}
189
194
190
195
export class ManageAutomaticTaskRunning extends Action2 {
@@ -202,14 +207,13 @@ export class ManageAutomaticTaskRunning extends Action2 {
202
207
203
208
public async run ( accessor : ServicesAccessor ) : Promise < any > {
204
209
const quickInputService = accessor . get ( IQuickInputService ) ;
205
- const storageService = accessor . get ( IStorageService ) ;
210
+ const configurationService = accessor . get ( IConfigurationService ) ;
206
211
const allowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.allowAutomaticTasks' , "Allow Automatic Tasks in Folder" ) } ;
207
212
const disallowItem : IQuickPickItem = { label : nls . localize ( 'workbench.action.tasks.disallowAutomaticTasks' , "Disallow Automatic Tasks in Folder" ) } ;
208
213
const value = await quickInputService . pick ( [ allowItem , disallowItem ] , { canPickMany : false } ) ;
209
214
if ( ! value ) {
210
215
return ;
211
216
}
212
-
213
- storageService . store ( ARE_AUTOMATIC_TASKS_ALLOWED_IN_WORKSPACE , value === allowItem , StorageScope . WORKSPACE , StorageTarget . MACHINE ) ;
217
+ configurationService . updateValue ( ALLOW_AUTOMATIC_TASKS , value === allowItem , ConfigurationTarget . WORKSPACE ) ;
214
218
}
215
219
}
0 commit comments