Skip to content

Add a mousedown handler to also signal user activity in the app#2976

Merged
sawka merged 7 commits intomainfrom
copilot/add-mousedown-event-handler
Mar 5, 2026
Merged

Add a mousedown handler to also signal user activity in the app#2976
sawka merged 7 commits intomainfrom
copilot/add-mousedown-event-handler

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

mousedown activity signaling was structured such that async telemetry concerns leaked into event handling. This change moves fire-and-forget behavior to the model boundary and keeps telemetry failures non-fatal.

  • mousedown handler path

    • AppKeyHandlers now calls GlobalModel.getInstance().setIsActive() directly (no async wrapper in the handler).
  • GlobalModel.setIsActive structure

    • setIsActive() is now synchronous (void).
    • Throttle logic remains unchanged.
    • Electron telemetry call is executed via util.fireAndForget(...) inside setIsActive().
  • Telemetry error containment

    • getApi().setIsActive() is wrapped in try/catch inside the fire-and-forget callback.
    • Errors are logged with console.log("setIsActive error", e) and do not bubble.
  • Focused coverage

    • Added frontend/app/store/global-model.test.ts for:
      • fire-and-forget invocation + throttling behavior
      • error logging/swallowing on rejected telemetry call
setIsActive(): void {
    const now = Date.now();
    if (now - this.lastSetIsActiveTs < GlobalModel.IsActiveThrottleMs) {
        return;
    }
    this.lastSetIsActiveTs = now;
    util.fireAndForget(async () => {
        try {
            await getApi().setIsActive();
        } catch (e) {
            console.log("setIsActive error", e);
        }
    });
}

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 4, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4cf6221
Status:⚡️  Build in progress...

View logs

Copilot AI changed the title [WIP] Add mousedown event handler for wasActive state Expand activity tracking to include renderer mousedown events via throttled set-is-active IPC Mar 4, 2026
Copilot finished work on behalf of sawka March 4, 2026 06:55
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Expand activity tracking to include renderer mousedown events via throttled set-is-active IPC Add renderer mousedown activity signal via throttled set-is-active IPC Mar 4, 2026
Copilot finished work on behalf of sawka March 4, 2026 17:34
@sawka sawka marked this pull request as ready for review March 4, 2026 18:34
return;
}
this.lastSetIsActiveTs = now;
await getApi().setIsActive();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Missing error handling for IPC call

The getApi().setIsActive() call could fail (e.g., if the IPC channel is unavailable). Since this is a non-critical activity tracking feature called in a fire-and-forget manner, consider adding a try-catch to prevent unhandled promise rejections:

async setIsActive(): Promise<void> {
    const now = Date.now();
    if (now - this.lastSetIsActiveTs < GlobalModel.IsActiveThrottleMs) {
        return;
    }
    this.lastSetIsActiveTs = now;
    try {
        await getApi().setIsActive();
    } catch (e) {
        // Silently ignore errors for non-critical activity tracking
    }
}

@kilo-code-bot
Copy link
Contributor

kilo-code-bot bot commented Mar 4, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
frontend/app/store/global-model.ts 61 Unnecessary arrow function wrapper in fireAndForget call
Files Reviewed (5 files)
  • frontend/app/store/global-model.ts - 1 issue
  • frontend/app/app.tsx - No issues
  • emain/emain-ipc.ts - No issues
  • emain/preload.ts - No issues
  • frontend/types/custom.d.ts - No issues

Fix these issues in Kilo Cloud

Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Add renderer mousedown activity signal via throttled set-is-active IPC Make mousedown activity telemetry non-blocking and non-fatal Mar 4, 2026
Copilot finished work on behalf of sawka March 4, 2026 18:54
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title Make mousedown activity telemetry non-blocking and non-fatal Restructure setIsActive to synchronous API with internal fire-and-forget telemetry call Mar 4, 2026
Copilot finished work on behalf of sawka March 4, 2026 21:25
await Promise.resolve();

expect(fireAndForget).toHaveBeenCalledTimes(1);
expect(logSpy).toHaveBeenCalledWith("setIsActive error", error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: Test expectation doesn't match actual error logging

The test expects console.log("setIsActive error", error) but the actual implementation uses fireAndForget() which logs "fireAndForget error" instead (see frontend/util/util.ts:179).

The test should expect:

expect(logSpy).toHaveBeenCalledWith("fireAndForget error", error);

return;
}
this.lastSetIsActiveTs = now;
util.fireAndForget(() => getApi().setIsActive());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Unnecessary arrow function wrapper

The fireAndForget function expects a function that returns a Promise. Since getApi().setIsActive() already returns a Promise<void>, you can pass it directly without the arrow function wrapper:

Suggested change
util.fireAndForget(() => getApi().setIsActive());
util.fireAndForget(getApi().setIsActive);

This is more concise and avoids creating an unnecessary closure.

@sawka sawka changed the title Restructure setIsActive to synchronous API with internal fire-and-forget telemetry call Add a mousedown handler to also signal user activity in the app Mar 5, 2026
@sawka sawka merged commit 0ab26ef into main Mar 5, 2026
5 of 6 checks passed
@sawka sawka deleted the copilot/add-mousedown-event-handler branch March 5, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants