@@ -54,6 +54,8 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
5454 public abstract getItems ( ) : Promise < TItem [ ] | undefined > ;
5555 public abstract getPropertyValue ( item : TItem , property : TProperty ) : string ;
5656
57+ public static autoRefreshViews : boolean = true ;
58+
5759 public groupBySetting : TProperty | CommonGroupBy ;
5860 public sortBySetting : CommonSortBy ;
5961 public labelSetting : TProperty ;
@@ -72,6 +74,10 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
7274 return workspace . getConfiguration ( `${ configPrefix } .${ this . treePrefix } ` ) ;
7375 }
7476
77+ private get autoRefreshEnabled ( ) : boolean {
78+ return window . state . focused && LocalRootTreeItemBase . autoRefreshViews ;
79+ }
80+
7581 protected getRefreshInterval ( ) : number {
7682 const configOptions : WorkspaceConfiguration = workspace . getConfiguration ( 'docker' ) ;
7783 return configOptions . get < number > ( 'explorerRefreshInterval' , 2000 )
@@ -89,8 +95,12 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
8995 const refreshInterval : number = this . getRefreshInterval ( ) ;
9096 intervalId = setInterval (
9197 async ( ) => {
92- if ( window . state . focused && await this . hasChanged ( ) ) {
93- await this . refresh ( ) ;
98+ if ( this . autoRefreshEnabled && await this . hasChanged ( ) ) {
99+ // Auto refresh could be disabled while invoking the hasChanged()
100+ // So check again before starting the refresh.
101+ if ( this . autoRefreshEnabled ) {
102+ await this . refresh ( ) ;
103+ }
94104 }
95105 } ,
96106 refreshInterval ) ;
@@ -118,13 +128,17 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
118128 } ) ] ;
119129 }
120130
131+ public clearPollingCache ( ) : void {
132+ this . _itemsFromPolling = undefined ;
133+ }
134+
121135 public async loadMoreChildrenImpl ( _clearCache : boolean , context : IActionContext ) : Promise < AzExtTreeItem [ ] > {
122136 try {
123137 // eslint-disable-next-line @typescript-eslint/no-floating-promises
124138 ext . activityMeasurementService . recordActivity ( 'overallnoedit' ) ;
125139
126140 this . _currentItems = this . _itemsFromPolling || await this . getSortedItems ( ) ;
127- this . _itemsFromPolling = undefined ;
141+ this . clearPollingCache ( ) ;
128142 this . failedToConnect = false ;
129143 this . _currentDockerStatus = 'Running' ;
130144 } catch ( error ) {
@@ -345,7 +359,7 @@ export abstract class LocalRootTreeItemBase<TItem extends ILocalItem, TProperty
345359 this . _itemsFromPolling = await this . getSortedItems ( ) ;
346360 pollingDockerStatus = 'Running' ;
347361 } catch ( error ) {
348- this . _itemsFromPolling = undefined ;
362+ this . clearPollingCache ( ) ;
349363 pollingDockerStatus = await dockerInstallStatusProvider . isDockerInstalled ( ) ? 'Installed' : 'NotInstalled' ;
350364 isDockerStatusChanged = pollingDockerStatus !== this . _currentDockerStatus ;
351365 }
0 commit comments