Skip to content

Commit 93aeba0

Browse files
Sandeep SomavarapuSandeep Somavarapu
authored andcommitted
stop sync when turned off
1 parent 88bf57b commit 93aeba0

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
8181
@IUserDataSyncService private readonly userDataSyncService: IUserDataSyncService,
8282
@IContextKeyService contextKeyService: IContextKeyService,
8383
@IActivityService private readonly activityService: IActivityService,
84-
@INotificationService private readonly notificationService: INotificationService
84+
@INotificationService private readonly notificationService: INotificationService,
85+
@IConfigurationService private readonly configurationService: IConfigurationService
8586
) {
8687
super();
8788
this.syncEnablementContext = CONTEXT_SYNC_STATE.bindTo(contextKeyService);
@@ -114,7 +115,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
114115
}
115116
}
116117

117-
private async sync(): Promise<void> {
118+
private async startSync(): Promise<void> {
118119
await this.userDataSyncService.sync();
119120
if (this.userDataSyncService.status === SyncStatus.HasConflicts) {
120121
const handle = this.notificationService.prompt(Severity.Warning, localize('conflicts detected', "Unable to sync due to conflicts. Please resolve them to continue."),
@@ -128,11 +129,24 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
128129
}
129130
}
130131

132+
private stopSync(): Promise<void> {
133+
return this.userDataSyncService.stopSync();
134+
}
135+
136+
private async turnOnSync(): Promise<void> {
137+
this.configurationService.updateValue('userConfiguration.autoSync', true);
138+
}
139+
140+
private async turnOffSync(): Promise<void> {
141+
this.configurationService.updateValue('userConfiguration.autoSync', false);
142+
this.stopSync();
143+
}
144+
131145
private registerActions(): void {
132146

133147
// Global Activity Actions
134148

135-
CommandsRegistry.registerCommand('workbench.userData.actions.turnOnSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userConfiguration.autoSync', true));
149+
CommandsRegistry.registerCommand('workbench.userData.actions.turnOnSync', () => this.turnOnSync());
136150
MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
137151
group: '5_sync',
138152
command: {
@@ -142,7 +156,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
142156
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.notEqualsTo(SyncStatus.Uninitialized), ContextKeyExpr.not('config.userConfiguration.autoSync')),
143157
});
144158

145-
CommandsRegistry.registerCommand('workbench.userData.actions.turnOffSync', serviceAccessor => serviceAccessor.get(IConfigurationService).updateValue('userConfiguration.autoSync', false));
159+
CommandsRegistry.registerCommand('workbench.userData.actions.turnOffSync', () => this.turnOffSync());
146160
MenuRegistry.appendMenuItem(MenuId.GlobalActivity, {
147161
group: '5_sync',
148162
command: {
@@ -175,7 +189,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
175189

176190
// Command Pallette Actions
177191

178-
CommandsRegistry.registerCommand('workbench.userData.actions.startSync', () => this.sync());
192+
CommandsRegistry.registerCommand('workbench.userData.actions.startSync', () => this.startSync());
179193
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
180194
command: {
181195
id: 'workbench.userData.actions.startSync',
@@ -184,7 +198,7 @@ class SyncContribution extends Disposable implements IWorkbenchContribution {
184198
when: ContextKeyExpr.and(CONTEXT_SYNC_STATE.isEqualTo(SyncStatus.Idle), ContextKeyExpr.not('config.userConfiguration.autoSync')),
185199
});
186200

187-
CommandsRegistry.registerCommand('workbench.userData.actions.stopSync', serviceAccessor => serviceAccessor.get(IUserDataSyncService).stopSync());
201+
CommandsRegistry.registerCommand('workbench.userData.actions.stopSync', () => this.stopSync());
188202
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
189203
command: {
190204
id: 'workbench.userData.actions.stopSync',

0 commit comments

Comments
 (0)