提交 67bd821c 编写于 作者: S Sandeep Somavarapu

control selecting settings service through canSwitch property

上级 f3bf1d17
......@@ -24,8 +24,9 @@ export interface IBuiltInExtension {
export type ConfigurationSyncStore = {
url: string,
insidersUrl?: string,
stableUrl?: string,
insidersUrl: string,
stableUrl: string,
canSwitch: boolean,
authenticationProviders: IStringDictionary<{ scopes: string[] }>
};
......
......@@ -120,8 +120,9 @@ export type IAuthenticationProvider = { id: string, scopes: string[] };
export interface IUserDataSyncStore {
readonly url: URI;
readonly defaultUrl: URI;
readonly stableUrl: URI | undefined;
readonly insidersUrl: URI | undefined;
readonly stableUrl: URI;
readonly insidersUrl: URI;
readonly canSwitch: boolean;
readonly authenticationProviders: IAuthenticationProvider[];
}
......
......@@ -57,15 +57,17 @@ export abstract class AbstractUserDataSyncStoreManagementService extends Disposa
const syncStore = value as ConfigurationSyncStore;
const type: UserDataSyncStoreType | undefined = this.storageService.get(SYNC_SERVICE_URL_TYPE, StorageScope.GLOBAL) as UserDataSyncStoreType | undefined;
const url = configuredStore?.url
|| (type === 'insiders' ? syncStore.insidersUrl : type === 'stable' ? syncStore.stableUrl : undefined)
|| syncStore.url;
|| type === 'insiders' ? syncStore.insidersUrl
: type === 'stable' ? syncStore.stableUrl
: syncStore.url;
return {
url: URI.parse(url),
type,
defaultType: syncStore.url === syncStore.insidersUrl ? 'insiders' : syncStore.url === syncStore.stableUrl ? 'stable' : undefined,
defaultUrl: URI.parse(syncStore.url),
stableUrl: syncStore.stableUrl ? URI.parse(syncStore.stableUrl) : undefined,
insidersUrl: syncStore.insidersUrl ? URI.parse(syncStore.insidersUrl) : undefined,
stableUrl: URI.parse(syncStore.stableUrl),
insidersUrl: URI.parse(syncStore.insidersUrl),
canSwitch: !!syncStore.canSwitch,
authenticationProviders: Object.keys(syncStore.authenticationProviders).reduce<IAuthenticationProvider[]>((result, id) => {
result.push({ id, scopes: syncStore!.authenticationProviders[id].scopes });
return result;
......@@ -110,8 +112,8 @@ export class UserDataSyncStoreManagementService extends AbstractUserDataSyncStor
}
async switch(type: UserDataSyncStoreType): Promise<void> {
if (type !== this.userDataSyncStore?.type) {
if (type === this.userDataSyncStore?.defaultType) {
if (this.userDataSyncStore?.canSwitch && type !== this.userDataSyncStore.type) {
if (type === this.userDataSyncStore.defaultType) {
this.storageService.remove(SYNC_SERVICE_URL_TYPE, StorageScope.GLOBAL);
} else {
this.storageService.store(SYNC_SERVICE_URL_TYPE, type, StorageScope.GLOBAL);
......
......@@ -69,6 +69,9 @@ export class UserDataSyncClient extends Disposable {
_serviceBrand: undefined, ...product, ...{
'configurationSync.store': {
url: this.testServer.url,
stableUrl: this.testServer.url,
insidersUrl: this.testServer.url,
canSwitch: false,
authenticationProviders: { 'test': { scopes: [] } }
}
}
......
......@@ -39,6 +39,9 @@ suite('UserDataSyncStoreManagementService', () => {
const configuredStore: ConfigurationSyncStore = {
url: 'http://configureHost:3000',
stableUrl: 'http://configureHost:3000',
insidersUrl: 'http://configureHost:3000',
canSwitch: false,
authenticationProviders: { 'configuredAuthProvider': { scopes: [] } }
};
await client.instantiationService.get(IFileService).writeFile(client.instantiationService.get(IEnvironmentService).settingsResource, VSBuffer.fromString(JSON.stringify({
......@@ -49,8 +52,9 @@ suite('UserDataSyncStoreManagementService', () => {
const expected: IUserDataSyncStore = {
url: URI.parse('http://configureHost:3000'),
defaultUrl: URI.parse('http://configureHost:3000'),
stableUrl: undefined,
insidersUrl: undefined,
stableUrl: URI.parse('http://configureHost:3000'),
insidersUrl: URI.parse('http://configureHost:3000'),
canSwitch: false,
authenticationProviders: [{ id: 'configuredAuthProvider', scopes: [] }]
};
......
......@@ -676,7 +676,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
private async switchSyncService(): Promise<void> {
const userDataSyncStore = this.userDataSyncStoreManagementService.userDataSyncStore;
if (userDataSyncStore?.insidersUrl && userDataSyncStore?.stableUrl && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
if (userDataSyncStore?.canSwitch && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
return new Promise<void>((c, e) => {
const disposables: DisposableStore = new DisposableStore();
const quickPick = disposables.add(this.quickInputService.createQuickPick<{ id: UserDataSyncStoreType, label: string, description?: string }>());
......@@ -1120,7 +1120,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
private registerSwitchSyncServiceAction(): void {
const that = this;
const userDataSyncStore = this.userDataSyncStoreManagementService.userDataSyncStore;
if (userDataSyncStore?.insidersUrl && userDataSyncStore?.stableUrl && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
if (userDataSyncStore?.canSwitch && ![userDataSyncStore.insidersUrl, userDataSyncStore.stableUrl].includes(userDataSyncStore.url)) {
this._register(registerAction2(class ShowSyncSettingsAction extends Action2 {
constructor() {
super({
......
......@@ -446,8 +446,7 @@ export class UserDataSyncWorkbenchService extends Disposable implements IUserDat
async switchSyncService(type: UserDataSyncStoreType): Promise<void> {
if (!this.userDataSyncStoreManagementService.userDataSyncStore
|| !this.userDataSyncStoreManagementService.userDataSyncStore.insidersUrl
|| !this.userDataSyncStoreManagementService.userDataSyncStore.stableUrl) {
|| !this.userDataSyncStoreManagementService.userDataSyncStore.canSwitch) {
return;
}
await this.userDataSyncStoreManagementService.switch(type);
......
......@@ -42,6 +42,7 @@ class UserDataSyncStoreManagementService extends AbstractUserDataSyncStoreManage
defaultUrl: URI.revive(userDataSyncStore.defaultUrl),
insidersUrl: URI.revive(userDataSyncStore.insidersUrl),
stableUrl: URI.revive(userDataSyncStore.stableUrl),
canSwitch: userDataSyncStore.canSwitch,
authenticationProviders: userDataSyncStore.authenticationProviders,
};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册