Skip to content

Commit 0749cc6

Browse files
authored
fix profiles enablement in web (microsoft#166059)
- only configurable in stable (not remote) - do not sync if disabled
1 parent 1ccc8d4 commit 0749cc6

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

src/vs/platform/userDataProfile/browser/userDataProfile.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment'
1010
import { IFileService } from 'vs/platform/files/common/files';
1111
import { ILogService } from 'vs/platform/log/common/log';
1212
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
13-
import { DidChangeProfilesEvent, IUserDataProfile, IUserDataProfilesService, PROFILES_ENABLEMENT_CONFIG, reviveProfile, StoredProfileAssociations, StoredUserDataProfile, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
13+
import { DidChangeProfilesEvent, IUserDataProfile, IUserDataProfilesService, reviveProfile, StoredProfileAssociations, StoredUserDataProfile, UserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
1414

1515
type BroadcastedProfileChanges = UriDto<Omit<DidChangeProfilesEvent, 'all'>>;
1616

@@ -25,7 +25,6 @@ export class BrowserUserDataProfilesService extends UserDataProfilesService impl
2525
@ILogService logService: ILogService,
2626
) {
2727
super(environmentService, fileService, uriIdentityService, logService);
28-
super.setEnablement(window.localStorage.getItem(PROFILES_ENABLEMENT_CONFIG) === 'true');
2928
this.changesBroadcastChannel = this._register(new BroadcastDataChannel<BroadcastedProfileChanges>(`${UserDataProfilesService.PROFILES_KEY}.changes`));
3029
this._register(this.changesBroadcastChannel.onDidReceiveData(changes => {
3130
try {
@@ -66,11 +65,6 @@ export class BrowserUserDataProfilesService extends UserDataProfilesService impl
6665
}
6766
}
6867

69-
override setEnablement(enabled: boolean): void {
70-
super.setEnablement(enabled);
71-
window.localStorage.setItem(PROFILES_ENABLEMENT_CONFIG, enabled ? 'true' : 'false');
72-
}
73-
7468
protected override getStoredProfiles(): StoredUserDataProfile[] {
7569
try {
7670
const value = window.localStorage.getItem(UserDataProfilesService.PROFILES_KEY);

src/vs/platform/userDataSync/common/userDataProfilesManifestSync.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'
1515
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
1616
import { AbstractSynchroniser, IAcceptResult, IMergeResult, IResourcePreview } from 'vs/platform/userDataSync/common/abstractSynchronizer';
1717
import { merge } from 'vs/platform/userDataSync/common/userDataProfilesManifestMerge';
18-
import { Change, IRemoteUserData, IUserDataSyncBackupStoreService, IUserDataSynchroniser, IUserDataSyncLogService, IUserDataSyncEnablementService, IUserDataSyncStoreService, SyncResource, USER_DATA_SYNC_SCHEME, ISyncUserDataProfile, ISyncData, IUserDataResourceManifest } from 'vs/platform/userDataSync/common/userDataSync';
18+
import { Change, IRemoteUserData, IUserDataSyncBackupStoreService, IUserDataSynchroniser, IUserDataSyncLogService, IUserDataSyncEnablementService, IUserDataSyncStoreService, SyncResource, USER_DATA_SYNC_SCHEME, ISyncUserDataProfile, ISyncData, IUserDataResourceManifest, UserDataSyncError, UserDataSyncErrorCode } from 'vs/platform/userDataSync/common/userDataSync';
1919

2020
export interface IUserDataProfileManifestResourceMergeResult extends IAcceptResult {
2121
readonly local: { added: ISyncUserDataProfile[]; removed: IUserDataProfile[]; updated: ISyncUserDataProfile[] };
@@ -66,6 +66,9 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
6666
}
6767

6868
protected async generateSyncPreview(remoteUserData: IRemoteUserData, lastSyncUserData: IRemoteUserData | null, isRemoteDataFromCurrentMachine: boolean): Promise<IUserDataProfilesManifestResourcePreview[]> {
69+
if (!this.userDataProfilesService.isEnabled()) {
70+
throw new UserDataSyncError('Cannot sync profiles because they are disabled', UserDataSyncErrorCode.LocalError);
71+
}
6972
const remoteProfiles: ISyncUserDataProfile[] | null = remoteUserData.syncData ? parseUserDataProfilesManifest(remoteUserData.syncData) : null;
7073
const lastSyncProfiles: ISyncUserDataProfile[] | null = lastSyncUserData?.syncData ? parseUserDataProfilesManifest(lastSyncUserData.syncData) : null;
7174
const localProfiles = this.getLocalUserDataProfiles();

src/vs/workbench/browser/web.main.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { UserDataProfileService } from 'vs/workbench/services/userDataProfile/co
8282
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
8383
import { BrowserUserDataProfilesService } from 'vs/platform/userDataProfile/browser/userDataProfile';
8484
import { timeout } from 'vs/base/common/async';
85+
import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
8586

8687
export class BrowserMain extends Disposable {
8788

@@ -288,6 +289,21 @@ export class BrowserMain extends Disposable {
288289
const userDataProfileService = new UserDataProfileService(currentProfile, userDataProfilesService);
289290
serviceCollection.set(IUserDataProfileService, userDataProfileService);
290291

292+
let isProfilesEnablementConfigured = false;
293+
if (environmentService.remoteAuthority) {
294+
// Always Disabled in web with remote connection
295+
userDataProfilesService.setEnablement(false);
296+
} else {
297+
if (productService.quality === 'stable') {
298+
// Enabled from Config
299+
userDataProfilesService.setEnablement(window.localStorage.getItem(PROFILES_ENABLEMENT_CONFIG) === 'true');
300+
isProfilesEnablementConfigured = true;
301+
} else {
302+
// Always Enabled
303+
userDataProfilesService.setEnablement(true);
304+
}
305+
}
306+
291307
// Long running services (workspace, config, storage)
292308
const [configurationService, storageService] = await Promise.all([
293309
this.createWorkspaceService(workspace, environmentService, userDataProfileService, userDataProfilesService, fileService, remoteAgentService, uriIdentityService, logService).then(service => {
@@ -310,12 +326,14 @@ export class BrowserMain extends Disposable {
310326
})
311327
]);
312328

313-
userDataProfilesService.setEnablement(!environmentService.remoteAuthority && (productService.quality !== 'stable' || configurationService.getValue(PROFILES_ENABLEMENT_CONFIG)));
314-
this._register(configurationService.onDidChangeConfiguration(e => {
315-
if (e.affectsConfiguration(PROFILES_ENABLEMENT_CONFIG)) {
316-
userDataProfilesService.setEnablement(!!configurationService.getValue(PROFILES_ENABLEMENT_CONFIG));
317-
}
318-
}));
329+
if (isProfilesEnablementConfigured) {
330+
userDataProfilesService.setEnablement(!!configurationService.getValue(PROFILES_ENABLEMENT_CONFIG));
331+
this._register(configurationService.onDidChangeConfiguration(e => {
332+
if (e.source !== ConfigurationTarget.DEFAULT && e.affectsConfiguration(PROFILES_ENABLEMENT_CONFIG)) {
333+
window.localStorage.setItem(PROFILES_ENABLEMENT_CONFIG, !!configurationService.getValue(PROFILES_ENABLEMENT_CONFIG) ? 'true' : 'false');
334+
}
335+
}));
336+
}
319337

320338
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
321339
//

0 commit comments

Comments
 (0)