Add a mousedown handler to also signal user activity in the app#2976
Add a mousedown handler to also signal user activity in the app#2976
Conversation
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
set-is-active IPC
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
set-is-active IPCset-is-active IPC
frontend/app/store/global-model.ts
Outdated
| return; | ||
| } | ||
| this.lastSetIsActiveTs = now; | ||
| await getApi().setIsActive(); |
There was a problem hiding this comment.
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
}
}
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Files Reviewed (5 files)
|
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
set-is-active IPCCo-authored-by: sawka <2722291+sawka@users.noreply.github.com>
setIsActive to synchronous API with internal fire-and-forget telemetry call
| await Promise.resolve(); | ||
|
|
||
| expect(fireAndForget).toHaveBeenCalledTimes(1); | ||
| expect(logSpy).toHaveBeenCalledWith("setIsActive error", error); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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:
| util.fireAndForget(() => getApi().setIsActive()); | |
| util.fireAndForget(getApi().setIsActive); |
This is more concise and avoids creating an unnecessary closure.
setIsActive to synchronous API with internal fire-and-forget telemetry call
mousedownactivity 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.mousedownhandler pathAppKeyHandlersnow callsGlobalModel.getInstance().setIsActive()directly (no async wrapper in the handler).GlobalModel.setIsActivestructuresetIsActive()is now synchronous (void).util.fireAndForget(...)insidesetIsActive().Telemetry error containment
getApi().setIsActive()is wrapped intry/catchinside the fire-and-forget callback.console.log("setIsActive error", e)and do not bubble.Focused coverage
frontend/app/store/global-model.test.tsfor:🔒 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.