@@ -63,6 +63,7 @@ import type { Deferrable } from '../../system/function/debounce';
6363import  {  debounce  }  from  '../../system/function/debounce' ; 
6464import  {  filterMap  }  from  '../../system/iterable' ; 
6565import  {  getSettledValue  }  from  '../../system/promise' ; 
66+ import  {  SubscriptionManager  }  from  '../../system/subscriptionManager' ; 
6667import  type  {  ShowInCommitGraphCommandArgs  }  from  '../plus/graph/protocol' ; 
6768import  type  {  Change  }  from  '../plus/patchDetails/protocol' ; 
6869import  type  {  IpcMessage  }  from  '../protocol' ; 
@@ -115,10 +116,6 @@ const emptyDisposable = Object.freeze({
115116	} , 
116117} ) ; 
117118
118- interface  RepositorySubscription  { 
119- 	repo : Repository ; 
120- 	subscription ?: Disposable ; 
121- } 
122119interface  RepositoryBranchData  { 
123120	repo : Repository ; 
124121	branches : GitBranch [ ] ; 
@@ -407,10 +404,10 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
407404	} 
408405
409406	private  hasRepositoryChanged ( ) : boolean  { 
410- 		if  ( this . _repositorySubscription ?. repo  !=  null )  { 
407+ 		if  ( this . _repositorySubscription ?. source  !=  null )  { 
411408			if  ( 
412- 				this . _repositorySubscription . repo . etag  !==  this . _etagRepository  || 
413- 				this . _repositorySubscription . repo . etagFileSystem  !==  this . _etagFileSystem 
409+ 				this . _repositorySubscription . source . etag  !==  this . _etagRepository  || 
410+ 				this . _repositorySubscription . source . etagFileSystem  !==  this . _etagFileSystem 
414411			)  { 
415412				return  true ; 
416413			} 
@@ -423,12 +420,12 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
423420
424421	onVisibilityChanged ( visible : boolean ) : void   { 
425422		if  ( ! visible )  { 
426- 			this . stopRepositorySubscription ( ) ; 
423+ 			this . _repositorySubscription ?. pause ( ) ; 
427424
428425			return ; 
429426		} 
430427
431- 		this . resumeRepositorySubscription ( ) ; 
428+ 		this . _repositorySubscription ?. resume ( ) ; 
432429
433430		if  ( 
434431			this . _discovering  ==  null  && 
@@ -860,7 +857,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
860857		} ; 
861858	} 
862859
863- 	private  _repositorySubscription : RepositorySubscription  |  undefined ; 
860+ 	private  _repositorySubscription : SubscriptionManager < Repository >  |  undefined ; 
864861	private  selectRepository ( repoPath ?: string )  { 
865862		let  repo : Repository  |  undefined ; 
866863		if  ( repoPath  !=  null )  { 
@@ -872,48 +869,29 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
872869			} 
873870		} 
874871
875- 		if  ( this . _repositorySubscription  !=  null )  { 
876- 			this . _repositorySubscription . subscription ?. dispose ( ) ; 
877- 			this . _repositorySubscription  =  undefined ; 
878- 		} 
872+ 		this . _repositorySubscription ?. dispose ( ) ; 
873+ 		this . _repositorySubscription  =  undefined ; 
874+ 
879875		if  ( repo  !=  null )  { 
880- 			this . _repositorySubscription  =  { 
881- 				repo : repo , 
882- 				subscription : this . subscribeToRepository ( repo ) , 
883- 			} ; 
876+ 			this . _repositorySubscription  =  new  SubscriptionManager ( repo ,  r  =>  this . subscribeToRepository ( r ) ) ; 
877+ 			// Start the subscription immediately if webview is visible 
878+ 			if  ( this . host . visible )  { 
879+ 				this . _repositorySubscription . start ( ) ; 
880+ 			} 
884881		} 
885882
886883		return  repo ; 
887884	} 
888885
889- 	private  stopRepositorySubscription ( )  { 
890- 		if  ( this . _repositorySubscription  !=  null )  { 
891- 			this . _repositorySubscription . subscription ?. dispose ( ) ; 
892- 			this . _repositorySubscription . subscription  =  undefined ; 
893- 		} 
894- 	} 
895- 
896- 	private  resumeRepositorySubscription ( force  =  false )  { 
897- 		if  ( this . _repositorySubscription  ==  null )  { 
898- 			return ; 
899- 		} 
900- 
901- 		if  ( force  ||  this . _repositorySubscription . subscription  ==  null )  { 
902- 			this . _repositorySubscription . subscription ?. dispose ( ) ; 
903- 			this . _repositorySubscription . subscription  =  undefined ; 
904- 			this . _repositorySubscription . subscription  =  this . subscribeToRepository ( this . _repositorySubscription . repo ) ; 
905- 		} 
906- 	} 
907- 
908886	private  resetBranchOverview ( )  { 
909887		this . _repositoryBranches . clear ( ) ; 
910888
911889		if  ( ! this . host . visible )  { 
912- 			this . stopRepositorySubscription ( ) ; 
890+ 			this . _repositorySubscription ?. pause ( ) ; 
913891			return ; 
914892		} 
915893
916- 		this . resumeRepositorySubscription ( true ) ; 
894+ 		this . _repositorySubscription ?. resume ( ) ; 
917895	} 
918896
919897	private  subscribeToRepository ( repo : Repository ) : Disposable  { 
@@ -977,7 +955,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
977955			this . selectRepository ( ) ; 
978956		} 
979957
980- 		return  this . _repositorySubscription ?. repo ; 
958+ 		return  this . _repositorySubscription ?. source ; 
981959	} 
982960
983961	private  _invalidateOverview : 'repo'  |  'wip'  |  undefined ; 
0 commit comments