Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5609d21

Browse files
committed
Prevent immediately polling when connecting
Now, calling fetchAndRefresh() is a no-op if the view is not visible.
1 parent 7c401fe commit 5609d21

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/workspacesProvider.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
3636
private agentWatchers: Record<WorkspaceAgent["id"], AgentWatcher> = {}
3737
private timeout: NodeJS.Timeout | undefined
3838
private fetching = false
39+
private visible = false
3940

4041
constructor(
4142
private readonly getWorkspacesQuery: WorkspaceQuery,
@@ -48,10 +49,10 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
4849
// fetchAndRefresh fetches new workspaces, re-renders the entire tree, then
4950
// keeps refreshing (if a timer length was provided) as long as the user is
5051
// still logged in and no errors were encountered fetching workspaces.
51-
// Calling this while already refreshing is a no-op and will return
52-
// immediately.
52+
// Calling this while already refreshing or not visible is a no-op and will
53+
// return immediately.
5354
async fetchAndRefresh() {
54-
if (this.fetching) {
55+
if (this.fetching || !this.visible) {
5556
return
5657
}
5758
this.fetching = true
@@ -146,6 +147,7 @@ export class WorkspaceProvider implements vscode.TreeDataProvider<vscode.TreeIte
146147
* Either start or stop the refresh timer based on visibility.
147148
*/
148149
setVisibility(visible: boolean) {
150+
this.visible = visible
149151
if (!visible) {
150152
this.cancelPendingRefresh()
151153
} else {

0 commit comments

Comments
 (0)