@@ -13,10 +13,7 @@ import { isPromiseCanceledError } from 'vs/base/common/errors';
1313import { CancellationToken } from 'vs/base/common/cancellation' ;
1414import { IStorageService , StorageScope , IWorkspaceStorageChangeEvent } from 'vs/platform/storage/common/storage' ;
1515import { IEnvironmentService } from 'vs/platform/environment/common/environment' ;
16- import { IUserDataSyncMachine , IUserDataSyncMachinesService } from 'vs/platform/userDataSync/common/userDataSyncMachines' ;
17- import { PlatformToString , isWeb , Platform , platform } from 'vs/base/common/platform' ;
18- import { escapeRegExpCharacters } from 'vs/base/common/strings' ;
19- import { IProductService } from 'vs/platform/product/common/productService' ;
16+ import { IUserDataSyncMachinesService } from 'vs/platform/userDataSync/common/userDataSyncMachines' ;
2017import { localize } from 'vs/nls' ;
2118
2219type AutoSyncClassification = {
@@ -33,7 +30,7 @@ type AutoSyncErrorClassification = {
3330
3431const enablementKey = 'sync.enable' ;
3532const disableMachineEventuallyKey = 'sync.disableMachineEventually' ;
36- const SESSION_ID_KEY = 'sync.sessionId' ;
33+ const sessionIdKey = 'sync.sessionId' ;
3734
3835export class UserDataAutoSyncEnablementService extends Disposable {
3936
@@ -92,7 +89,6 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i
9289 @IUserDataSyncAccountService private readonly userDataSyncAccountService : IUserDataSyncAccountService ,
9390 @ITelemetryService private readonly telemetryService : ITelemetryService ,
9491 @IUserDataSyncMachinesService private readonly userDataSyncMachinesService : IUserDataSyncMachinesService ,
95- @IProductService private readonly productService : IProductService ,
9692 @IStorageService storageService : IStorageService ,
9793 @IEnvironmentService environmentService : IEnvironmentService
9894 ) {
@@ -114,7 +110,7 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i
114110 const { enabled, reason } = this . isAutoSyncEnabled ( ) ;
115111 if ( enabled ) {
116112 if ( this . autoSync . value === undefined ) {
117- this . autoSync . value = new AutoSync ( 1000 * 60 * 5 /* 5 miutes */ , this . userDataSyncStoreService , this . userDataSyncService , this . userDataSyncMachinesService , this . logService , this . storageService , this . productService ) ;
113+ this . autoSync . value = new AutoSync ( 1000 * 60 * 5 /* 5 miutes */ , this . userDataSyncStoreService , this . userDataSyncService , this . userDataSyncMachinesService , this . logService , this . storageService ) ;
118114 this . autoSync . value . register ( this . autoSync . value . onDidStartSync ( ( ) => this . lastSyncTriggerTime = new Date ( ) . getTime ( ) ) ) ;
119115 this . autoSync . value . register ( this . autoSync . value . onDidFinishSync ( e => this . onDidFinishSync ( e ) ) ) ;
120116 if ( this . startAutoSync ( ) ) {
@@ -167,7 +163,7 @@ export class UserDataAutoSyncService extends UserDataAutoSyncEnablementService i
167163 this . setEnablement ( false ) ;
168164
169165 // Reset Session
170- this . storageService . remove ( SESSION_ID_KEY , StorageScope . GLOBAL ) ;
166+ this . storageService . remove ( sessionIdKey , StorageScope . GLOBAL ) ;
171167
172168 // Reset
173169 if ( everywhere ) {
@@ -309,7 +305,6 @@ class AutoSync extends Disposable {
309305 private readonly userDataSyncMachinesService : IUserDataSyncMachinesService ,
310306 private readonly logService : IUserDataSyncLogService ,
311307 private readonly storageService : IStorageService ,
312- private readonly productService : IProductService ,
313308 ) {
314309 super ( ) ;
315310 }
@@ -368,7 +363,7 @@ class AutoSync extends Disposable {
368363 throw new UserDataAutoSyncError ( localize ( 'turned off' , "Cannot sync because syncing is turned off in the cloud" ) , UserDataSyncErrorCode . TurnedOff ) ;
369364 }
370365
371- const sessionId = this . storageService . get ( SESSION_ID_KEY , StorageScope . GLOBAL ) ;
366+ const sessionId = this . storageService . get ( sessionIdKey , StorageScope . GLOBAL ) ;
372367 // Server session is different from client session
373368 if ( sessionId && manifest && sessionId !== manifest . session ) {
374369 throw new UserDataAutoSyncError ( localize ( 'session expired' , "Cannot sync because current session is expired" ) , UserDataSyncErrorCode . SessionExpired ) ;
@@ -396,7 +391,7 @@ class AutoSync extends Disposable {
396391
397392 // Update local session id
398393 if ( manifest && manifest . session !== sessionId ) {
399- this . storageService . store ( SESSION_ID_KEY , manifest . session , StorageScope . GLOBAL ) ;
394+ this . storageService . store ( sessionIdKey , manifest . session , StorageScope . GLOBAL ) ;
400395 }
401396
402397 // Return if cancellation is requested
@@ -406,8 +401,7 @@ class AutoSync extends Disposable {
406401
407402 // Add current machine
408403 if ( ! currentMachine ) {
409- const name = this . computeDefaultMachineName ( machines ) ;
410- await this . userDataSyncMachinesService . addCurrentMachine ( name , manifest || undefined ) ;
404+ await this . userDataSyncMachinesService . addCurrentMachine ( manifest || undefined ) ;
411405 }
412406
413407 } catch ( e ) {
@@ -418,20 +412,6 @@ class AutoSync extends Disposable {
418412 this . _onDidFinishSync . fire ( error ) ;
419413 }
420414
421- private computeDefaultMachineName ( machines : IUserDataSyncMachine [ ] ) : string {
422- const namePrefix = `${ this . productService . nameLong } (${ PlatformToString ( isWeb ? Platform . Web : platform ) } )` ;
423- const nameRegEx = new RegExp ( `${ escapeRegExpCharacters ( namePrefix ) } \\s#(\\d)` ) ;
424-
425- let nameIndex = 0 ;
426- for ( const machine of machines ) {
427- const matches = nameRegEx . exec ( machine . name ) ;
428- const index = matches ? parseInt ( matches [ 1 ] ) : 0 ;
429- nameIndex = index > nameIndex ? index : nameIndex ;
430- }
431-
432- return `${ namePrefix } #${ nameIndex + 1 } ` ;
433- }
434-
435415 register < T extends IDisposable > ( t : T ) : T {
436416 return super . _register ( t ) ;
437417 }
0 commit comments