Skip to content

Commit 5d40163

Browse files
committed
Improve continuous sync
1 parent 3aba6f7 commit 5d40163

2 files changed

Lines changed: 35 additions & 30 deletions

File tree

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

Lines changed: 13 additions & 15 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 } from 'vs/workbench/services/userData/common/userData';
7+
import { IUserDataSyncService, SyncStatus, USER_DATA_PREVIEW_SCHEME, IRemoteUserDataService } from 'vs/workbench/services/userData/common/userData';
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';
@@ -37,7 +37,7 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
3737
'userConfiguration.enableSync': {
3838
type: 'boolean',
3939
description: localize('userConfiguration.enableSync', "When enabled, synchronises User Configuration: Settings, Keybindings, Extensions & Snippets."),
40-
default: false,
40+
default: true,
4141
scope: ConfigurationScope.APPLICATION
4242
}
4343
}
@@ -48,25 +48,23 @@ class UserDataSyncContribution extends Disposable implements IWorkbenchContribut
4848
constructor(
4949
@IConfigurationService private readonly configurationService: IConfigurationService,
5050
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
51+
@IRemoteUserDataService private readonly remoteUserDataService: IRemoteUserDataService,
5152
) {
5253
super();
5354
this.loopSync();
54-
this._register(Event.filter(this.configurationService.onDidChangeConfiguration,
55-
e => e.affectsConfiguration('userConfiguration.enableSync') && this.configurationService.getValue<boolean>('userConfiguration.enableSync'))
56-
(() => this.sync()));
55+
this._register(Event.any<any>(
56+
Event.filter(this.configurationService.onDidChangeConfiguration, e => e.affectsConfiguration('userConfiguration.enableSync') && this.configurationService.getValue<boolean>('userConfiguration.enableSync')),
57+
this.remoteUserDataService.onDidChangeEnablement)
58+
(() => this.loopSync()));
5759
}
5860

5961
private loopSync(): void {
60-
this.sync()
61-
.then(() => timeout(500))
62-
.then(() => this.loopSync());
63-
}
64-
65-
private sync(): Promise<any> {
66-
if (this.userDataSyncService.status === SyncStatus.Idle && this.configurationService.getValue<boolean>('userConfiguration.enableSync')) {
67-
return this.userDataSyncService.sync();
62+
if (this.configurationService.getValue<boolean>('userConfiguration.enableSync') && this.remoteUserDataService.isEnabled()) {
63+
this.userDataSyncService.sync()
64+
.then(null, () => null) // Surpress errors
65+
.then(() => timeout(500))
66+
.then(() => this.loopSync());
6867
}
69-
return Promise.resolve();
7068
}
7169

7270
}
@@ -91,7 +89,7 @@ class SyncActionsContribution extends Disposable implements IWorkbenchContributi
9189
super();
9290
this.syncEnablementContext = CONTEXT_SYNC_STATE.bindTo(contextKeyService);
9391
this.onDidChangeStatus(userDataSyncService.status);
94-
this._register(userDataSyncService.onDidChangeStatus(status => this.onDidChangeStatus(status)));
92+
this._register(Event.debounce(userDataSyncService.onDidChangeStatus, () => undefined, 500)(status => this.onDidChangeStatus(userDataSyncService.status)));
9593
this.registerActions();
9694
}
9795

src/vs/workbench/services/userData/common/settingsSync.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,31 @@ export class SettingsSynchroniser extends Disposable implements ISynchroniser {
139139
if (!this.syncPreviewResultPromise) {
140140
return;
141141
}
142+
142143
const result = await this.syncPreviewResultPromise;
143-
let remoteUserData = result.remoteUserData;
144-
const settingsPreivew = await this.fileService.readFile(SETTINGS_PREVIEW_RESOURCE);
145-
const content = settingsPreivew.value.toString();
144+
if (await this.fileService.exists(SETTINGS_PREVIEW_RESOURCE)) {
146145

147-
if (this.hasErrors(content)) {
148-
return Promise.reject(localize('errorInvalidSettings', "Unable to sync settings. Please resolve conflicts without any errors/warnings and try again."));
149-
}
150-
if (result.hasRemoteChanged) {
151-
const ref = await this.writeToRemote(content, remoteUserData ? remoteUserData.ref : null);
152-
remoteUserData = { ref, content };
153-
}
154-
if (result.hasLocalChanged) {
155-
await this.writeToLocal(content, result.fileContent);
156-
}
157-
if (remoteUserData) {
158-
this.updateLastSyncValue(remoteUserData);
146+
const settingsPreivew = await this.fileService.readFile(SETTINGS_PREVIEW_RESOURCE);
147+
const content = settingsPreivew.value.toString();
148+
if (this.hasErrors(content)) {
149+
return Promise.reject(localize('errorInvalidSettings', "Unable to sync settings. Please resolve conflicts without any errors/warnings and try again."));
150+
}
151+
152+
let remoteUserData = result.remoteUserData;
153+
if (result.hasRemoteChanged) {
154+
const ref = await this.writeToRemote(content, remoteUserData ? remoteUserData.ref : null);
155+
remoteUserData = { ref, content };
156+
}
157+
158+
if (result.hasLocalChanged) {
159+
await this.writeToLocal(content, result.fileContent);
160+
}
161+
162+
if (remoteUserData) {
163+
this.updateLastSyncValue(remoteUserData);
164+
}
159165
}
166+
160167
this.syncPreviewResultPromise = null;
161168
this.setStatus(SyncStatus.Idle);
162169
}

0 commit comments

Comments
 (0)