@@ -106,7 +106,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
106106 * @returns The ref of the stored state.
107107 */
108108 async write ( resource : SyncResource , content : string | EditSession ) : Promise < string > {
109- await this . initialize ( false ) ;
109+ await this . initialize ( 'write' , false ) ;
110110 if ( ! this . initialized ) {
111111 throw new Error ( 'Please sign in to store your edit session.' ) ;
112112 }
@@ -131,7 +131,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
131131 * @returns An object representing the requested or latest state, if any.
132132 */
133133 async read ( resource : SyncResource , ref : string | undefined ) : Promise < { ref : string ; content : string } | undefined > {
134- await this . initialize ( false ) ;
134+ await this . initialize ( 'read' , false ) ;
135135 if ( ! this . initialized ) {
136136 throw new Error ( 'Please sign in to apply your latest edit session.' ) ;
137137 }
@@ -159,7 +159,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
159159 }
160160
161161 async delete ( resource : SyncResource , ref : string | null ) {
162- await this . initialize ( false ) ;
162+ await this . initialize ( 'write' , false ) ;
163163 if ( ! this . initialized ) {
164164 throw new Error ( `Unable to delete edit session with ref ${ ref } .` ) ;
165165 }
@@ -172,7 +172,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
172172 }
173173
174174 async list ( resource : SyncResource ) : Promise < IResourceRefHandle [ ] > {
175- await this . initialize ( false ) ;
175+ await this . initialize ( 'read' , false ) ;
176176 if ( ! this . initialized ) {
177177 throw new Error ( `Unable to list edit sessions.` ) ;
178178 }
@@ -186,11 +186,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
186186 return [ ] ;
187187 }
188188
189- public async initialize ( silent : boolean = false ) {
189+ public async initialize ( reason : 'read' | 'write' , silent : boolean = false ) {
190190 if ( this . initialized ) {
191191 return true ;
192192 }
193- this . initialized = await this . doInitialize ( silent ) ;
193+ this . initialized = await this . doInitialize ( reason , silent ) ;
194194 this . signedInContext . set ( this . initialized ) ;
195195 if ( this . initialized ) {
196196 this . _didSignIn . fire ( ) ;
@@ -205,7 +205,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
205205 * meaning that authentication is configured and it
206206 * can be used to communicate with the remote storage service
207207 */
208- private async doInitialize ( silent : boolean ) : Promise < boolean > {
208+ private async doInitialize ( reason : 'read' | 'write' , silent : boolean ) : Promise < boolean > {
209209 // Wait for authentication extensions to be registered
210210 await this . extensionService . whenInstalledExtensionsRegistered ( ) ;
211211
@@ -231,7 +231,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
231231 return true ;
232232 }
233233
234- const authenticationSession = await this . getAuthenticationSession ( silent ) ;
234+ const authenticationSession = await this . getAuthenticationSession ( reason , silent ) ;
235235 if ( authenticationSession !== undefined ) {
236236 this . authenticationInfo = authenticationSession ;
237237 this . storeClient . setAuthToken ( authenticationSession . token , authenticationSession . providerId ) ;
@@ -243,7 +243,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
243243 private cachedMachines : Map < string , string > | undefined ;
244244
245245 async getMachineById ( machineId : string ) {
246- await this . initialize ( false ) ;
246+ await this . initialize ( 'read' , false ) ;
247247
248248 if ( ! this . cachedMachines ) {
249249 const machines = await this . machineClient ! . getMachines ( ) ;
@@ -264,7 +264,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
264264 return currentMachineId ;
265265 }
266266
267- private async getAuthenticationSession ( silent : boolean ) {
267+ private async getAuthenticationSession ( reason : 'read' | 'write' , silent : boolean ) {
268268 // If the user signed in previously and the session is still available, reuse that without prompting the user again
269269 if ( this . existingSessionId ) {
270270 this . logService . info ( `Searching for existing authentication session with ID ${ this . existingSessionId } ` ) ;
@@ -295,7 +295,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
295295 }
296296
297297 // Ask the user to pick a preferred account
298- const authenticationSession = await this . getAccountPreference ( ) ;
298+ const authenticationSession = await this . getAccountPreference ( reason ) ;
299299 if ( authenticationSession !== undefined ) {
300300 this . existingSessionId = authenticationSession . id ;
301301 return { sessionId : authenticationSession . id , token : authenticationSession . idToken ?? authenticationSession . accessToken , providerId : authenticationSession . providerId } ;
@@ -312,10 +312,10 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
312312 *
313313 * Prompts the user to pick an authentication option for storing and getting edit sessions.
314314 */
315- private async getAccountPreference ( ) : Promise < AuthenticationSession & { providerId : string } | undefined > {
315+ private async getAccountPreference ( reason : 'read' | 'write' ) : Promise < AuthenticationSession & { providerId : string } | undefined > {
316316 const quickpick = this . quickInputService . createQuickPick < ExistingSession | AuthenticationProviderOption | IQuickPickItem > ( ) ;
317317 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" ) ;
319319 quickpick . ignoreFocusOut = true ;
320320 quickpick . items = await this . createQuickpickItems ( ) ;
321321
@@ -482,7 +482,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
482482 }
483483
484484 async run ( ) {
485- return await that . initialize ( false ) ;
485+ return await that . initialize ( 'write' , false ) ;
486486 }
487487 } ) ) ;
488488
0 commit comments