diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts index 1119e18907325..cb6dcacc81023 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessions.contribution.ts @@ -131,6 +131,7 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo this._register(this.fileService.registerProvider(EditSessionsFileSystemProvider.SCHEMA, new EditSessionsFileSystemProvider(this.editSessionsStorageService))); this.lifecycleService.onWillShutdown((e) => e.join(this.autoStoreEditSession(), { id: 'autoStoreEditSession', label: localize('autoStoreEditSession', 'Storing current edit session...') })); this._register(this.editSessionsStorageService.onDidSignIn(() => this.updateAccountsMenuBadge())); + this._register(this.editSessionsStorageService.onDidSignOut(() => this.updateAccountsMenuBadge())); } private autoResumeEditSession() { @@ -377,6 +378,10 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo this.logService.info(ref !== undefined ? `Resuming edit session with ref ${ref}...` : 'Resuming edit session...'); + if (silent && !(await this.editSessionsStorageService.initialize(false, true))) { + return; + } + const data = await this.editSessionsStorageService.read(ref); if (!data) { if (ref === undefined && !silent) { @@ -397,6 +402,9 @@ export class EditSessionsContribution extends Disposable implements IWorkbenchCo try { const { changes, conflictingChanges } = await this.generateChanges(editSession, ref); + if (changes.length === 0) { + return; + } // TODO@joyceerhl Provide the option to diff files which would be overwritten by edit session contents if (conflictingChanges.length > 0) { diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts b/src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts index 7637ef73355dc..fcdcc89dcce04 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessionsStorageService.ts @@ -56,6 +56,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes return this._didSignIn.event; } + private _didSignOut = new Emitter(); + get onDidSignOut() { + return this._didSignOut.event; + } + constructor( @IFileService private readonly fileService: IFileService, @IStorageService private readonly storageService: IStorageService, @@ -162,11 +167,11 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes return []; } - public async initialize(fromContinueOn: boolean) { + public async initialize(fromContinueOn: boolean, silent: boolean = false) { if (this.initialized) { return true; } - this.initialized = await this.doInitialize(fromContinueOn); + this.initialized = await this.doInitialize(fromContinueOn, silent); this.signedInContext.set(this.initialized); if (this.initialized) { this._didSignIn.fire(); @@ -181,7 +186,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes * meaning that authentication is configured and it * can be used to communicate with the remote storage service */ - private async doInitialize(fromContinueOn: boolean): Promise { + private async doInitialize(fromContinueOn: boolean, silent: boolean): Promise { // Wait for authentication extensions to be registered await this.extensionService.whenInstalledExtensionsRegistered(); @@ -206,7 +211,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes return true; } - const authenticationSession = await this.getAuthenticationSession(fromContinueOn); + const authenticationSession = await this.getAuthenticationSession(fromContinueOn, silent); if (authenticationSession !== undefined) { this.#authenticationInfo = authenticationSession; this.storeClient.setAuthToken(authenticationSession.token, authenticationSession.providerId); @@ -239,7 +244,7 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes return currentMachineId; } - private async getAuthenticationSession(fromContinueOn: boolean) { + private async getAuthenticationSession(fromContinueOn: boolean, silent: boolean) { // If the user signed in previously and the session is still available, reuse that without prompting the user again if (this.existingSessionId) { this.logService.info(`Searching for existing authentication session with ID ${this.existingSessionId}`); @@ -247,6 +252,8 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes if (existingSession) { this.logService.info(`Found existing authentication session with ID ${existingSession.session.id}`); return { sessionId: existingSession.session.id, token: existingSession.session.idToken ?? existingSession.session.accessToken, providerId: existingSession.session.providerId }; + } else { + this._didSignOut.fire(); } } @@ -261,6 +268,12 @@ export class EditSessionsWorkbenchService extends Disposable implements IEditSes } } + // If we aren't supposed to prompt the user because + // we're in a silent flow, just return here + if (silent) { + return; + } + // Ask the user to pick a preferred account const authenticationSession = await this.getAccountPreference(fromContinueOn); if (authenticationSession !== undefined) { diff --git a/src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts b/src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts index ddde6f4d7659a..92e368b719afd 100644 --- a/src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts +++ b/src/vs/workbench/contrib/editSessions/browser/editSessionsViews.ts @@ -208,7 +208,8 @@ class EditSessionDataViewDataProvider implements ITreeViewDataProvider { const sessionData = await this.editSessionsStorageService.read(session.ref); const label = sessionData?.editSession.folders.map((folder) => folder.name).join(', ') ?? session.ref; const machineId = sessionData?.editSession.machine; - const description = machineId === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${await this.editSessionsStorageService.getMachineById(machineId)}`; + const machineName = machineId ? await this.editSessionsStorageService.getMachineById(machineId) : undefined; + const description = machineName === undefined ? fromNow(session.created, true) : `${fromNow(session.created, true)}\u00a0\u00a0\u2022\u00a0\u00a0${machineName}`; editSessions.push({ handle: resource.toString(), diff --git a/src/vs/workbench/contrib/editSessions/common/editSessions.ts b/src/vs/workbench/contrib/editSessions/common/editSessions.ts index f9b84cf5bc050..99e5c8a16cc90 100644 --- a/src/vs/workbench/contrib/editSessions/common/editSessions.ts +++ b/src/vs/workbench/contrib/editSessions/common/editSessions.ts @@ -25,8 +25,9 @@ export interface IEditSessionsStorageService { readonly isSignedIn: boolean; readonly onDidSignIn: Event; + readonly onDidSignOut: Event; - initialize(fromContinueOn: boolean): Promise; + initialize(fromContinueOn: boolean, silent?: boolean): Promise; read(ref: string | undefined): Promise<{ ref: string; editSession: EditSession } | undefined>; write(editSession: EditSession): Promise; delete(ref: string | null): Promise; diff --git a/src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts b/src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts index a766a5350951a..3bcd8b1d946c0 100644 --- a/src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts +++ b/src/vs/workbench/contrib/editSessions/test/browser/editSessions.test.ts @@ -68,6 +68,7 @@ suite('Edit session sync', () => { instantiationService.stub(INotificationService, new TestNotificationService()); instantiationService.stub(IEditSessionsStorageService, new class extends mock() { override onDidSignIn = Event.None; + override onDidSignOut = Event.None; }); instantiationService.stub(IProgressService, ProgressService); instantiationService.stub(ISCMService, SCMService);