@@ -166,22 +166,43 @@ export class CopilotPRWatcher extends Disposable {
166166 this . _pollForChanges ( ) ;
167167 }
168168 } ) ) ;
169- this . _register ( { dispose : ( ) => this . _timeout && clearTimeout ( this . _timeout ) } ) ;
169+ this . _register ( vscode . window . onDidChangeWindowState ( e => {
170+ if ( e . active || e . focused ) {
171+ // If we are becoming active/focused, and it's been more than the poll interval since the last poll, poll now
172+ if ( Date . now ( ) - this . _lastPollTime > this . _pollInterval ) {
173+ this . _pollForChanges ( ) ;
174+ }
175+ }
176+ } ) ) ;
177+ this . _register ( { dispose : ( ) => this . _pollTimeout && clearTimeout ( this . _pollTimeout ) } ) ;
170178 }
171179
172180 private _queriesIncludeCopilot ( ) : string | undefined {
173181 const queries = vscode . workspace . getConfiguration ( PR_SETTINGS_NAMESPACE ) . get < { label : string ; query : string } [ ] > ( QUERIES , [ ] ) ;
174182 return queries . find ( query => isCopilotQuery ( query . query ) ) ?. query ;
175183 }
176184
177- private _timeout : NodeJS . Timeout | undefined ;
185+ private get _pollInterval ( ) : number {
186+ if ( vscode . window . state . active || vscode . window . state . focused ) {
187+ return 60 * 1000 * 2 ; // Poll every 2 minutes
188+ }
189+ return 60 * 1000 * 5 ; // Poll every 5 minutes
190+ }
191+
192+ private _pollTimeout : NodeJS . Timeout | undefined ;
193+ private _lastPollTime = 0 ;
178194 private async _pollForChanges ( ) : Promise < void > {
195+ if ( this . _pollTimeout ) {
196+ clearTimeout ( this . _pollTimeout ) ;
197+ this . _pollTimeout = undefined ;
198+ }
199+ this . _lastPollTime = Date . now ( ) ;
179200 const shouldContinue = await this . _getStateChanges ( ) ;
180201
181202 if ( shouldContinue ) {
182- this . _timeout = setTimeout ( ( ) => {
203+ this . _pollTimeout = setTimeout ( ( ) => {
183204 this . _pollForChanges ( ) ;
184- } , 60 * 1000 ) ; // Poll every minute
205+ } , this . _pollInterval ) ;
185206 }
186207 }
187208
0 commit comments