fix(usage): refresh usage snapshot on window focus - #4044
Draft
posthog[bot] wants to merge 1 commit into
Draft
Conversation
The title-bar usage meter is served from `UsageMonitorService`'s cached snapshot, refreshed only by the app's own LLM activity or a 30-minute backstop timer. Usage consumed elsewhere (the website, another device, a teammate) while the desktop window sits unfocused isn't reflected until that backstop fires, so the badge can read well under what the website already reports as exhausted. Adds a window-focus trigger, mirroring the existing `onLlmActivity` hook: the main process wires `UsageHost.onWindowFocus`/`offWindowFocus` to `IMainWindow.onFocus`, and `UsageMonitorService` requests a refresh whenever the window regains focus. Generated-By: PostHog Code Task-Id: a01f545a-82a9-4c13-b43e-be5b365d7a07
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UsageMonitorServiceserves the badge from a cached snapshot, refreshed only by two triggers: this app's own LLM activity, or a 30-minute backstop timer.Changes
UsageMonitorService, mirroring the existingonLlmActivitypattern:UsageHostgainsonWindowFocus/offWindowFocus, and the service callsrequestRefresh()whenever the window regains focus.IMainWindow.onFocusplatform hook — no new Electron surface needed.How did you test this?
pnpm --filter @posthog/core test -- usage-monitor— all 21 tests pass, including 2 new ones covering the focus-triggered refresh and its unsubscribe-on-stop behavior.npx biome checkon all changed files — clean.tsc --noEmitfailures for@posthog/agent/@posthog/gitreproduce identically on a cleanmaincheckout (unbuilt workspace deps in this sandbox), unrelated to this change; no new type errors were introduced.Automatic notifications
Created with PostHog Desktop from this inbox report.