mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-29 09:35:38 -05:00
Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 (#7415)
* Merge from vscode f2d41726ba5a0e8abfe61b2c743022b1b6372010 * add missing files
This commit is contained in:
@@ -12,6 +12,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
||||
import { timeout } from 'vs/base/common/async';
|
||||
import { ExtensionsSynchroniser } from 'vs/platform/userDataSync/common/extensionsSync';
|
||||
import { IExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
|
||||
import { IAuthTokenService, AuthTokenStatus } from 'vs/platform/auth/common/auth';
|
||||
|
||||
export class UserDataSyncService extends Disposable implements IUserDataSyncService {
|
||||
|
||||
@@ -35,6 +36,7 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
|
||||
constructor(
|
||||
@IUserDataSyncStoreService private readonly userDataSyncStoreService: IUserDataSyncStoreService,
|
||||
@IInstantiationService private readonly instantiationService: IInstantiationService,
|
||||
@IAuthTokenService private readonly authTokenService: IAuthTokenService,
|
||||
) {
|
||||
super();
|
||||
this.settingsSynchroniser = this._register(this.instantiationService.createInstance(SettingsSynchroniser));
|
||||
@@ -43,12 +45,16 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
|
||||
this.updateStatus();
|
||||
this._register(Event.any(...this.synchronisers.map(s => Event.map(s.onDidChangeStatus, () => undefined)))(() => this.updateStatus()));
|
||||
this.onDidChangeLocal = Event.any(...this.synchronisers.map(s => s.onDidChangeLocal));
|
||||
this._register(authTokenService.onDidChangeStatus(() => this.onDidChangeAuthTokenStatus()));
|
||||
}
|
||||
|
||||
async sync(_continue?: boolean): Promise<boolean> {
|
||||
if (!this.userDataSyncStoreService.enabled) {
|
||||
throw new Error('Not enabled');
|
||||
}
|
||||
if (this.authTokenService.status === AuthTokenStatus.Inactive) {
|
||||
return Promise.reject('Not Authenticated. Please sign in to start sync.');
|
||||
}
|
||||
for (const synchroniser of this.synchronisers) {
|
||||
if (!await synchroniser.sync(_continue)) {
|
||||
return false;
|
||||
@@ -105,36 +111,51 @@ export class UserDataSyncService extends Disposable implements IUserDataSyncServ
|
||||
return null;
|
||||
}
|
||||
|
||||
private onDidChangeAuthTokenStatus(): void {
|
||||
if (this.authTokenService.status === AuthTokenStatus.Inactive) {
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class UserDataAutoSync extends Disposable {
|
||||
|
||||
private enabled: boolean = false;
|
||||
|
||||
constructor(
|
||||
@IConfigurationService private readonly configurationService: IConfigurationService,
|
||||
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
|
||||
@IUserDataSyncStoreService userDataSyncStoreService: IUserDataSyncStoreService,
|
||||
@IUserDataSyncLogService private readonly userDataSyncLogService: IUserDataSyncLogService,
|
||||
@IAuthTokenService private readonly authTokenService: IAuthTokenService,
|
||||
) {
|
||||
super();
|
||||
if (userDataSyncStoreService.enabled) {
|
||||
this.sync(true);
|
||||
this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('configurationSync.enable'))(() => {
|
||||
if (this.isSyncEnabled()) {
|
||||
userDataSyncLogService.info('Syncing configuration started...');
|
||||
this.sync(true);
|
||||
} else {
|
||||
this.userDataSyncService.stop();
|
||||
userDataSyncLogService.info('Syncing configuration stopped.');
|
||||
}
|
||||
}));
|
||||
this.updateEnablement();
|
||||
this.sync(true);
|
||||
this._register(Event.any<any>(authTokenService.onDidChangeStatus, userDataSyncService.onDidChangeStatus)(() => this.updateEnablement()));
|
||||
this._register(Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('configurationSync.enable'))(() => this.updateEnablement()));
|
||||
|
||||
// Sync immediately if there is a local change.
|
||||
this._register(Event.debounce(this.userDataSyncService.onDidChangeLocal, () => undefined, 500)(() => this.sync(false)));
|
||||
// Sync immediately if there is a local change.
|
||||
this._register(Event.debounce(this.userDataSyncService.onDidChangeLocal, () => undefined, 500)(() => this.sync(false)));
|
||||
}
|
||||
|
||||
private updateEnablement(): void {
|
||||
const enabled = this.isSyncEnabled();
|
||||
if (this.enabled !== enabled) {
|
||||
this.enabled = enabled;
|
||||
if (this.enabled) {
|
||||
this.userDataSyncLogService.info('Syncing configuration started');
|
||||
this.sync(true);
|
||||
} else {
|
||||
this.userDataSyncService.stop();
|
||||
this.userDataSyncLogService.info('Syncing configuration stopped.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async sync(loop: boolean): Promise<void> {
|
||||
if (this.isSyncEnabled()) {
|
||||
if (this.enabled) {
|
||||
try {
|
||||
await this.userDataSyncService.sync();
|
||||
} catch (e) {
|
||||
@@ -148,7 +169,9 @@ export class UserDataAutoSync extends Disposable {
|
||||
}
|
||||
|
||||
private isSyncEnabled(): boolean {
|
||||
return this.configurationService.getValue<boolean>('configurationSync.enable');
|
||||
return this.configurationService.getValue<boolean>('configurationSync.enable')
|
||||
&& this.userDataSyncService.status !== SyncStatus.Uninitialized
|
||||
&& this.authTokenService.status !== AuthTokenStatus.Inactive;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user