Skip to content

Commit

Permalink
fix auto sync
Browse files Browse the repository at this point in the history
  • Loading branch information
sandy081 committed Sep 11, 2019
1 parent e3bfd2c commit 7e961eb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/vs/workbench/contrib/userData/common/userData.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration)
properties: {
'userConfiguration.autoSync': {
type: 'boolean',
description: localize('userData.autoSync', "When enabled, automatically synchronises User Configuration: Settings, Keybindings, Extensions & Snippets."),
description: localize('userConfiguration.autoSync', "When enabled, automatically synchronises User Configuration: Settings, Keybindings, Extensions & Snippets."),
default: false,
scope: ConfigurationScope.APPLICATION
}
Expand All @@ -45,6 +45,11 @@ class AutoSyncUserData extends Disposable implements IWorkbenchContribution {
) {
super();
this.loopAutoSync();
this._register(this.configurationService.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('userConfiguration.autoSync') && this.configurationService.getValue<boolean>('userConfiguration.autoSync')) {
this.autoSync();
}
}));
}

private loopAutoSync(): void {
Expand All @@ -54,7 +59,7 @@ class AutoSyncUserData extends Disposable implements IWorkbenchContribution {
}

private autoSync(): Promise<any> {
if (this.userDataSyncService.status === SyncStatus.Idle && this.configurationService.getValue<boolean>('userData.autoSync')) {
if (this.userDataSyncService.status === SyncStatus.Idle && this.configurationService.getValue<boolean>('userConfiguration.autoSync')) {
return this.userDataSyncService.sync();
}
return Promise.resolve();
Expand Down Expand Up @@ -104,24 +109,24 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {

// Global Activity Actions

CommandsRegistry.registerCommand('workbench.userData.actions.turnOnSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userData.autoSync', true));
CommandsRegistry.registerCommand('workbench.userData.actions.turnOnAutoSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userConfiguration.autoSync', true));
MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
group: '5_sync',
command: {
id: 'workbench.userData.actions.turnOnAutoSync',
title: localize('turn on auto sync', "Sync: Turn On")
},
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), ContextKeyExpr.not('config.userData.autoSync')),
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), ContextKeyExpr.not('config.userConfiguration.autoSync')),
});

CommandsRegistry.registerCommand('workbench.userData.actions.turnOffSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userData.autoSync', false));
CommandsRegistry.registerCommand('workbench.userData.actions.turnOffSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userConfiguration.autoSync', false));
MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
group: '5_sync',
command: {
id: 'workbench.userData.actions.turnOffAutoSync',
title: localize('turn off auto sync', "Sync: Turn Off")
},
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), ContextKeyExpr.has('config.userData.autoSync')),
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), ContextKeyExpr.has('config.userConfiguration.autoSync')),
});

CommandsRegistry.registerCommand('sync.resolveConflicts', serviceAccessor => serviceAccessor.get(IUserDataSyncService).resolveConflicts());
Expand Down Expand Up @@ -153,7 +158,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
id: 'workbench.userData.actions.startSync',
title: localize('start sync', "Sync: Start")
},
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.isEqualTo(SyncStatus.Idle), ContextKeyExpr.not('config.userData.autoSync')),
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.isEqualTo(SyncStatus.Idle), ContextKeyExpr.not('config.userConfiguration.autoSync')),
});
}
}
Expand Down

0 comments on commit 7e961eb

Please sign in to comment.