Skip to content

Commit 1bfccfd

Browse files
authored
Refresh PR when webview becomes visible (#6933)
* Remove uses of property existence with `in` * Refresh PR when webview becomes visible Fixes #6898 * Revert "Remove uses of property existence with `in`" This reverts commit 28cf23a.
1 parent a80e822 commit 1bfccfd

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/github/issueOverview.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
88
import { openPullRequestOnGitHub } from '../commands';
99
import { COPILOT_ACCOUNTS, IComment } from '../common/comment';
1010
import Logger from '../common/logger';
11-
import { WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys';
11+
import { PR_SETTINGS_NAMESPACE, WEBVIEW_REFRESH_INTERVAL } from '../common/settingKeys';
1212
import { ITelemetry } from '../common/telemetry';
1313
import { CommentEvent, EventType, TimelineEvent } from '../common/timelineEvent';
1414
import { 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> {

src/github/pullRequestOverview.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
124124
));
125125

126126
this.setVisibilityContext();
127-
this._register(this._panel.onDidChangeViewState(() => this.setVisibilityContext()));
128127
this._register(folderRepositoryManager.onDidMergePullRequest(_ => {
129128
this._postMessage({
130129
command: 'update-state',
@@ -167,6 +166,11 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
167166
}
168167
}
169168

169+
protected override onDidChangeViewState(e: vscode.WebviewPanelOnDidChangeViewStateEvent): void {
170+
super.onDidChangeViewState(e);
171+
this.setVisibilityContext();
172+
}
173+
170174
private setVisibilityContext() {
171175
return commands.setContext(contexts.PULL_REQUEST_DESCRIPTION_VISIBLE, this._panel.visible);
172176
}

0 commit comments

Comments
 (0)