Skip to content

Commit 964065c

Browse files
committed
Fix #229: Auto-poll active runs and respect window focus
1 parent a62d2e0 commit 964065c

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/extension.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ export async function activate(context: vscode.ExtensionContext) {
6262

6363
const store = new RunStore();
6464

65+
// Handle focus changes to pause/resume polling
66+
context.subscriptions.push(
67+
vscode.window.onDidChangeWindowState(e => {
68+
store.setFocused(e.focused);
69+
})
70+
);
71+
6572
// Pinned workflows
6673
await initPinnedWorkflows(store);
6774

src/store/store.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ type Updater = {
2020
export class RunStore extends EventEmitter<RunStoreEvent> {
2121
private runs = new Map<number, WorkflowRun>();
2222
private updaters = new Map<number, Updater>();
23+
private _isFocused = true;
24+
25+
setFocused(focused: boolean) {
26+
this._isFocused = focused;
27+
logDebug(`[Store]: Focus state changed to ${focused}`);
28+
}
2329

2430
getRun(runId: number): WorkflowRun | undefined {
2531
return this.runs.get(runId);
@@ -66,6 +72,10 @@ export class RunStore extends EventEmitter<RunStoreEvent> {
6672
}
6773

6874
private async fetchRun(updater: Updater) {
75+
if (!this._isFocused) {
76+
return;
77+
}
78+
6979
log(`Fetching run update: ${updater.runId}. Remaining attempts: ${updater.remainingAttempts}`);
7080

7181
updater.remainingAttempts--;
@@ -87,7 +97,14 @@ export class RunStore extends EventEmitter<RunStoreEvent> {
8797
log(`Polled run: ${run.id} Status: ${run.status} Conclusion: ${run.conclusion}`);
8898
this.addRun(updater.repoContext, run);
8999

90-
if (run.status === "completed" || run.status === "cancelled" || run.status === "failure" || run.status === "success" || run.status === "skipped" || run.status === "timed_out") {
100+
if (
101+
run.status === "completed" ||
102+
run.status === "cancelled" ||
103+
run.status === "failure" ||
104+
run.status === "success" ||
105+
run.status === "skipped" ||
106+
run.status === "timed_out"
107+
) {
91108
if (updater.handle) {
92109
clearInterval(updater.handle);
93110
}

src/treeViews/workflowRunTreeDataProvider.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ export abstract class WorkflowRunTreeDataProvider {
2424
): WorkflowRunNode[] {
2525
return runData.map(runData => {
2626
const workflowRun = this.store.addRun(gitHubRepoContext, runData);
27+
28+
// Auto-poll active runs
29+
if (
30+
workflowRun.run.status === "in_progress" ||
31+
workflowRun.run.status === "queued" ||
32+
workflowRun.run.status === "waiting" ||
33+
workflowRun.run.status === "requested"
34+
) {
35+
// Poll every 4 seconds for up to 15 minutes (225 attempts)
36+
this.store.pollRun(workflowRun.run.id, gitHubRepoContext, 4000, 225);
37+
}
38+
2739
const node = new WorkflowRunNode(
2840
this.store,
2941
gitHubRepoContext,

0 commit comments

Comments
 (0)