Skip to content

Commit 67bd821

Browse files
committed
control selecting settings service through canSwitch property
1 parent f3bf1d1 commit 67bd821

8 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/vs/platform/product/common/productService.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ export interface IBuiltInExtension {
2424

2525
export type ConfigurationSyncStore = {
2626
url: string,
27-
insidersUrl?: string,
28-
stableUrl?: string,
27+
insidersUrl: string,
28+
stableUrl: string,
29+
canSwitch: boolean,
2930
authenticationProviders: IStringDictionary<{ scopes: string[] }>
3031
};
3132

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ export type IAuthenticationProvider = { id: string, scopes: string[] };
120120
export interface IUserDataSyncStore {
121121
readonly url: URI;
122122
readonly defaultUrl: URI;
123-
readonly stableUrl: URI | undefined;
124-
readonly insidersUrl: URI | undefined;
123+
readonly stableUrl: URI;
124+
readonly insidersUrl: URI;
125+
readonly canSwitch: boolean;
125126
readonly authenticationProviders: IAuthenticationProvider[];
126127
}
127128

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ export abstract class AbstractUserDataSyncStoreManagementService extends Disposa
5757
const syncStore = value as ConfigurationSyncStore;
5858
const type: UserDataSyncStoreType | undefined = this.storageService.get(SYNC_SERVICE_URL_TYPE, StorageScope.GLOBAL) as UserDataSyncStoreType | undefined;
5959
const url = configuredStore?.url
60-
|| (type === 'insiders' ? syncStore.insidersUrl : type === 'stable' ? syncStore.stableUrl : undefined)
61-
|| syncStore.url;
60+
|| type === 'insiders' ? syncStore.insidersUrl
61+
: type === 'stable' ? syncStore.stableUrl
62+
: syncStore.url;
6263
return {
6364
url: URI.parse(url),
6465
type,
6566
defaultType: syncStore.url === syncStore.insidersUrl ? 'insiders' : syncStore.url === syncStore.stableUrl ? 'stable' : undefined,
6667
defaultUrl: URI.parse(syncStore.url),
67-
stableUrl: syncStore.stableUrl ? URI.parse(syncStore.stableUrl) : undefined,
68-
insidersUrl: syncStore.insidersUrl ? URI.parse(syncStore.insidersUrl) : undefined,
68+
stableUrl: URI.parse(syncStore.stableUrl),
69+
insidersUrl: URI.parse(syncStore.insidersUrl),
70+
canSwitch: !!syncStore.canSwitch,
6971
authenticationProviders: Object.keys(syncStore.authenticationProviders).reduce<IAuthenticationProvider[]>((result, id) => {
7072
result.push({ id, scopes: syncStore!.authenticationProviders[id].scopes });
7173
return result;
@@ -110,8 +112,8 @@ export class UserDataSyncStoreManagementService extends AbstractUserDataSyncStor
110112
}
111113

112114
async switch(type: UserDataSyncStoreType): Promise<void> {
113-
if (type !== this.userDataSyncStore?.type) {
114-
if (type === this.userDataSyncStore?.defaultType) {
115+
if (this.userDataSyncStore?.canSwitch && type !== this.userDataSyncStore.type) {
116+
if (type === this.userDataSyncStore.defaultType) {
115117
this.storageService.remove(SYNC_SERVICE_URL_TYPE, StorageScope.GLOBAL);
116118
} else {
117119
this.storageService.store(SYNC_SERVICE_URL_TYPE, type, StorageScope.GLOBAL);

src/vs/platform/userDataSync/test/common/userDataSyncClient.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ export class UserDataSyncClient extends Disposable {
6969
_serviceBrand: undefined, ...product, ...{
7070
'configurationSync.store': {
7171
url: this.testServer.url,
72+
stableUrl: this.testServer.url,
73+
insidersUrl: this.testServer.url,
74+
canSwitch: false,
7275
authenticationProviders: { 'test': { scopes: [] } }
7376
}
7477
}

src/vs/platform/userDataSync/test/common/userDataSyncStoreService.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ suite('UserDataSyncStoreManagementService', () => {
3939

4040
const configuredStore: ConfigurationSyncStore = {
4141
url: 'http://configureHost:3000',
42+
stableUrl: 'http://configureHost:3000',
43+
insidersUrl: 'http://configureHost:3000',
44+
canSwitch: false,
4245
authenticationProviders: { 'configuredAuthProvider': { scopes: [] } }
4346
};
4447
await client.instantiationService.get(IFileService).writeFile(client.instantiationService.get(IEnvironmentService).settingsResource, VSBuffer.fromString(JSON.stringify({
@@ -49,8 +52,9 @@ suite('UserDataSyncStoreManagementService', () => {
4952
const expected: IUserDataSyncStore = {
5053
url: URI.parse('http://configureHost:3000'),
5154
defaultUrl: URI.parse('http://configureHost:3000'),
52-
stableUrl: undefined,
53-
insidersUrl: undefined,
55+
stableUrl: URI.parse('http://configureHost:3000'),
56+
insidersUrl: URI.parse('http://configureHost:3000'),
57+
canSwitch: false,
5458
authenticationProviders: [{ id: 'configuredAuthProvider', scopes: [] }]
5559
};
5660

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
676676

677677
private async switchSyncService(): Promise<void> {
678678
const userDataSyncStore = this.userDataSyncStoreManagementService.userDataSyncStore;
679-
if (userDataSyncStore?.insidersUrl && userDataSyncStore?.stableUrl && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
679+
if (userDataSyncStore?.canSwitch && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
680680
return new Promise<void>((c, e) => {
681681
const disposables: DisposableStore = new DisposableStore();
682682
const quickPick = disposables.add(this.quickInputService.createQuickPick<{ id: UserDataSyncStoreType, label: string, description?: string }>());
@@ -1120,7 +1120,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
11201120
private registerSwitchSyncServiceAction(): void {
11211121
const that = this;
11221122
const userDataSyncStore = this.userDataSyncStoreManagementService.userDataSyncStore;
1123-
if (userDataSyncStore?.insidersUrl && userDataSyncStore?.stableUrl && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
1123+
if (userDataSyncStore?.canSwitch && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
11241124
this._register(registerAction2(class ShowSyncSettingsAction extends Action2 {
11251125
constructor() {
11261126
super({

src/vs/workbench/services/userDataSync/browser/userDataSyncWorkbenchService.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
446446

447447
async switchSyncService(type: UserDataSyncStoreType): Promise<void> {
448448
if (!this.userDataSyncStoreManagementService.userDataSyncStore
449-
|| !this.userDataSyncStoreManagementService.userDataSyncStore.insidersUrl
450-
|| !this.userDataSyncStoreManagementService.userDataSyncStore.stableUrl) {
449+
|| !this.userDataSyncStoreManagementService.userDataSyncStore.canSwitch) {
451450
return;
452451
}
453452
await this.userDataSyncStoreManagementService.switch(type);

src/vs/workbench/services/userDataSync/electron-browser/userDataSyncStoreManagementService.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class UserDataSyncStoreManagementService extends AbstractUserDataSyncStoreManage
4242
defaultUrl: URI.revive(userDataSyncStore.defaultUrl),
4343
insidersUrl: URI.revive(userDataSyncStore.insidersUrl),
4444
stableUrl: URI.revive(userDataSyncStore.stableUrl),
45+
canSwitch: userDataSyncStore.canSwitch,
4546
authenticationProviders: userDataSyncStore.authenticationProviders,
4647
};
4748
}

0 commit comments

Comments
 (0)