Add Focus lockdown; list every site on Websites; fix sidebar null#12

merged5
main
hoplite/phanagoria-8d502e8a
opened21d agobyUusehopliteBot
View on GitHubTwo-way sync enabledPR last imported 21d ago

Focus lockdown

A new Focus page holds a block list and an on/off switch, and the tray has a matching turn-on/turn-off item. While lockdown is on, a blocked site in the browser in front of you is covered on every screen by a "Focus lockdown is on" window. The cover goes away when you close the tab or switch to something else.

  • How sites are recognised: the browser in front is checked about once a second, using the window title and the browser's local history (the same approach site tracking uses). Nothing is blocked at the network level, so a page can show for about a second before it is covered.
  • Block list entries: pasted addresses (https://www.reddit.com/r/all, *.reddit.com) are saved as plain hostnames, and each entry also covers its subdomains. The Go backend and the Electron fallback store clean entries up the same way.
  • The cover: it opens without taking keyboard focus, so Ctrl+W still reaches the browser. Its "Open screen-time" button jumps to the Focus page, and it never runs in demo or screenshot mode.
  • History guesses: when a site can only be guessed from the latest history visit, that guess is now cached briefly instead of for 10 minutes. Lockdown only trusts such a guess if the visit is under a minute old.

Fixes

  • The Websites page now lists every site instead of the top 6 plus an "Other sites" row. The Today card keeps the short list and adds a "See all N sites" link.
  • The sidebar no longer shows a stray "null" when no update is waiting.

Verification

  • npm test passes, with new tests covering block-list cleanup, subdomain matching, the watcher's show/hide rules, and stale guesses.
  • go test ./... passes, with a new store test.
  • Screenshots checked: the Focus page (demo data, and the Go backend with a seeded list), the cover screen, the Websites page, and the Today card.
  • Not verified: the cover over a real browser on Windows, macOS or Linux, because the sandbox has no desktop. This needs a manual check on each platform.

Devin Review

Checks

1 cancelled ยท 1 successful
Some checks were not successful

Cancelled1

57ebc10
Synced from GitHub

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cb45f7a1-cdd6-4215-af33-73d480b235f5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix ยท Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

electron/focus.jsline 86Outdated ยท e4e4690Open thread
……@@ -0,0 +1,125 @@
83+ const list = normalizeSiteList(this.store.settings.blockedSites);
84+ const foreground = this.readWindow();
85+ // An unreadable window, the cover or screen-time itself: leave things as they are.
86+ if (!foreground || foreground.error || foreground.pid === this.selfPid) return;
Ddevin-ai-integrationBoton line 8621d ago

๐ŸŸก Tray-opened settings remain covered

Opening screen-time from the tray while a site is blocked leaves the always-on-top cover over its window. FocusGuard.check keeps that cover when screen-time becomes foreground, hiding the settings needed to disable lockdown.

Learn more

The cover spans every display and stays above ordinary windows. When a user opens screen-time via the tray while it is showing, showWindow raises the main window but does not hide the cover. The next check sees screen-time's PID and returns without clearing it. The cover button works differently because its IPC handler hides the cover first.

Example: Block reddit.com, visit it, then choose โ€œOpen screen-timeโ€ from the tray. The Focus page opens behind the cover rather than becoming visible.

Recommended fix: Hide the cover when showing the main window, or distinguish the main window from the cover in FocusGuard.check and hide it while the main window is active. Preserve the ability to restore the cover if the blocked browser returns to foreground.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: showWindow now hides the cover, and the guard also clears it when the main screen-time window is foreground.

electron/focus.jslines 97โ€“98Outdated ยท e4e4690Open thread
……@@ -0,0 +1,125 @@
95+ let found = null;
96+ try { found = await this.lookup(browser, title, { negativeMs: LOOKUP_RETRY_MS }); } catch { found = null; }
97+ const trusted = found && (!found.guessed || Date.now() - found.visitedAt < GUESS_MAX_AGE_MS);
98+ if (trusted) site = blockedEntry(found.domain, list);
Ddevin-ai-integrationBoton lines 97โ€“9821d ago

๐ŸŸก Old history matches cover unrelated pages

When an unblocked page shares a title with an old blocked visit, FocusGuard trusts that history match regardless of age. lookup can return and cache the old visit, covering the unblocked page.

Learn more

History lookup searches recent rows by title, but does not limit the age of a title match. It labels only the latest-visit fallback as guessed. FocusGuard accepts every non-guessed match even when the matching history entry came from a blocked site visited long before the page now in front. The shared browser lookup can keep that matched result cached for ten minutes.

Example: Visit a blocked site whose page title is โ€œAccountโ€, then later open an unrelated site whose title is also โ€œAccountโ€ and has no matching history record yet. The old blocked history row matches and causes a cover on the unrelated site.

Recommended fix: Bound the age of title-based history results used for lockdown, and verify that a currently visited page corresponds to the chosen domain before enforcing a block. Keep the screen-time naming heuristic separate if older matches remain useful there.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: FocusGuard now requires a recent visit or a strong title match, so loose old history matches no longer trigger lockdown.

electron/main.jsline 342Outdated ยท e4e4690Open thread
……@@ -312,25 +331,40 @@ function applyLoginItem(settings) {
339+ if (settings.launchAtLogin !== before.launchAtLogin) applyLoginItem(settings);
340+ if (settings.autoUpdate !== before.autoUpdate && updater) updater.setEnabled(updatesAllowed(settings));
341+ if (settings.sampleSeconds !== before.sampleSeconds) tracker.restart();
342+ if (focusGuard) focusGuard.sync();
Ddevin-ai-integrationBoton line 34221d ago

๐Ÿ”ด Browser settings leave lockdown inactive

When the browser UI enables lockdown, FocusGuard stays stopped because browser settings updates bypass applySettings. Blocked sites remain visible until Electron restarts or updates settings through its own window.

Learn more

The Go backend serves the same Focus page to a browser. Its settings endpoint updates the persisted store directly, while BackendStore.settings only refreshes on Electron-initiated requests or snapshots. FocusGuard.sync runs at startup and after Electron settings updates, so it never sees a browser-only change while the desktop frontend is closed. This also leaves an already-running guard using an outdated list after browser-side edits.

Example: Electron runs hidden in the tray with lockdown off. A browser opens the Go UI, adds reddit.com, and turns lockdown on. The server persists both changes, but FocusGuard remains stopped and Reddit is not covered.

Recommended fix: Have the Electron process observe backend settings changes independently of frontend snapshots, update BackendStore.settings, and call focusGuard.sync() on changes. Cover both enabling and disabling, including block-list changes.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: The settings poll now refreshes BackendStore.settings and calls FocusGuard.sync(), so browser-side lockdown and block-list changes reach the guard.

electron/blocklist.jsline 47Outdated ยท e4e4690Open thread
……@@ -0,0 +1,51 @@
44+ if (!text) return null;
45+ return list.find((entry) => {
46+ const escaped = entry.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
47+ return new RegExp(`(^|[^a-z0-9-])([a-z0-9-]+\\.)*${escaped}($|[^a-z0-9-])`).test(text);
Ddevin-ai-integrationBoton line 4721d ago

๐ŸŸก Unrelated domain suffixes trigger lockdown

With reddit.com blocked, titleEntry also matches browser titles containing reddit.com.au. The period passes its trailing boundary check, so unrelated sites get covered before history can identify them.

Learn more

The title matcher accepts a dot after the entire blocked entry, although a dot there can continue the hostname. blockedEntry correctly matches only an exact hostname or a hostname ending with . plus the entry; the title-based path has different semantics and takes priority over history lookup.

Example: If reddit.com is blocked, a browser title reddit.com.au - Google Chrome matches titleEntry, while blockedEntry('reddit.com.au', ['reddit.com']) returns null. The cover hides the unrelated site.

Recommended fix: Parse hostname-like spans in titles and pass the extracted host to blockedEntry, or require that the character following the matched domain cannot extend a hostname, including a period followed by another label.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: The title matcher now rejects a hostname continuation such as .au after reddit.com.

Synced from GitHub

Addressed all four review comments in ba0491a:

  1. Settings changed from the browser UI (electron/main.js): the backend now has GET /api/v1/settings. When Electron uses the Go backend it re-reads settings every 3 seconds and re-syncs the lockdown watcher and the tray.
  2. Cover stuck over the main window (electron/focus.js): opening the main window from anywhere now hides the cover first. The watcher also lifts the cover whenever screen-time's own window is in front, unless the cover itself has focus, and puts it back if the blocked page returns.
  3. reddit.com.au matching reddit.com (electron/blocklist.js): a title match can no longer run on into a longer hostname.
  4. Old, loose history matches (electron/focus.js): a history answer only triggers the cover if the visit is under a minute old or the title matched closely (90 or more out of 100).

New tests cover each fix; npm test and go test ./... pass.

electron/main.jslines 484โ€“485Outdated ยท ba0491aOpen thread
……@@ -435,6 +472,27 @@ if (!app.requestSingleInstanceLock()) {
482+ settingsPoll = setInterval(async () => {
483+ const before = store.settings;
484+ try { await store.refreshSettings(); } catch { return; }
485+ focusGuard.sync();
Ddevin-ai-integrationBoton lines 484โ€“48521d ago

๐Ÿ” Browser settings bypass desktop side effects

When browser users change login, update, or sampling settings, the poll refreshes store.settings without running applySettings. Desktop side effects remain unchanged until restart.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: The concern that browser-side settings skipped all desktop side effects has been addressed by the new settingsChanged call. The current bug concerns a separate race where another snapshot can update settings before the poll.

Synced from GitHub

Addressed the follow-up comment on electron/main.js (browser settings skipping desktop side effects): the side effects now live in one settingsChanged(before, after) function, used both by applySettings and by the settings poll. Changes to launch at login, auto-update, sampling, pause or lockdown made from the browser UI now take effect within about 3 seconds, without a restart.

electron/main.jsline 490Outdated ยท 54bfe73Open thread
……@@ -435,6 +477,22 @@ if (!app.requestSingleInstanceLock()) {
487+ settingsPoll = setInterval(async () => {
488+ const before = store.settings;
489+ try { await store.refreshSettings(); } catch { return; }
490+ settingsChanged(before, store.settings);
Ddevin-ai-integrationBoton line 49021d ago

๐Ÿ” Settings restart clears lock suspension

If a browser sampling change reaches the poll after screen lock, tracker.restart() clears the tracker's suspended state and schedules sampling. Check whether the sampler must remain stopped until unlock.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: Tracker.restart now returns while suspended, preserving suspension until wake().

electron/main.jsline 490Outdated ยท 54bfe73Open thread
……@@ -435,6 +477,22 @@ if (!app.requestSingleInstanceLock()) {
487+ settingsPoll = setInterval(async () => {
488+ const before = store.settings;
489+ try { await store.refreshSettings(); } catch { return; }
490+ settingsChanged(before, store.settings);
Ddevin-ai-integrationBoton line 49021d ago

๐Ÿ”ด Browser update opt-out leaves downloads enabled

If the desktop opens after a browser update opt-out, settingsChanged misses it because snapshot() already replaced store.settings. The updater stays enabled and can install an update on quit.

Learn more

The Electron renderer calls snapshot when its window opens. BackendStore.snapshot assigns the backend settings to store.settings, independently of the polling callback. If this request lands between a browser-side settings change and the poll, both before and the refreshed settings contain the new value. The poll skips desktop side effects, including Updater.setEnabled, until another change occurs.

Example: With automatic updates on, turn them off in the browser and open the desktop window within three seconds. The snapshot caches autoUpdate: false before the poll, so the poll never disables the already-running updater.

Recommended fix: Keep a separate last-applied desktop settings snapshot for settingsChanged, rather than using store.settings as the previous value. Update that snapshot only after desktop side effects have run, including for changes made through applySettings.

Devin Review


Was this helpful? React with ๐Ÿ‘ or ๐Ÿ‘Ž to provide feedback.

โœ… Resolved: The new appliedSettings snapshot tracks the last settings applied to desktop side effects, so a renderer snapshot cannot make the polling callback miss a browser-side autoUpdate change.

Synced from GitHub

Addressed both follow-up findings on electron/main.js:

  • Browser update opt-out missed by the poll: the desktop now keeps its own copy of the last settings it applied, so a snapshot request refreshing the shared settings first can no longer hide a change from the poll.
  • Sampling change during screen lock: a tracker restart now leaves a suspended (locked or asleep) tracker alone. Waking already starts fresh with the current interval. Test added.

npm test, the lifecycle test and go test ./... pass.

Added 5 commits

  • Track last-applied settings for the poll; keep a locked tracker suspended on restart57ebc10
  • Stub the Focus lockdown modules in the lifecycle test5ecd1f9
  • Add Focus lockdown, list every site on the Websites page, fix stray null in sidebar7fcd281
  • Run desktop side effects for settings changed from the browser UIbc252a0
  • Focus lockdown: follow browser-UI settings, lift cover for screen-time, tighter site matchingcc7bd1e