5
5
6
6
import { Action } from 'vs/base/common/actions' ;
7
7
import { toErrorMessage } from 'vs/base/common/errorMessage' ;
8
- import { canceled , isPromiseCanceledError } from 'vs/base/common/errors' ;
8
+ import { isPromiseCanceledError } from 'vs/base/common/errors' ;
9
9
import { Event } from 'vs/base/common/event' ;
10
10
import { Disposable , DisposableStore , dispose , MutableDisposable , toDisposable , IDisposable } from 'vs/base/common/lifecycle' ;
11
11
import { isEqual , basename } from 'vs/base/common/resources' ;
@@ -28,9 +28,9 @@ import { INotificationService, Severity } from 'vs/platform/notification/common/
28
28
import { IQuickInputService , IQuickPickItem , IQuickPickSeparator } from 'vs/platform/quickinput/common/quickInput' ;
29
29
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry' ;
30
30
import {
31
- CONTEXT_SYNC_STATE , IUserDataAutoSyncService , IUserDataSyncService , registerConfiguration ,
32
- SyncResource , SyncStatus , UserDataSyncError , UserDataSyncErrorCode , USER_DATA_SYNC_SCHEME , IUserDataSyncEnablementService , CONTEXT_SYNC_ENABLEMENT ,
33
- SyncResourceConflicts , Conflict , getSyncResourceFromLocalPreview , getSyncAreaLabel , ENABLE_SYNC_VIEWS_COMMAND_ID , CONFIGURE_SYNC_COMMAND_ID , AccountStatus , CONTEXT_ENABLE_VIEWS , SHOW_SYNC_LOG_COMMAND_ID , CONTEXT_ACCOUNT_STATE
31
+ IUserDataAutoSyncService , IUserDataSyncService , registerConfiguration ,
32
+ SyncResource , SyncStatus , UserDataSyncError , UserDataSyncErrorCode , USER_DATA_SYNC_SCHEME , IUserDataSyncEnablementService ,
33
+ SyncResourceConflicts , Conflict , getSyncResourceFromLocalPreview
34
34
} from 'vs/platform/userDataSync/common/userDataSync' ;
35
35
import { FloatingClickWidget } from 'vs/workbench/browser/parts/editor/editorWidgets' ;
36
36
import { IWorkbenchContribution } from 'vs/workbench/common/contributions' ;
@@ -48,13 +48,12 @@ import { IProductService } from 'vs/platform/product/common/productService';
48
48
import { IStorageService , StorageScope } from 'vs/platform/storage/common/storage' ;
49
49
import { IOpenerService } from 'vs/platform/opener/common/opener' ;
50
50
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService' ;
51
- import { UserDataSyncAccounts } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncAccount' ;
52
51
import { Registry } from 'vs/platform/registry/common/platform' ;
53
52
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors' ;
54
53
import { Codicon } from 'vs/base/common/codicons' ;
55
54
import { ViewContainerLocation , IViewContainersRegistry , Extensions , ViewContainer } from 'vs/workbench/common/views' ;
56
55
import { UserDataSyncViewPaneContainer , UserDataSyncDataViews } from 'vs/workbench/contrib/userDataSync/browser/userDataSyncViews' ;
57
- import { IUserDataSyncWorkbenchService } from 'vs/workbench/services/userDataSync/common/userDataSyncWorkbenchService ' ;
56
+ import { IUserDataSyncWorkbenchService , CONTEXT_ENABLE_VIEWS , getSyncAreaLabel , AccountStatus , CONTEXT_SYNC_STATE , CONTEXT_SYNC_ENABLEMENT , CONTEXT_ACCOUNT_STATE , CONFIGURE_SYNC_COMMAND_ID , ENABLE_SYNC_VIEWS_COMMAND_ID , SHOW_SYNC_LOG_COMMAND_ID } from 'vs/workbench/services/userDataSync/common/userDataSync ' ;
58
57
59
58
const CONTEXT_CONFLICTS_SOURCES = new RawContextKey < string > ( 'conflictsSources' , '' ) ;
60
59
@@ -65,10 +64,6 @@ type SyncConflictsClassification = {
65
64
action ?: { classification : 'SystemMetaData' , purpose : 'FeatureInsight' , isMeasurement : true } ;
66
65
} ;
67
66
68
- type FirstTimeSyncClassification = {
69
- action : { classification : 'SystemMetaData' , purpose : 'FeatureInsight' , isMeasurement : true } ;
70
- } ;
71
-
72
67
const turnOnSyncCommand = { id : 'workbench.userDataSync.actions.turnOn' , title : localize ( 'turn on sync with category' , "Preferences Sync: Turn On..." ) } ;
73
68
const turnOffSyncCommand = { id : 'workbench.userDataSync.actions.turnOff' , title : localize ( 'stop sync' , "Preferences Sync: Turn Off" ) } ;
74
69
const configureSyncCommand = { id : CONFIGURE_SYNC_COMMAND_ID , title : localize ( 'configure sync' , "Preferences Sync: Configure..." ) } ;
@@ -95,13 +90,9 @@ const CONTEXT_TURNING_ON_STATE = new RawContextKey<false>('userDataSyncTurningOn
95
90
export class UserDataSyncWorkbenchContribution extends Disposable implements IWorkbenchContribution {
96
91
97
92
private readonly turningOnSyncContext : IContextKey < boolean > ;
98
- private readonly syncEnablementContext : IContextKey < boolean > ;
99
- private readonly syncStatusContext : IContextKey < string > ;
100
- private readonly accountStatusContext : IContextKey < string > ;
101
93
private readonly conflictsSources : IContextKey < string > ;
102
94
private readonly viewsEnablementContext : IContextKey < boolean > ;
103
95
104
- private readonly userDataSyncAccounts : UserDataSyncAccounts ;
105
96
private readonly badgeDisposable = this . _register ( new MutableDisposable ( ) ) ;
106
97
107
98
constructor (
@@ -130,29 +121,24 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
130
121
super ( ) ;
131
122
132
123
this . turningOnSyncContext = CONTEXT_TURNING_ON_STATE . bindTo ( contextKeyService ) ;
133
- this . syncEnablementContext = CONTEXT_SYNC_ENABLEMENT . bindTo ( contextKeyService ) ;
134
- this . syncStatusContext = CONTEXT_SYNC_STATE . bindTo ( contextKeyService ) ;
135
- this . accountStatusContext = CONTEXT_ACCOUNT_STATE . bindTo ( contextKeyService ) ;
136
124
this . conflictsSources = CONTEXT_CONFLICTS_SOURCES . bindTo ( contextKeyService ) ;
137
125
this . viewsEnablementContext = CONTEXT_ENABLE_VIEWS . bindTo ( contextKeyService ) ;
138
126
139
- this . userDataSyncAccounts = instantiationService . createInstance ( UserDataSyncAccounts ) ;
140
-
141
- if ( this . userDataSyncAccounts . authenticationProviders . length ) {
127
+ if ( this . userDataSyncWorkbenchService . authenticationProviders . length ) {
142
128
registerConfiguration ( ) ;
143
129
144
- this . onDidChangeSyncStatus ( this . userDataSyncService . status ) ;
130
+ this . updateBadge ( ) ;
145
131
this . onDidChangeConflicts ( this . userDataSyncService . conflicts ) ;
146
- this . onDidChangeEnablement ( this . userDataSyncEnablementService . isEnabled ( ) ) ;
147
- this . onDidChangeAccountStatus ( this . userDataSyncAccounts . status ) ;
148
132
149
- this . _register ( Event . debounce ( userDataSyncService . onDidChangeStatus , ( ) => undefined , 500 ) ( ( ) => this . onDidChangeSyncStatus ( this . userDataSyncService . status ) ) ) ;
133
+ this . _register ( Event . any (
134
+ Event . debounce ( userDataSyncService . onDidChangeStatus , ( ) => undefined , 500 ) ,
135
+ this . userDataSyncEnablementService . onDidChangeEnablement ,
136
+ this . userDataSyncWorkbenchService . onDidChangeAccountStatus
137
+ ) ( ( ) => this . updateBadge ( ) ) ) ;
150
138
this . _register ( userDataSyncService . onDidChangeConflicts ( ( ) => this . onDidChangeConflicts ( this . userDataSyncService . conflicts ) ) ) ;
151
139
this . _register ( userDataSyncService . onSyncErrors ( errors => this . onSyncErrors ( errors ) ) ) ;
152
- this . _register ( this . userDataSyncEnablementService . onDidChangeEnablement ( enabled => this . onDidChangeEnablement ( enabled ) ) ) ;
153
140
this . _register ( userDataAutoSyncService . onError ( error => this . onAutoSyncError ( error ) ) ) ;
154
- this . _register ( this . userDataSyncAccounts . onDidChangeStatus ( status => this . onDidChangeAccountStatus ( status ) ) ) ;
155
- this . _register ( this . userDataSyncAccounts . onDidSignOut ( ( ) => this . doTurnOff ( false ) ) ) ;
141
+
156
142
this . registerActions ( ) ;
157
143
this . registerViews ( ) ;
158
144
@@ -161,16 +147,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
161
147
}
162
148
}
163
149
164
- private onDidChangeAccountStatus ( status : AccountStatus ) : void {
165
- this . accountStatusContext . set ( status ) ;
166
- this . updateBadge ( ) ;
167
- }
168
-
169
- private onDidChangeSyncStatus ( status : SyncStatus ) {
170
- this . syncStatusContext . set ( status ) ;
171
- this . updateBadge ( ) ;
172
- }
173
-
174
150
private readonly conflictsDisposables = new Map < SyncResource , IDisposable > ( ) ;
175
151
private onDidChangeConflicts ( conflicts : SyncResourceConflicts [ ] ) {
176
152
this . updateBadge ( ) ;
@@ -285,11 +261,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
285
261
}
286
262
}
287
263
288
- private onDidChangeEnablement ( enabled : boolean ) {
289
- this . syncEnablementContext . set ( enabled ) ;
290
- this . updateBadge ( ) ;
291
- }
292
-
293
264
private onAutoSyncError ( error : UserDataSyncError ) : void {
294
265
switch ( error . code ) {
295
266
case UserDataSyncErrorCode . TurnedOff :
@@ -383,7 +354,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
383
354
let clazz : string | undefined ;
384
355
let priority : number | undefined = undefined ;
385
356
386
- if ( this . userDataSyncService . status !== SyncStatus . Uninitialized && this . userDataSyncEnablementService . isEnabled ( ) && this . userDataSyncAccounts . status === AccountStatus . Unavailable ) {
357
+ if ( this . userDataSyncService . status !== SyncStatus . Uninitialized && this . userDataSyncEnablementService . isEnabled ( ) && this . userDataSyncWorkbenchService . accountStatus === AccountStatus . Unavailable ) {
387
358
badge = new NumberBadge ( 1 , ( ) => localize ( 'sign in to sync preferences' , "Sign in to Sync Preferences" ) ) ;
388
359
} else if ( this . userDataSyncService . conflicts . length ) {
389
360
badge = new NumberBadge ( this . userDataSyncService . conflicts . reduce ( ( result , syncResourceConflict ) => { return result + syncResourceConflict . conflicts . length ; } , 0 ) , ( ) => localize ( 'has conflicts' , "Preferences Sync: Conflicts Detected" ) ) ;
@@ -419,7 +390,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
419
390
if ( ! turnOn ) {
420
391
return ;
421
392
}
422
- await this . doTurnOn ( ) ;
393
+ await this . userDataSyncWorkbenchService . turnOn ( ) ;
423
394
this . storageService . store ( 'sync.donotAskPreviewConfirmation' , true , StorageScope . GLOBAL ) ;
424
395
} finally {
425
396
this . turningOnSync = false ;
@@ -454,13 +425,13 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
454
425
quickPick . title = localize ( 'Preferences Sync Title' , "Preferences Sync" ) ;
455
426
quickPick . ok = false ;
456
427
quickPick . customButton = true ;
457
- if ( this . userDataSyncAccounts . all . length ) {
428
+ if ( this . userDataSyncWorkbenchService . all . length ) {
458
429
quickPick . customLabel = localize ( 'turn on' , "Turn On" ) ;
459
430
} else {
460
431
const orTerm = localize ( { key : 'or' , comment : [ 'Here is the context where it is used - Sign in with your A or B or C account to synchronize your data across devices.' ] } , "or" ) ;
461
- const displayName = this . userDataSyncAccounts . authenticationProviders . length === 1
462
- ? this . authenticationService . getDisplayName ( this . userDataSyncAccounts . authenticationProviders [ 0 ] . id )
463
- : this . userDataSyncAccounts . authenticationProviders . map ( ( { id } ) => this . authenticationService . getDisplayName ( id ) ) . join ( ` ${ orTerm } ` ) ;
432
+ const displayName = this . userDataSyncWorkbenchService . authenticationProviders . length === 1
433
+ ? this . authenticationService . getDisplayName ( this . userDataSyncWorkbenchService . authenticationProviders [ 0 ] . id )
434
+ : this . userDataSyncWorkbenchService . authenticationProviders . map ( ( { id } ) => this . authenticationService . getDisplayName ( id ) ) . join ( ` ${ orTerm } ` ) ;
464
435
quickPick . description = localize ( 'sign in and turn on sync detail' , "Sign in with your {0} account to synchronize your data across devices." , displayName ) ;
465
436
quickPick . customLabel = localize ( 'sign in and turn on sync' , "Sign in & Turn on" ) ;
466
437
}
@@ -491,22 +462,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
491
462
} ) ;
492
463
}
493
464
494
- private async doTurnOn ( ) : Promise < void > {
495
- const picked = await this . userDataSyncAccounts . pick ( ) ;
496
- if ( ! picked ) {
497
- throw canceled ( ) ;
498
- }
499
-
500
- // User did not pick an account or login failed
501
- if ( this . userDataSyncAccounts . status !== AccountStatus . Available ) {
502
- throw new Error ( localize ( 'no account' , "No account available" ) ) ;
503
- }
504
-
505
- await this . handleFirstTimeSync ( ) ;
506
- this . userDataSyncEnablementService . setEnablement ( true ) ;
507
- this . notificationService . info ( localize ( 'sync turned on' , "Preferences sync is turned on" ) ) ;
508
- }
509
-
510
465
private getConfigureSyncQuickPickItems ( ) : ConfigureSyncQuickPickItem [ ] {
511
466
return [ {
512
467
id : SyncResource . Settings ,
@@ -563,38 +518,6 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
563
518
} ) ;
564
519
}
565
520
566
- private async handleFirstTimeSync ( ) : Promise < void > {
567
- const isFirstSyncWithMerge = await this . userDataSyncService . isFirstTimeSyncWithMerge ( ) ;
568
- if ( ! isFirstSyncWithMerge ) {
569
- return ;
570
- }
571
- const result = await this . dialogService . show (
572
- Severity . Info ,
573
- localize ( 'firs time sync' , "Sync" ) ,
574
- [
575
- localize ( 'merge' , "Merge" ) ,
576
- localize ( 'cancel' , "Cancel" ) ,
577
- localize ( 'replace' , "Replace Local" ) ,
578
- ] ,
579
- {
580
- cancelId : 1 ,
581
- detail : localize ( 'first time sync detail' , "It looks like this is the first time sync is set up.\nWould you like to merge or replace with the data from the cloud?" ) ,
582
- }
583
- ) ;
584
- switch ( result . choice ) {
585
- case 0 :
586
- this . telemetryService . publicLog2 < { action : string } , FirstTimeSyncClassification > ( 'sync/firstTimeSync' , { action : 'merge' } ) ;
587
- break ;
588
- case 1 :
589
- this . telemetryService . publicLog2 < { action : string } , FirstTimeSyncClassification > ( 'sync/firstTimeSync' , { action : 'cancelled' } ) ;
590
- throw canceled ( ) ;
591
- case 2 :
592
- this . telemetryService . publicLog2 < { action : string } , FirstTimeSyncClassification > ( 'sync/firstTimeSync' , { action : 'replace-local' } ) ;
593
- await this . userDataSyncService . pull ( ) ;
594
- break ;
595
- }
596
- }
597
-
598
521
private async turnOff ( ) : Promise < void > {
599
522
const result = await this . dialogService . confirm ( {
600
523
type : 'info' ,
@@ -606,18 +529,8 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
606
529
}
607
530
} ) ;
608
531
if ( result . confirmed ) {
609
- return this . doTurnOff ( ! ! result . checkboxChecked ) ;
610
- }
611
- }
612
-
613
- private async doTurnOff ( turnOffEveryWhere : boolean ) : Promise < void > {
614
- if ( ! this . userDataSyncEnablementService . isEnabled ( ) ) {
615
- return ;
616
- }
617
- if ( ! this . userDataSyncEnablementService . canToggleEnablement ( ) ) {
618
- return ;
532
+ return this . userDataSyncWorkbenchService . turnoff ( ! ! result . checkboxChecked ) ;
619
533
}
620
- await this . userDataSyncWorkbenchService . turnoff ( turnOffEveryWhere ) ;
621
534
}
622
535
623
536
private disableSync ( source ?: SyncResource ) : void {
@@ -786,7 +699,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
786
699
}
787
700
async run ( ) : Promise < any > {
788
701
try {
789
- await that . userDataSyncAccounts . pick ( ) ;
702
+ await that . userDataSyncWorkbenchService . pickAccount ( ) ;
790
703
} catch ( e ) {
791
704
that . notificationService . error ( e ) ;
792
705
}
@@ -943,7 +856,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
943
856
items . push ( { type : 'separator' } ) ;
944
857
items . push ( { id : syncNowCommand . id , label : syncNowCommand . title , description : syncNowCommand . description ( that . userDataSyncService ) } ) ;
945
858
if ( that . userDataSyncEnablementService . canToggleEnablement ( ) ) {
946
- const account = that . userDataSyncAccounts . current ;
859
+ const account = that . userDataSyncWorkbenchService . current ;
947
860
items . push ( { id : turnOffSyncCommand . id , label : turnOffSyncCommand . title , description : account ? `${ account . accountName } (${ that . authenticationService . getDisplayName ( account . authenticationProviderId ) } )` : undefined } ) ;
948
861
}
949
862
quickPick . items = items ;
0 commit comments