Skip to content

Commit 52b1015

Browse files
Copilotalexr00
andcommitted
Add periodic notification refresh setting
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 861b09e commit 52b1015

4 files changed

Lines changed: 32 additions & 12 deletions

File tree

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@
297297
"default": "off",
298298
"description": "%githubPullRequests.notifications.description%"
299299
},
300+
"githubPullRequests.notificationsRefreshInterval": {
301+
"type": "number",
302+
"default": 600,
303+
"minimum": 60,
304+
"description": "%githubPullRequests.notificationsRefreshInterval.description%"
305+
},
300306
"githubPullRequests.fileListLayout": {
301307
"type": "string",
302308
"enum": [

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"githubPullRequests.queries.createdByMe": "Created By Me",
3636
"githubPullRequests.defaultMergeMethod.description": "The method to use when merging pull requests.",
3737
"githubPullRequests.notifications.description": "If GitHub notifications should be shown to the user.",
38+
"githubPullRequests.notificationsRefreshInterval.description": "The interval in seconds at which to refresh GitHub notifications. Default is 600 seconds (10 minutes). Minimum is 60 seconds.",
3839
"githubPullRequests.fileListLayout.description": "The layout to use when displaying changed files list.",
3940
"githubPullRequests.hideViewedFiles.description": "Hide files that have been marked as viewed in the pull request changes tree.",
4041
"githubPullRequests.defaultDeletionMethod.selectLocalBranch.description": "When true, the option to delete the local branch will be selected by default when deleting a branch from a pull request.",

src/common/settingKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export const EXPERIMENTAL_CHAT = 'experimental.chat';
6262
export const EXPERIMENTAL_USE_QUICK_CHAT = 'experimental.useQuickChat';
6363
export const EXPERIMENTAL_NOTIFICATIONS_PAGE_SIZE = 'experimental.notificationsViewPageSize';
6464
export const EXPERIMENTAL_NOTIFICATIONS_SCORE = 'experimental.notificationsScore';
65+
export const NOTIFICATIONS_REFRESH_INTERVAL = 'notificationsRefreshInterval';
6566
export const WEBVIEW_REFRESH_INTERVAL = 'webviewRefreshInterval';
6667

6768
// git

src/notifications/notificationsManager.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { NotificationsProvider } from './notificationsProvider';
99
import { commands, contexts } from '../common/executeCommands';
1010
import { Disposable } from '../common/lifecycle';
1111
import Logger from '../common/logger';
12-
import { NOTIFICATION_SETTING, NotificationVariants, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
12+
import { NOTIFICATION_SETTING, NOTIFICATIONS_REFRESH_INTERVAL, NotificationVariants, PR_SETTINGS_NAMESPACE } from '../common/settingKeys';
1313
import { EventType, TimelineEvent } from '../common/timelineEvent';
1414
import { toNotificationUri } from '../common/uri';
1515
import { CredentialStore } from '../github/credentials';
@@ -70,6 +70,13 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
7070
this._startPolling();
7171
}
7272
}
73+
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${NOTIFICATIONS_REFRESH_INTERVAL}`)) {
74+
if (this.isPRNotificationsOn() && this._pollingHandler) {
75+
// Restart polling with new interval
76+
this._stopPolling();
77+
this._startPolling();
78+
}
79+
}
7380
}));
7481
this._register(PullRequestOverviewPanel.onVisible(e => {
7582
this.markPrNotificationsAsRead(e);
@@ -412,6 +419,10 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
412419
return (vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<NotificationVariants>(NOTIFICATION_SETTING) === 'pullRequests');
413420
}
414421

422+
private _getRefreshInterval(): number {
423+
return vscode.workspace.getConfiguration(PR_SETTINGS_NAMESPACE).get<number>(NOTIFICATIONS_REFRESH_INTERVAL, 600);
424+
}
425+
415426
private async _pollForNewNotifications() {
416427
this._pageCount = 1;
417428
this._dateTime = new Date();
@@ -423,33 +434,34 @@ export class NotificationsManager extends Disposable implements vscode.TreeDataP
423434
return;
424435
}
425436

426-
// Adapt polling interval if it has changed.
427-
if (response.pollInterval !== this._pollingDuration) {
428-
this._pollingDuration = response.pollInterval;
429-
if (this._pollingHandler && this.isPRNotificationsOn()) {
430-
Logger.appendLine('Notifications: Clearing interval', NotificationsManager.ID);
431-
clearInterval(this._pollingHandler);
432-
Logger.appendLine(`Notifications: Starting new polling interval with ${this._pollingDuration}`, NotificationsManager.ID);
433-
this._startPolling();
434-
}
435-
}
437+
// Note: We ignore the pollInterval from GitHub's response and use the user-configured interval instead
436438
if (response.lastModified !== this._pollingLastModified) {
437439
this._pollingLastModified = response.lastModified;
438440
this._onDidChangeTreeData.fire();
439441
}
440442
// this._onDidChangeNotifications.fire(oldPRNodesToUpdate);
441443
}
442444

445+
private _stopPolling() {
446+
if (this._pollingHandler) {
447+
Logger.appendLine('Notifications: Clearing interval', NotificationsManager.ID);
448+
clearInterval(this._pollingHandler);
449+
this._pollingHandler = null;
450+
}
451+
}
452+
443453
private _startPolling() {
444454
if (!this.isPRNotificationsOn()) {
445455
return;
446456
}
457+
const refreshInterval = this._getRefreshInterval();
458+
Logger.appendLine(`Notifications: Starting polling with interval ${refreshInterval} seconds`, NotificationsManager.ID);
447459
this._pollForNewNotifications();
448460
this._pollingHandler = setInterval(
449461
function (notificationProvider: NotificationsManager) {
450462
notificationProvider._pollForNewNotifications();
451463
},
452-
this._pollingDuration * 1000,
464+
refreshInterval * 1000,
453465
this
454466
);
455467
this._register({ dispose: () => clearInterval(this._pollingHandler!) });

0 commit comments

Comments
 (0)