feat(gui): a tab owns its threads; kept state belongs to its books; one dock layout

An independent review of the tab work found that closing a tab did not
end what the tab started, that what the viewer keeps was filed under the
book id alone, and a few smaller things. All of it is the viewer's own
state: nothing here writes the books.

Threads: every thread a tab starts (loader, receipts' workers, export,
owner job, the dock's start and its agent's reaper) is counted in one
per-view registry (jobs.rs). Dropping the view tells them to stop and the
registry says, on a condition, when the last has ended. An owner job that
changes something (restore, format upgrade, new books, connect, close the
books, check for updates, update) is never abandoned: its tab's close
control is off with a hover text saying what runs, App::close refuses, and
the window's close request is cancelled with a dialog that offers only to
wait. Read-only jobs (an export, a backup, the restore's check) stop with
the tab: an export checks at its phase boundaries and saves nothing (the
save is one atomic write of a new file; one the stop reaches too late is
removed). The dock's agent is hung up on and, if it ignores that for two
seconds, killed and reaped; the window's drop waits for that.

Release on close: the loader checks "gone" before every retry and between
the phases of a load, its retry wait is woken by the drop, and the viewer
presence is let go in the drop itself, not when a refresh in flight ends.
A thumbnail for a closed tab is not written.

Kept state: filed under a hash of the data root's canonical path and the
id (books outside any root: under their folder), with the books' identity,
the SHA-256 of the journal's first line, taken once they load. A stored
state whose identity differs from the loaded books' is discarded with the
remembered name. Old unkeyed keys are read without error and not used. A
start that names a company never writes the list of open companies.

The dock's height is the app's one layout in every tab (said in the spec
block and tested); the sidebar, rail and top bar panels now take ids made
from their view's, since egui keys a panel's size by the id as given.

Every new test was seen to fail with its fix switched off. The four
sidenav tests keep their BAR_H: at the owner's 519 they fail by 15 points
(sidebar) and 11 (rail) without it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Sonnet 5.5 committed 2026-11-20 19:03:26 -07:00
1 parent 5cd0eded36
commit ec436cfc02
16 files changed
+2388 -154

No files matched your search

+21 -8
View File
@@ -46,6 +46,10 @@
//! for a state mark (drawn by a later unit, nothing now).
//! 6. This only says what was asked (show, close, open); the app does
//! it.
//! 7. A tab whose company has a job under way that changes its books
//! (`Tab::held`) has its close control off: disabled to assistive
//! technology, drawn faint, no click and no middle click closes it,
//! and its hover text says what is running.
//! ```
use crate::theme::{self, pal};
@@ -92,6 +96,10 @@ pub struct Tab {
/// What its badge's hue is chosen from: the id of its books
/// ([`hue_of`]).
pub hue_key: String,
/// Why the tab can't be closed now: a job that changes its books is
/// running ("Restoring these books: wait for it to finish"). Its close
/// control is off, and says so on hover.
pub held: Option<String>,
}
/// The badge hue of the company whose books have id `book_id`, light or
@@ -428,7 +436,7 @@ fn one_tab(
close.widget_info(|| {
egui::WidgetInfo::labeled(
egui::WidgetType::Button,
true,
tab.held.is_none(),
format!("Close {}", tab.title),
)
});
@@ -507,7 +515,7 @@ fn one_tab(
galley,
p.text,
);
if close.hovered() {
if close.hovered() && tab.held.is_none() {
painter.rect_filled(close_rect, CornerRadius::same(5), p.selected);
}
painter.text(
@@ -515,7 +523,9 @@ fn one_tab(
egui::Align2::CENTER_CENTER,
icon::X,
egui::FontId::proportional(12.0),
if close.hovered() || here {
if tab.held.is_some() {
p.faint
} else if close.hovered() || here {
p.text
} else {
p.muted
@@ -525,12 +535,15 @@ fn one_tab(
let resp = resp.on_hover_text(&tab.detail);
// The close control sits over the tab and is the one under the pointer
// there: a click on it is its own, never the tab's.
if close
.on_hover_text(format!("Close {}", tab.title))
.clicked()
|| resp.middle_clicked()
{
let close_tip = match &tab.held {
Some(why) => why.clone(),
None => format!("Close {}", tab.title),
};
let closes = close.on_hover_text(close_tip).clicked() || resp.middle_clicked();
if closes && tab.held.is_none() {
*action = Some(TabAction::Close(i));
} else if closes {
// Held open: the click is the close control's, and does nothing.
} else if resp.clicked() {
*action = Some(TabAction::Show(i));
}