Browser: drive the live list off inotify, not a 1s poll
Replace the 1 s polling re-read of the browser directory with an inotify watch (dirWatcher, internal/editor/dirwatcher.go) using golang.org/x/sys/unix, which is already in the build list — no new dependency, no go.mod change. - The watcher watches the current browser directory and coalesces a burst of events to at most one token; the owner re-reads on the token. Create, delete, rename, modify, and attrib (mtime) changes are all covered, so an inbound sync that touches a file's mtime re-sorts the list in the current sort mode. - The watch is re-pointed when the directory changes (a no-op while the path is unchanged) and is closed when the logic goroutine exits (covers both Shutdown and the test harness Done+WaitForExit path). - A slow 30 s backstop rescan remains as a safety net for the rare event the FUSE inotify layer drops (syncthing uses the same inotify+rescan pattern on Android). The change-detection from the previous commit means the backstop emits no frame when nothing changed, so TestNoFramesWhileIdle_Browser still holds. - If inotify is unavailable (newDirWatcher returns nil) or a watch add fails, the 30 s backstop is the only path — a graceful degradation, not a break. Verified on-device (Notes dir, Date-descending): an external add appears at the top in well under a second (impossibly fast for the 30 s backstop, so the inotify path); touching a file's mtime re-sorts it to the top; a delete drops the row. All sub-second.
This commit is contained in:
+23
-17
@@ -544,23 +544,29 @@ Only the visible byte range is shaped and drawn each frame:
|
||||
- The browser renders via `ListView`/`ListItem` elements; rows carry
|
||||
`Interaction` handlers that send channel requests (tap) or mutate state
|
||||
directly when the handler runs on the owner (scroll).
|
||||
- **Live refresh.** While the browser page is on screen, the current directory
|
||||
is re-read on a short timer (≈1 s) so external changes — files added,
|
||||
removed, renamed, or mtime-changed (including inbound syncs) — appear live,
|
||||
re-sorted in the *current* sort mode. Invariant: **a refresh that finds the
|
||||
directory unchanged rebuilds nothing and emits no frame**, so the
|
||||
event-driven emission contract (§2; `TestNoFramesWhileIdle_Browser`) still
|
||||
holds while the browser idles. A landing (re)index is applied in place: the
|
||||
visible+prefetch pages are repopulated synchronously from the fresh index
|
||||
(no async gap / flicker), the scroll offset is preserved then clamped, and an
|
||||
active search is re-filtered without a scroll jump. Bounded to **one read per
|
||||
directory**: a refresh requested while a read of the same directory is in
|
||||
flight coalesces (skips), and a stale result for a directory the user has
|
||||
since left is dropped rather than clobbering the current view. A failed
|
||||
*refresh* keeps the last good view (the next tick retries); a failed
|
||||
*navigation* still recovers to the previous directory. Returning to the
|
||||
browser from the editor triggers one immediate refresh so the list is current
|
||||
on the frame you land back, not one tick later.
|
||||
- **Live refresh.** While the browser page is on screen the current directory
|
||||
is watched with **inotify** (`dirWatcher`, `internal/editor/dirwatcher.go`):
|
||||
a create / delete / rename / modify / attrib event there — including an
|
||||
inbound sync that changes a file's mtime — re-reads the directory within tens
|
||||
of ms, re-sorted in the *current* sort mode. A slow **backstop rescan** (30 s)
|
||||
covers the rare event the FUSE inotify layer drops; it is the only remaining
|
||||
periodic component and, by the invariant below, emits no frame when nothing
|
||||
changed. The watch is re-pointed whenever the directory changes (a no-op while
|
||||
the path is unchanged) and is closed when the logic goroutine exits. Invariant:
|
||||
**a re-read that finds the directory unchanged rebuilds nothing and emits no
|
||||
frame**, so the event-driven emission contract (§2;
|
||||
`TestNoFramesWhileIdle_Browser`) still holds while the browser idles. A
|
||||
landing (re)index is applied in place: the visible+prefetch pages are
|
||||
repopulated synchronously from the fresh index (no async gap / flicker), the
|
||||
scroll offset is preserved then clamped, and an active search is re-filtered
|
||||
without a scroll jump. Bounded to **one read per directory**: a re-read
|
||||
requested while a read of the same directory is in flight coalesces (skips),
|
||||
and a stale result for a directory the user has since left is dropped rather
|
||||
than clobbering the current view. A failed *refresh* keeps the last good view
|
||||
(the next event or backstop tick retries); a failed *navigation* still recovers
|
||||
to the previous directory. Returning to the browser from the editor triggers
|
||||
one immediate re-read so the list is current on the frame you land back (events
|
||||
that fired while the editor was on screen are no-ops there).
|
||||
|
||||
## 8. Render pipeline (`internal/ui`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user