Skip to content

Commit 874d2fc

Browse files
committed
sketch user data sync store service with log in
1 parent c9258e8 commit 874d2fc

7 files changed

Lines changed: 62 additions & 78 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface IProductConfiguration {
103103

104104
readonly msftInternalDomains?: string[];
105105
readonly linkProtectionTrustedDomains?: readonly string[];
106+
readonly settingsSyncStoreUrl?: string;
106107
}
107108

108109
export interface IExeBasedExtensionTip {

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,6 @@ export enum UserDataSyncStoreErrorCode {
1717
Unknown = 'Unknown'
1818
}
1919

20-
export function markAsUserDataSyncStoreError(error: Error, code: UserDataSyncStoreErrorCode): Error {
21-
error.name = code ? `${code} (UserDataSyncStoreError)` : `UserDataSyncStoreError`;
22-
23-
return error;
24-
}
25-
26-
export function toUserDataSyncStoreErrorCode(error: Error | undefined | null): UserDataSyncStoreErrorCode {
27-
28-
// Guard against abuse
29-
if (!error) {
30-
return UserDataSyncStoreErrorCode.Unknown;
31-
}
32-
33-
// FileSystemProviderError comes with the code
34-
if (error instanceof UserDataSyncStoreError) {
35-
return error.code;
36-
}
37-
38-
// Any other error, check for name match by assuming that the error
39-
// went through the markAsUserDataSyncStoreError() method
40-
const match = /^(.+) \(UserDataSyncStoreError\)$/.exec(error.name);
41-
if (!match) {
42-
return UserDataSyncStoreErrorCode.Unknown;
43-
}
44-
45-
switch (match[1]) {
46-
case UserDataSyncStoreErrorCode.Rejected: return UserDataSyncStoreErrorCode.Rejected;
47-
}
48-
49-
return UserDataSyncStoreErrorCode.Unknown;
50-
}
51-
5220
export class UserDataSyncStoreError extends Error {
5321

5422
constructor(message: string, public readonly code: UserDataSyncStoreErrorCode) {
@@ -57,23 +25,17 @@ export class UserDataSyncStoreError extends Error {
5725

5826
}
5927

60-
export interface IUserDataSyncStore {
61-
readonly id: string;
62-
readonly name: string;
63-
read(key: string): Promise<IUserData | null>;
64-
write(key: string, content: string, ref: string | null): Promise<string>;
65-
}
66-
6728
export const IUserDataSyncStoreService = createDecorator<IUserDataSyncStoreService>('IUserDataSyncStoreService');
6829

6930
export interface IUserDataSyncStoreService {
7031
_serviceBrand: undefined;
7132

72-
readonly onDidChangeEnablement: Event<boolean>;
7333
readonly enabled: boolean;
7434

75-
registerUserDataSyncStore(userDataSyncStore: IUserDataSyncStore): void;
76-
deregisterUserDataSyncStore(): void;
35+
readonly loggedIn: boolean;
36+
readonly onDidChangeLoggedIn: Event<boolean>;
37+
login(): Promise<void>;
38+
logout(): Promise<void>;
7739

7840
read(key: string): Promise<IUserData | null>;
7941
write(key: string, content: string, ref: string | null): Promise<string>;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
3232
this.instantiationService.createInstance(SettingsSynchroniser)
3333
];
3434
this.updateStatus();
35-
this._register(Event.any(this.userDataSyncStoreService.onDidChangeEnablement, ...this.synchronisers.map(s => Event.map(s.onDidChangeStatus, () => undefined)))(() => this.updateStatus()));
35+
this._register(Event.any(...this.synchronisers.map(s => Event.map(s.onDidChangeStatus, () => undefined)))(() => this.updateStatus()));
3636
this.onDidChangeLocal = Event.any(...this.synchronisers.map(s => s.onDidChangeLocal));
3737
}
3838

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

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,45 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Disposable, } from 'vs/base/common/lifecycle';
7+
import { IUserData, IUserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSync';
8+
import { IProductService } from 'vs/platform/product/common/productService';
79
import { Emitter, Event } from 'vs/base/common/event';
8-
import { IUserDataSyncStore, IUserData, UserDataSyncStoreError, toUserDataSyncStoreErrorCode, IUserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSync';
9-
import { ILogService } from 'vs/platform/log/common/log';
1010

1111
export class UserDataSyncStoreService extends Disposable implements IUserDataSyncStoreService {
1212

1313
_serviceBrand: any;
1414

15-
private userDataSyncStore: IUserDataSyncStore | null = null;
15+
get enabled(): boolean { return !!this.productService.settingsSyncStoreUrl; }
1616

17-
get enabled(): boolean { return !!this.userDataSyncStore; }
18-
private readonly _onDidChangeEnablement: Emitter<boolean> = this._register(new Emitter<boolean>());
19-
readonly onDidChangeEnablement: Event<boolean> = this._onDidChangeEnablement.event;
17+
private _loggedIn: boolean = false;
18+
get loggedIn(): boolean { return this._loggedIn; }
19+
private readonly _onDidChangeLoggedIn: Emitter<boolean> = this._register(new Emitter<boolean>());
20+
readonly onDidChangeLoggedIn: Event<boolean> = this._onDidChangeLoggedIn.event;
2021

2122
constructor(
22-
@ILogService private logService: ILogService
23+
@IProductService private readonly productService: IProductService,
2324
) {
2425
super();
2526
}
2627

27-
registerUserDataSyncStore(userDataSyncStore: IUserDataSyncStore): void {
28-
if (this.userDataSyncStore) {
29-
this.logService.warn(`A user data sync store '${this.userDataSyncStore.name}' already registered. Hence ignoring the newly registered '${userDataSyncStore.name}' store.`);
30-
return;
31-
}
32-
this.userDataSyncStore = userDataSyncStore;
33-
this._onDidChangeEnablement.fire(true);
28+
async login(): Promise<void> {
3429
}
3530

36-
deregisterUserDataSyncStore(): void {
37-
this.userDataSyncStore = null;
38-
this._onDidChangeEnablement.fire(false);
31+
async logout(): Promise<void> {
3932
}
4033

41-
read(key: string): Promise<IUserData | null> {
42-
if (!this.userDataSyncStore) {
43-
throw new Error('No user sync store exists.');
34+
async read(key: string): Promise<IUserData | null> {
35+
if (!this.enabled) {
36+
return Promise.reject(new Error('No settings sync store url configured.'));
4437
}
45-
return this.userDataSyncStore.read(key)
46-
.then(null, error => Promise.reject(new UserDataSyncStoreError(error.message, toUserDataSyncStoreErrorCode(error))));
38+
return null;
4739
}
4840

49-
write(key: string, content: string, ref: string | null): Promise<string> {
50-
if (!this.userDataSyncStore) {
51-
throw new Error('No user sync store exists.');
41+
async write(key: string, content: string, ref: string | null): Promise<string> {
42+
if (!this.enabled) {
43+
return Promise.reject(new Error('No settings sync store url configured.'));
5244
}
53-
return this.userDataSyncStore.write(key, content, ref)
54-
.then(null, error => Promise.reject(new UserDataSyncStoreError(error.message, toUserDataSyncStoreErrorCode(error))));
45+
return '';
5546
}
5647

5748
}

src/vs/workbench/api/common/extHostTypes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { generateUuid } from 'vs/base/common/uuid';
1414
import * as vscode from 'vscode';
1515
import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/platform/files/common/files';
1616
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
17-
import { UserDataSyncStoreErrorCode, markAsUserDataSyncStoreError } from 'vs/platform/userDataSync/common/userDataSync';
17+
import { UserDataSyncStoreErrorCode } from 'vs/platform/userDataSync/common/userDataSync';
18+
import { markAsUserDataSyncStoreError } from 'vs/workbench/services/userDataSync/common/userDataSyncStores';
1819

1920
function es5ClassCompat(target: Function): any {
2021
///@ts-ignore

src/vs/workbench/contrib/userData/browser/userData.contribution.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from 'vs/workbench/common/contributions';
7-
import { IUserDataSyncService, SyncStatus, USER_DATA_PREVIEW_SCHEME, IUserDataSyncStoreService } from 'vs/platform/userDataSync/common/userDataSync';
7+
import { IUserDataSyncService, SyncStatus, USER_DATA_PREVIEW_SCHEME } from 'vs/platform/userDataSync/common/userDataSync';
88
import { localize } from 'vs/nls';
99
import { Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
1010
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
@@ -52,22 +52,19 @@ class UserDataSyncContribution extends Disposable implements IWorkbenchContribut
5252
@IFileService fileService: IFileService,
5353
@IConfigurationService private readonly configurationService: IConfigurationService,
5454
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
55-
@IUserDataSyncStoreService private readonly userDataSyncStoreService: IUserDataSyncStoreService,
5655
) {
5756
super();
5857
this._register(fileService.registerProvider(USER_DATA_PREVIEW_SCHEME, new InMemoryFileSystemProvider()));
5958
this.sync(true);
60-
this._register(Event.any<any>(
61-
Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('userConfiguration.enableSync') && this.configurationService.getValue<boolean>('userConfiguration.enableSync')),
62-
this.userDataSyncStoreService.onDidChangeEnablement)
59+
this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('userConfiguration.enableSync') && this.configurationService.getValue<boolean>('userConfiguration.enableSync'))
6360
(() => this.sync(true)));
6461

6562
// Sync immediately if there is a local change.
6663
this._register(Event.debounce(this.userDataSyncService.onDidChangeLocal, () => undefined, 500)(() => this.sync(false)));
6764
}
6865

6966
private async sync(loop: boolean): Promise<void> {
70-
if (this.configurationService.getValue<boolean>('userConfiguration.enableSync') && this.userDataSyncStoreService.enabled) {
67+
if (this.configurationService.getValue<boolean>('userConfiguration.enableSync')) {
7168
try {
7269
await this.userDataSyncService.sync();
7370
} catch (e) {

src/vs/workbench/services/userDataSync/common/userDataSyncStores.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,43 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { Event, Emitter } from 'vs/base/common/event';
7-
import { IUserData } from 'vs/platform/userDataSync/common/userDataSync';
7+
import { IUserData, UserDataSyncStoreErrorCode, UserDataSyncStoreError } from 'vs/platform/userDataSync/common/userDataSync';
88
import { Disposable } from 'vs/base/common/lifecycle';
99
import { values } from 'vs/base/common/map';
1010
import { Registry } from 'vs/platform/registry/common/platform';
1111

12+
export function markAsUserDataSyncStoreError(error: Error, code: UserDataSyncStoreErrorCode): Error {
13+
error.name = code ? `${code} (UserDataSyncStoreError)` : `UserDataSyncStoreError`;
14+
15+
return error;
16+
}
17+
18+
export function toUserDataSyncStoreErrorCode(error: Error | undefined | null): UserDataSyncStoreErrorCode {
19+
20+
// Guard against abuse
21+
if (!error) {
22+
return UserDataSyncStoreErrorCode.Unknown;
23+
}
24+
25+
// FileSystemProviderError comes with the code
26+
if (error instanceof UserDataSyncStoreError) {
27+
return error.code;
28+
}
29+
30+
// Any other error, check for name match by assuming that the error
31+
// went through the markAsUserDataSyncStoreError() method
32+
const match = /^(.+) \(UserDataSyncStoreError\)$/.exec(error.name);
33+
if (!match) {
34+
return UserDataSyncStoreErrorCode.Unknown;
35+
}
36+
37+
switch (match[1]) {
38+
case UserDataSyncStoreErrorCode.Rejected: return UserDataSyncStoreErrorCode.Rejected;
39+
}
40+
41+
return UserDataSyncStoreErrorCode.Unknown;
42+
}
43+
1244
export interface IUserDataSyncStore {
1345
readonly id: string;
1446
readonly name: string;

0 commit comments

Comments
 (0)