@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
88import { openPullRequestOnGitHub } from '../commands' ;
99import { COPILOT_ACCOUNTS , IComment } from '../common/comment' ;
1010import Logger from '../common/logger' ;
11- import { WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys' ;
11+ import { PR_SETTINGS_NAMESPACE , WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys' ;
1212import { ITelemetry } from '../common/telemetry' ;
1313import { CommentEvent , EventType , TimelineEvent } from '../common/timelineEvent' ;
1414import { asPromise , formatError } from '../common/utils' ;
@@ -130,29 +130,39 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
130130 } ) ;
131131 }
132132 } ) ) ;
133- this . pollForUpdates ( true ) ;
133+
134+ this . _register ( this . _panel . onDidChangeViewState ( e => this . onDidChangeViewState ( e ) ) ) ;
135+ this . pollForUpdates ( ) ;
136+ this . _register ( vscode . workspace . onDidChangeConfiguration ( e => {
137+ if ( e . affectsConfiguration ( `${ PR_SETTINGS_NAMESPACE } .${ WEBVIEW_REFRESH_INTERVAL } ` ) ) {
138+ this . pollForUpdates ( ) ;
139+ }
140+ } ) ) ;
141+
134142 }
135143
136144 private getRefreshInterval ( ) : number {
137- return vscode . workspace . getConfiguration ( ) . get < number > ( `githubPullRequests .${ WEBVIEW_REFRESH_INTERVAL } ` ) || 60 ;
145+ return vscode . workspace . getConfiguration ( ) . get < number > ( `${ PR_SETTINGS_NAMESPACE } .${ WEBVIEW_REFRESH_INTERVAL } ` ) || 60 ;
138146 }
139147
140- private refreshIntervalSetting : vscode . Disposable | undefined ;
141- private pollForUpdates ( shorterTimeout : boolean = false ) : void {
142- const webview = shorterTimeout || vscode . window . tabGroups . all . find ( group => group . activeTab ?. input instanceof vscode . TabInputWebview && group . activeTab . input . viewType . endsWith ( this . type ) ) ;
148+ protected onDidChangeViewState ( e : vscode . WebviewPanelOnDidChangeViewStateEvent ) : void {
149+ if ( e . webviewPanel . visible ) {
150+ this . pollForUpdates ( true ) ;
151+ }
152+ }
153+
154+ private timeout : NodeJS . Timeout | undefined = undefined ;
155+ private pollForUpdates ( refreshImmediately : boolean = false ) : void {
156+ clearTimeout ( this . timeout ) ;
157+ if ( refreshImmediately ) {
158+ this . refreshPanel ( ) ;
159+ }
160+ const webview = vscode . window . tabGroups . all . find ( group => group . activeTab ?. input instanceof vscode . TabInputWebview && group . activeTab . input . viewType . endsWith ( this . type ) ) ;
143161 const timeoutDuration = 1000 * ( webview ? this . getRefreshInterval ( ) : ( 5 * 60 ) ) ;
144- const timeout = setTimeout ( async ( ) => {
162+ this . timeout = setTimeout ( async ( ) => {
145163 await this . refreshPanel ( ) ;
146164 this . pollForUpdates ( ) ;
147165 } , timeoutDuration ) ;
148- if ( ! this . refreshIntervalSetting ) {
149- this . refreshIntervalSetting = vscode . workspace . onDidChangeConfiguration ( e => {
150- if ( e . affectsConfiguration ( `githubPullRequests.${ WEBVIEW_REFRESH_INTERVAL } ` ) ) {
151- clearTimeout ( timeout ) ;
152- this . pollForUpdates ( true ) ;
153- }
154- } ) ;
155- }
156166 }
157167
158168 public async refreshPanel ( ) : Promise < void > {
0 commit comments