Building StareBrain, Part 18: Auto-Collapse — The Overlay That Knows When to Hide
Building StareBrain, Part 18: Auto-Collapse — The Overlay That Knows When to Hide Part 17 covered drag-to-reposition. Today we tackle the other half of staying out of the way: auto-collapse. The overlay has three states — Idle, Running, AwaitingConfirmation. What we hadn't solved was when to transition between them based on what the user is doing, not just what the task is doing. If a step…
In this section of the StareBrain building process, the focus is on implementing an auto-collapse feature for the overlay. The overlay has three states: Idle, Running, and AwaitingConfirmation. The challenge lies in determining when to transition between these states based on user activity rather than just task activity. If a step completes while the user is typing in another app, expanding the overlay mid-keystroke would be incorrect.
To address this, an auto-collapse mechanism is introduced, which shrinks the overlay to a dot when the user is actively interacting with another app and expands it only when necessary attention is required. The implementation relies on an AccessibilityService that tracks user interactions using events such as focus changes, window changes, and text input.
A UserInteractionTracker class keeps track of the last interaction timestamp and whether the user is considered active. If there is no interaction for 3 seconds, the user is considered inactive. The CollapseController class then uses this information to decide whether to collapse the overlay based on task state and user activity.
Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.