Skip to content

Commit 689cfc7

Browse files
committed
Don't prompt for auth if the auth session that the user previously used for edit sessions is no longer available
1 parent e1730b2 commit 689cfc7

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
131131
this._register(this.fileService.registerProvider(EditSessionsFileSystemProvider.SCHEMA, new EditSessionsFileSystemProvider(this.editSessionsStorageService)));
132132
this.lifecycleService.onWillShutdown((e) => e.join(this.autoStoreEditSession(), { id: 'autoStoreEditSession', label: localize('autoStoreEditSession', 'Storing current edit session...') }));
133133
this._register(this.editSessionsStorageService.onDidSignIn(() => this.updateAccountsMenuBadge()));
134+
this._register(this.editSessionsStorageService.onDidSignOut(() => this.updateAccountsMenuBadge()));
134135
}
135136

136137
private autoResumeEditSession() {
@@ -378,6 +379,10 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo
378379

379380
this.logService.info(ref !== undefined ? `Resuming edit session with ref ${ref}...` : 'Resuming edit session...');
380381

382+
if (silent && !(await this.editSessionsStorageService.initialize(false, true))) {
383+
return;
384+
}
385+
381386
const data = await this.editSessionsStorageService.read(ref);
382387
if (!data) {
383388
if (ref === undefined && !silent) {

src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
5656
return this._didSignIn.event;
5757
}
5858

59+
private _didSignOut = new Emitter<void>();
60+
get onDidSignOut() {
61+
return this._didSignOut.event;
62+
}
63+
5964
constructor(
6065
@IFileService private readonly fileService: IFileService,
6166
@IStorageService private readonly storageService: IStorageService,
@@ -162,11 +167,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
162167
return [];
163168
}
164169

165-
public async initialize(fromContinueOn: boolean) {
170+
public async initialize(fromContinueOn: boolean, silent: boolean = false) {
166171
if (this.initialized) {
167172
return true;
168173
}
169-
this.initialized = await this.doInitialize(fromContinueOn);
174+
this.initialized = await this.doInitialize(fromContinueOn, silent);
170175
this.signedInContext.set(this.initialized);
171176
if (this.initialized) {
172177
this._didSignIn.fire();
@@ -181,7 +186,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
181186
* meaning that authentication is configured and it
182187
* can be used to communicate with the remote storage service
183188
*/
184-
private async doInitialize(fromContinueOn: boolean): Promise<boolean> {
189+
private async doInitialize(fromContinueOn: boolean, silent: boolean): Promise<boolean> {
185190
// Wait for authentication extensions to be registered
186191
await this.extensionService.whenInstalledExtensionsRegistered();
187192

@@ -206,7 +211,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
206211
return true;
207212
}
208213

209-
const authenticationSession = await this.getAuthenticationSession(fromContinueOn);
214+
const authenticationSession = await this.getAuthenticationSession(fromContinueOn, silent);
210215
if (authenticationSession !== undefined) {
211216
this.#authenticationInfo = authenticationSession;
212217
this.storeClient.setAuthToken(authenticationSession.token, authenticationSession.providerId);
@@ -239,14 +244,16 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
239244
return currentMachineId;
240245
}
241246

242-
private async getAuthenticationSession(fromContinueOn: boolean) {
247+
private async getAuthenticationSession(fromContinueOn: boolean, silent: boolean) {
243248
// If the user signed in previously and the session is still available, reuse that without prompting the user again
244249
if (this.existingSessionId) {
245250
this.logService.info(`Searching for existing authentication session with ID ${this.existingSessionId}`);
246251
const existingSession = await this.getExistingSession();
247252
if (existingSession) {
248253
this.logService.info(`Found existing authentication session with ID ${existingSession.session.id}`);
249254
return { sessionId: existingSession.session.id, token: existingSession.session.idToken ?? existingSession.session.accessToken, providerId: existingSession.session.providerId };
255+
} else {
256+
this._didSignOut.fire();
250257
}
251258
}
252259

@@ -261,6 +268,12 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes
261268
}
262269
}
263270

271+
// If we aren't supposed to prompt the user because
272+
// we're in a silent flow, just return here
273+
if (silent) {
274+
return;
275+
}
276+
264277
// Ask the user to pick a preferred account
265278
const authenticationSession = await this.getAccountPreference(fromContinueOn);
266279
if (authenticationSession !== undefined) {

src/vs/workbench/contrib/editSessions/common/editSessions.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ export interface IEditSessionsStorageService {
2525

2626
readonly isSignedIn: boolean;
2727
readonly onDidSignIn: Event<void>;
28+
readonly onDidSignOut: Event<void>;
2829

29-
initialize(fromContinueOn: boolean): Promise<boolean>;
30+
initialize(fromContinueOn: boolean, silent?: boolean): Promise<boolean>;
3031
read(ref: string | undefined): Promise<{ ref: string; editSession: EditSession } | undefined>;
3132
write(editSession: EditSession): Promise<string>;
3233
delete(ref: string | null): Promise<void>;

src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ suite('Edit session sync', () => {
6868
instantiationService.stub(INotificationService, new TestNotificationService());
6969
instantiationService.stub(IEditSessionsStorageService, new class extends mock<IEditSessionsStorageService>() {
7070
override onDidSignIn = Event.None;
71+
override onDidSignOut = Event.None;
7172
});
7273
instantiationService.stub(IProgressService, ProgressService);
7374
instantiationService.stub(ISCMService, SCMService);

0 commit comments

Comments
 (0)