@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
8
8
import { openPullRequestOnGitHub } from '../commands' ;
9
9
import { COPILOT_ACCOUNTS , IComment } from '../common/comment' ;
10
10
import Logger from '../common/logger' ;
11
- import { WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys' ;
11
+ import { PR_SETTINGS_NAMESPACE , WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys' ;
12
12
import { ITelemetry } from '../common/telemetry' ;
13
13
import { CommentEvent , EventType , TimelineEvent } from '../common/timelineEvent' ;
14
14
import { asPromise , formatError } from '../common/utils' ;
@@ -130,29 +130,39 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
130
130
} ) ;
131
131
}
132
132
} ) ) ;
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
+
134
142
}
135
143
136
144
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 ;
138
146
}
139
147
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 ) ) ;
143
161
const timeoutDuration = 1000 * ( webview ? this . getRefreshInterval ( ) : ( 5 * 60 ) ) ;
144
- const timeout = setTimeout ( async ( ) => {
162
+ this . timeout = setTimeout ( async ( ) => {
145
163
await this . refreshPanel ( ) ;
146
164
this . pollForUpdates ( ) ;
147
165
} , 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
- }
156
166
}
157
167
158
168
public async refreshPanel ( ) : Promise < void > {
0 commit comments