Skip to content

Commit b59a959

Browse files
committed
Use session id in embedder api
1 parent bd26289 commit b59a959

2 files changed

Lines changed: 15 additions & 22 deletions

File tree

src/vs/workbench/contrib/userDataSync/browser/userDataSyncAccount.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ export const enum AccountStatus {
4545

4646
export class UserDataSyncAccounts extends Disposable {
4747

48-
private static DONOT_USE_DEFAULT_ACCOUNT = 'userDataSyncAccount.donotUseDefaultAccount';
48+
private static DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY = 'userDataSyncAccount.donotUseWorkbenchSession';
4949
private static CACHED_SESSION_STORAGE_KEY = 'userDataSyncAccountPreference';
5050

5151
_serviceBrand: any;
5252

5353
readonly authenticationProviders: IAuthenticationProvider[];
54-
private readonly defaultUserDataSyncAccount: Omit<IUserDataSyncAccount, 'sessionId'> | undefined;
5554

5655
private _status: AccountStatus = AccountStatus.Uninitialized;
5756
get status(): AccountStatus { return this._status; }
@@ -77,11 +76,10 @@ export class UserDataSyncAccounts extends Disposable {
7776
@IProductService productService: IProductService,
7877
@IConfigurationService configurationService: IConfigurationService,
7978
@IExtensionService extensionService: IExtensionService,
80-
@IWorkbenchEnvironmentService environmentService: IWorkbenchEnvironmentService,
79+
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService,
8180
) {
8281
super();
8382
this.authenticationProviders = getUserDataSyncStore(productService, configurationService)?.authenticationProviders || [];
84-
this.defaultUserDataSyncAccount = environmentService.options?.loggedInAccount;
8583
if (this.authenticationProviders.length) {
8684
extensionService.whenInstalledExtensionsRegistered().then(() => {
8785
if (this.authenticationProviders.every(({ id }) => authenticationService.isAuthenticationProviderRegistered(id))) {
@@ -181,15 +179,7 @@ export class UserDataSyncAccounts extends Disposable {
181179
}
182180

183181
private isCurrentAccount(account: IUserDataSyncAccount): boolean {
184-
if (account.sessionId === this.currentSessionId) {
185-
return true;
186-
}
187-
if (this.defaultUserDataSyncAccount && this.useDefaultUserDataSyncAccount
188-
&& this.defaultUserDataSyncAccount.authenticationProviderId === account.authenticationProviderId
189-
&& this.defaultUserDataSyncAccount.accountName === account.accountName) {
190-
return true;
191-
}
192-
return false;
182+
return account.sessionId === this.currentSessionId;
193183
}
194184

195185
async pick(): Promise<boolean> {
@@ -302,17 +292,20 @@ export class UserDataSyncAccounts extends Disposable {
302292
private get currentSessionId(): string | undefined {
303293
if (this._cachedCurrentSessionId === null) {
304294
this._cachedCurrentSessionId = this.getStoredCachedSessionId();
295+
if (this._cachedCurrentSessionId === undefined && this.useWorkbenchSessionId) {
296+
this._cachedCurrentSessionId = this.environmentService.options?.sessionId;
297+
}
305298
}
306299
return this._cachedCurrentSessionId;
307300
}
308301

309302
private set currentSessionId(cachedSessionId: string | undefined) {
310-
if (this.currentSessionId !== cachedSessionId) {
303+
if (this._cachedCurrentSessionId !== cachedSessionId) {
311304
this._cachedCurrentSessionId = cachedSessionId;
312305
if (cachedSessionId === undefined) {
313306
this.storageService.remove(UserDataSyncAccounts.CACHED_SESSION_STORAGE_KEY, StorageScope.GLOBAL);
314307
} else {
315-
this.useDefaultUserDataSyncAccount = false;
308+
this.useWorkbenchSessionId = false;
316309
this.storageService.store(UserDataSyncAccounts.CACHED_SESSION_STORAGE_KEY, cachedSessionId, StorageScope.GLOBAL);
317310
}
318311
}
@@ -322,11 +315,11 @@ export class UserDataSyncAccounts extends Disposable {
322315
return this.storageService.get(UserDataSyncAccounts.CACHED_SESSION_STORAGE_KEY, StorageScope.GLOBAL);
323316
}
324317

325-
private get useDefaultUserDataSyncAccount(): boolean {
326-
return !this.storageService.getBoolean(UserDataSyncAccounts.DONOT_USE_DEFAULT_ACCOUNT, StorageScope.GLOBAL, false);
318+
private get useWorkbenchSessionId(): boolean {
319+
return !this.storageService.getBoolean(UserDataSyncAccounts.DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY, StorageScope.GLOBAL, false);
327320
}
328321

329-
private set useDefaultUserDataSyncAccount(useDefaultAccount: boolean) {
330-
this.storageService.store(UserDataSyncAccounts.DONOT_USE_DEFAULT_ACCOUNT, !useDefaultAccount, StorageScope.GLOBAL);
322+
private set useWorkbenchSessionId(useWorkbenchSession: boolean) {
323+
this.storageService.store(UserDataSyncAccounts.DONOT_USE_WORKBENCH_SESSION_STORAGE_KEY, !useWorkbenchSession, StorageScope.GLOBAL);
331324
}
332325
}

src/vs/workbench/workbench.web.api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ interface IWorkbenchConstructionOptions {
214214
userDataProvider?: IFileSystemProvider;
215215

216216
/**
217-
* Logged in user account information.
217+
* Session id of the current logged in user
218218
*/
219-
readonly loggedInAccount?: { authenticationProviderId: string, accountName: string };
219+
readonly sessionId?: string;
220220

221221
/**
222-
* Enables user data sync by default and syncs into the [loggedInAccount}(#loggedInAccount) if provided.
222+
* Enables user data sync by default and syncs into the current logged in user using the provided [sessionId}(#sessionId).
223223
*/
224224
readonly enableSyncByDefault?: boolean;
225225

0 commit comments

Comments
 (0)