@@ -106,8 +106,6 @@ const CONTEXT_ACCOUNT_STATE = new RawContextKey<string>('userDataSyncAccountStat
106106
107107export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {
108108
109- private static TURNING_ON_SYNC_KEY = 'userDataSync.turningOn' ;
110-
111109 private readonly turningOnSyncContext : IContextKey < boolean > ;
112110 private readonly syncEnablementContext : IContextKey < boolean > ;
113111 private readonly syncStatusContext : IContextKey < string > ;
@@ -152,13 +150,11 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
152150 if ( this . userDataSyncAccounts . authenticationProviders . length ) {
153151 registerConfiguration ( ) ;
154152
155- this . onDidChangeTurningOnState ( ) ;
156153 this . onDidChangeSyncStatus ( this . userDataSyncService . status ) ;
157154 this . onDidChangeConflicts ( this . userDataSyncService . conflicts ) ;
158155 this . onDidChangeEnablement ( this . userDataSyncEnablementService . isEnabled ( ) ) ;
159156 this . onDidChangeAccountStatus ( this . userDataSyncAccounts . status ) ;
160157
161- this . _register ( Event . filter ( storageService . onDidChangeStorage , e => e . scope === StorageScope . GLOBAL && e . key === UserDataSyncWorkbenchContribution . TURNING_ON_SYNC_KEY ) ( ( ) => this . onDidChangeTurningOnState ( ) ) ) ;
162158 this . _register ( Event . debounce ( userDataSyncService . onDidChangeStatus , ( ) => undefined , 500 ) ( ( ) => this . onDidChangeSyncStatus ( this . userDataSyncService . status ) ) ) ;
163159 this . _register ( userDataSyncService . onDidChangeConflicts ( ( ) => this . onDidChangeConflicts ( this . userDataSyncService . conflicts ) ) ) ;
164160 this . _register ( userDataSyncService . onSyncErrors ( errors => this . onSyncErrors ( errors ) ) ) ;
@@ -177,11 +173,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
177173 }
178174 }
179175
180- private onDidChangeTurningOnState ( ) : void {
181- this . turningOnSyncContext . set ( this . storageService . getBoolean ( UserDataSyncWorkbenchContribution . TURNING_ON_SYNC_KEY , StorageScope . GLOBAL , false ) ) ;
182- this . updateBadge ( ) ;
183- }
184-
185176 private onDidChangeAccountStatus ( status : AccountStatus ) : void {
186177 this . accountStatusContext . set ( status ) ;
187178 this . updateBadge ( ) ;
@@ -402,7 +393,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
402393 badge = new NumberBadge ( 1 , ( ) => localize ( 'sign in to sync preferences' , "Sign in to Sync Preferences" ) ) ;
403394 } else if ( this . userDataSyncService . conflicts . length ) {
404395 badge = new NumberBadge ( this . userDataSyncService . conflicts . reduce ( ( result , syncResourceConflict ) => { return result + syncResourceConflict . conflicts . length ; } , 0 ) , ( ) => localize ( 'has conflicts' , "Preferences Sync: Conflicts Detected" ) ) ;
405- } else if ( this . turningOnSyncContext . get ( ) ) {
396+ } else if ( this . turningOnSync ) {
406397 badge = new ProgressBadge ( ( ) => localize ( 'turning on syncing' , "Turning on Preferences Sync..." ) ) ;
407398 clazz = 'progress-badge' ;
408399 priority = 1 ;
@@ -413,8 +404,17 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
413404 }
414405 }
415406
407+ private get turningOnSync ( ) : boolean {
408+ return ! ! this . turningOnSyncContext . get ( ) ;
409+ }
410+
411+ private set turningOnSync ( turningOn : boolean ) {
412+ this . turningOnSyncContext . set ( turningOn ) ;
413+ this . updateBadge ( ) ;
414+ }
415+
416416 private async turnOn ( ) : Promise < void > {
417- this . storageService . store ( UserDataSyncWorkbenchContribution . TURNING_ON_SYNC_KEY , true , StorageScope . GLOBAL ) ;
417+ this . turningOnSync = true ;
418418 try {
419419 if ( ! this . storageService . getBoolean ( 'sync.donotAskPreviewConfirmation' , StorageScope . GLOBAL , false ) ) {
420420 if ( ! await this . askForConfirmation ( ) ) {
@@ -428,7 +428,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
428428 await this . doTurnOn ( ) ;
429429 this . storageService . store ( 'sync.donotAskPreviewConfirmation' , true , StorageScope . GLOBAL ) ;
430430 } finally {
431- this . storageService . store ( UserDataSyncWorkbenchContribution . TURNING_ON_SYNC_KEY , false , StorageScope . GLOBAL ) ;
431+ this . turningOnSync = false ;
432432 }
433433 }
434434
0 commit comments