@@ -106,7 +106,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
106
106
* @returns The ref of the stored state.
107
107
*/
108
108
async write ( resource : SyncResource , content : string | EditSession ) : Promise < string > {
109
- await this . initialize ( false ) ;
109
+ await this . initialize ( 'write' , false ) ;
110
110
if ( ! this . initialized ) {
111
111
throw new Error ( 'Please sign in to store your edit session.' ) ;
112
112
}
@@ -131,7 +131,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
131
131
* @returns An object representing the requested or latest state, if any.
132
132
*/
133
133
async read ( resource : SyncResource , ref : string | undefined ) : Promise < { ref : string ; content : string } | undefined > {
134
- await this . initialize ( false ) ;
134
+ await this . initialize ( 'read' , false ) ;
135
135
if ( ! this . initialized ) {
136
136
throw new Error ( 'Please sign in to apply your latest edit session.' ) ;
137
137
}
@@ -159,7 +159,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
159
159
}
160
160
161
161
async delete ( resource : SyncResource , ref : string | null ) {
162
- await this . initialize ( false ) ;
162
+ await this . initialize ( 'write' , false ) ;
163
163
if ( ! this . initialized ) {
164
164
throw new Error ( `Unable to delete edit session with ref ${ ref } .` ) ;
165
165
}
@@ -172,7 +172,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
172
172
}
173
173
174
174
async list ( resource : SyncResource ) : Promise < IResourceRefHandle [ ] > {
175
- await this . initialize ( false ) ;
175
+ await this . initialize ( 'read' , false ) ;
176
176
if ( ! this . initialized ) {
177
177
throw new Error ( `Unable to list edit sessions.` ) ;
178
178
}
@@ -186,11 +186,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
186
186
return [ ] ;
187
187
}
188
188
189
- public async initialize ( silent : boolean = false ) {
189
+ public async initialize ( reason : 'read' | 'write' , silent : boolean = false ) {
190
190
if ( this . initialized ) {
191
191
return true ;
192
192
}
193
- this . initialized = await this . doInitialize ( silent ) ;
193
+ this . initialized = await this . doInitialize ( reason , silent ) ;
194
194
this . signedInContext . set ( this . initialized ) ;
195
195
if ( this . initialized ) {
196
196
this . _didSignIn . fire ( ) ;
@@ -205,7 +205,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
205
205
* meaning that authentication is configured and it
206
206
* can be used to communicate with the remote storage service
207
207
*/
208
- private async doInitialize ( silent : boolean ) : Promise < boolean > {
208
+ private async doInitialize ( reason : 'read' | 'write' , silent : boolean ) : Promise < boolean > {
209
209
// Wait for authentication extensions to be registered
210
210
await this . extensionService . whenInstalledExtensionsRegistered ( ) ;
211
211
@@ -231,7 +231,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
231
231
return true ;
232
232
}
233
233
234
- const authenticationSession = await this . getAuthenticationSession ( silent ) ;
234
+ const authenticationSession = await this . getAuthenticationSession ( reason , silent ) ;
235
235
if ( authenticationSession !== undefined ) {
236
236
this . authenticationInfo = authenticationSession ;
237
237
this . storeClient . setAuthToken ( authenticationSession . token , authenticationSession . providerId ) ;
@@ -243,7 +243,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
243
243
private cachedMachines : Map < string , string > | undefined ;
244
244
245
245
async getMachineById ( machineId : string ) {
246
- await this . initialize ( false ) ;
246
+ await this . initialize ( 'read' , false ) ;
247
247
248
248
if ( ! this . cachedMachines ) {
249
249
const machines = await this . machineClient ! . getMachines ( ) ;
@@ -264,7 +264,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
264
264
return currentMachineId ;
265
265
}
266
266
267
- private async getAuthenticationSession ( silent : boolean ) {
267
+ private async getAuthenticationSession ( reason : 'read' | 'write' , silent : boolean ) {
268
268
// If the user signed in previously and the session is still available, reuse that without prompting the user again
269
269
if ( this . existingSessionId ) {
270
270
this . logService . info ( `Searching for existing authentication session with ID ${ this . existingSessionId } ` ) ;
@@ -295,7 +295,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
295
295
}
296
296
297
297
// Ask the user to pick a preferred account
298
- const authenticationSession = await this . getAccountPreference ( ) ;
298
+ const authenticationSession = await this . getAccountPreference ( reason ) ;
299
299
if ( authenticationSession !== undefined ) {
300
300
this . existingSessionId = authenticationSession . id ;
301
301
return { sessionId : authenticationSession . id , token : authenticationSession . idToken ?? authenticationSession . accessToken , providerId : authenticationSession . providerId } ;
@@ -312,10 +312,10 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
312
312
*
313
313
* Prompts the user to pick an authentication option for storing and getting edit sessions.
314
314
*/
315
- private async getAccountPreference ( ) : Promise < AuthenticationSession & { providerId : string } | undefined > {
315
+ private async getAccountPreference ( reason : 'read' | 'write' ) : Promise < AuthenticationSession & { providerId : string } | undefined > {
316
316
const quickpick = this . quickInputService . createQuickPick < ExistingSession | AuthenticationProviderOption | IQuickPickItem > ( ) ;
317
317
quickpick . ok = false ;
318
- quickpick . placeholder = localize ( 'choose account placeholder' , "Select an account to store your working changes in the cloud" ) ;
318
+ quickpick . placeholder = reason === 'read' ? localize ( 'choose account read placeholder' , "Select an account to restore your working changes from the cloud" ) : localize ( 'choose account placeholder' , "Select an account to store your working changes in the cloud" ) ;
319
319
quickpick . ignoreFocusOut = true ;
320
320
quickpick . items = await this . createQuickpickItems ( ) ;
321
321
@@ -482,7 +482,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
482
482
}
483
483
484
484
async run ( ) {
485
- return await that . initialize ( false ) ;
485
+ return await that . initialize ( 'write' , false ) ;
486
486
}
487
487
} ) ) ;
488
488
0 commit comments