Merge branch 't3/wanderbooks-app-hosted-bridge': nothing on the desktop starts a detached host (P15 A5)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Fable 5.2 committed 2026-11-21 12:32:59 -07:00
commit 610e41d1d1
34 files changed
+2967 -527

No files matched your search

+14
View File
@@ -535,12 +535,20 @@ impl App {
self.notices.extend(self.serving.take_notices());
let starting = self.serving.is_starting();
let down = self.serving.is_down();
// The refusal by a host is over once the start is on its way again
// (the host was closed): its words go, whether or not they were
// dismissed.
if !down {
self.notices.retain(|n| n != crate::serving::HOST_HOLDS);
}
if self.notices.is_empty() && !starting && !down {
return;
}
let p = pal(ui.ctx());
let mut dismiss = None;
let mut retry = false;
let mut close_host = false;
let host_blocks = self.serving.host_blocks();
egui::Panel::top("server_notices")
.resizable(false)
.frame(
@@ -563,6 +571,9 @@ impl App {
for (i, words) in self.notices.iter().enumerate() {
ui.horizontal_wrapped(|ui| {
ui.label(RichText::new(words).color(p.text));
if host_blocks && ui.button("Close it").clicked() {
close_host = true;
}
if down && ui.button("Try again").clicked() {
retry = true;
}
@@ -578,6 +589,9 @@ impl App {
if retry {
self.serving.retry();
}
if close_host {
self.serving.close_host();
}
if let Some(i) = dismiss {
self.notices.remove(i);
}
+19 -36
View File
@@ -1,14 +1,16 @@
//! The viewer's Books menu (plan P2 "Viewer menu", D-19, D-32): the
//! owner's own actions on the books, handed to the books server (back up
//! now, restore, new books, close the books, the format upgrade) or to the
//! now, restore, new books, the format upgrade) or to the
//! owner's agent (connect). The viewer itself still never writes the
//! books.
//!
//! ```text
//! GOAL: the owner backs up, restores, starts new books, closes the books
//! and connects an agent from the viewer, without a terminal.
//! GOAL: the owner backs up, restores, starts new books and connects an
//! agent from the viewer, without a terminal. (There is no "Close the
//! books": the app is the host, and a company's tab, or the window,
//! closes it: WB-app-2, WB-app-4.)
//! SOURCE: plan P2 ("Viewer menu (D-19)": "Back up now", "Restore…",
//! "New books…", "Close the books" and "Connect an assistant…"; the
//! "New books…" and "Connect an assistant…"; the
//! page it opens carries the two connect buttons; "Nothing in the viewer writes a book"); D-32
//! (no confinement: the viewer asks the server itself, as the
//! command line does); plan 3.9 and D-39 (the format upgrade: the
@@ -279,6 +281,19 @@ pub trait Owner: Send + Sync {
fn serve_start(&self, _open: &[String]) -> Result<(), String> {
Ok(())
}
/// Whether another program's host holds the books now (an earlier
/// build's, or `wanderbooks serve`'s): asked when the start was
/// refused, to offer the person a button that closes it
/// (`serve_close_host`) beside the line that says what to type.
fn serve_host_holds(&self) -> bool {
false
}
/// Ask that host to close the books and wait until it has (what
/// `wanderbooks close` does, for a person with no command line on
/// their path): `Ok` says what came of it, `Err` why not. Blocks.
fn serve_close_host(&self) -> Result<String, String> {
Err("not here".into())
}
/// Open the company `book` in the server (a tab opened): `Ok(None)`
/// when it is open now. Blocks.
fn serve_open(&self, _book: &str) -> Result<Option<String>, String> {
@@ -348,8 +363,6 @@ pub trait Owner: Send + Sync {
fn make_key(&self, _book: &str) -> Result<bool, String> {
Err("not here".into())
}
/// Close the books: everything holding them lets go.
fn close_books(&self) -> Result<String, String>;
/// New, empty books `id` in `currency`.
fn new_books(&self, id: &str, currency: &str) -> Result<String, String>;
/// Back the books `book` up now.
@@ -472,8 +485,6 @@ enum Dialog {
NewBooks { id: String, currency: String },
/// "Restore…": the backup, then its preview.
Restore(Box<RestoreForm>),
/// "Close the books": asked first.
Close,
/// The format upgrade: the go-ahead, with the owner passphrase.
Upgrade(Box<UpgradeForm>),
}
@@ -822,14 +833,6 @@ impl OwnerMenu {
Box::new(move || o.apply_update()),
));
}
ui.separator();
if ui
.button(format!("{} Close the books", icon::POWER))
.on_hover_text("Close the books now: assistants' sessions and every other holder let go")
.clicked()
{
self.dialog = Dialog::Close;
}
})
})
.inner;
@@ -916,26 +919,6 @@ impl OwnerMenu {
);
}
}
Dialog::Close => {
egui::Modal::new(self.scope.unwrap_or(egui::Id::NULL).with("owner-close")).show(ctx, |ui| {
ui.heading("Close the books?");
ui.label("Assistants' sessions and everything else holding them let go. They open again when something holds them.");
ui.horizontal(|ui| {
if ui.button("Close the books").clicked() {
let o = owner.clone();
run = Some((
"Close the books".into(),
Effect::Changes("Closing the books"),
Box::new(move || o.close_books().map(|l| vec![l])),
));
close = true;
}
if ui.button("Cancel").clicked() {
close = true;
}
});
});
}
Dialog::NewBooks { id, currency } => {
egui::Modal::new(self.scope.unwrap_or(egui::Id::NULL).with("owner-new-books"))
.show(ctx, |ui| {
+75 -1
View File
@@ -24,6 +24,11 @@
//! next tab opens or the person asks (`retry`); the owner has
//! stopped the server that failed, so no second one runs beside it.
//! A server still starting is waited for, in view (`is_starting`).
//! A start refused because a host holds the books (an earlier
//! build's, or `wanderbooks serve`'s) says what the button will do
//! and what to type instead, and offers the button (`host_blocks`,
//! `close_host`): it asks the host to close the books and starts
//! the server when it has; a close that fails says why.
//! 4. A company the window opened at the start is not opened again; a
//! company whose open failed, at the start (the server's list says
//! it isn't open: `serve_not_open`) or later, is a notice, and is
@@ -47,6 +52,11 @@ use std::collections::{BTreeSet, HashMap};
use std::sync::mpsc::{Sender, channel};
use std::sync::{Arc, Condvar, Mutex, MutexGuard};
/// What the person is told when the start was refused because a host
/// holds the books, and what to do: the button closes it for them, and the
/// command is there for a person who prefers a terminal.
pub const HOST_HOLDS: &str = "Assistants can't reach your companies: another program has these books open (an earlier Wanderbooks, or `wanderbooks serve`). \"Close it\" makes it let go of them and starts the books here; or, in a terminal, `wanderbooks close` does the same.";
/// Where the server's start stands (INVARIANT 3).
#[derive(Clone, Copy, PartialEq, Eq)]
enum Gate {
@@ -82,6 +92,12 @@ struct State {
report: Vec<String>,
/// The person has seen the report and chose to close anyway.
report_seen: bool,
/// The start was refused because a host holds the books (an earlier
/// build's, or `wanderbooks serve`'s): the notice has a button that
/// closes it (INVARIANT 3).
host_blocks: bool,
/// That button was pressed and the host is being asked to close.
host_closing: bool,
}
struct Inner {
@@ -207,7 +223,14 @@ impl Serving {
// A window asked to close meanwhile has no use for
// the word.
if *lock(&starting.closing) == Closing::Not {
starting.note(format!("Assistants can't reach your companies: {why}"));
let host = starting.owner.serve_host_holds();
lock(&starting.state).host_blocks = host;
if host {
starting.note(HOST_HOLDS.into());
} else {
starting
.note(format!("Assistants can't reach your companies: {why}"));
}
}
Gate::Down
}
@@ -276,6 +299,57 @@ impl Serving {
.is_some_and(|i| *lock(&i.gate) == Gate::Up && *lock(&i.closing) == Closing::Not)
}
/// Whether the start was refused because a host holds the books, so
/// the notice offers to close it (INVARIANT 3): not while that is
/// being done.
pub fn host_blocks(&self) -> bool {
self.inner.as_ref().is_some_and(|i| {
let state = lock(&i.state);
*lock(&i.gate) == Gate::Down && state.host_blocks && !state.host_closing
})
}
/// Ask the host that holds the books to close them, and start the
/// server when it has (INVARIANT 3): on a thread of its own, the
/// answer a notice. False when nothing was started.
pub fn close_host(&self) -> bool {
let Some(inner) = self.inner.clone() else {
return false;
};
if !self.host_blocks() {
return false;
}
lock(&inner.state).host_closing = true;
let asking = inner.clone();
let started = std::thread::Builder::new()
.name("serving-close-host".into())
.spawn(move || {
let said = asking.owner.serve_close_host();
{
let mut state = lock(&asking.state);
state.host_closing = false;
if said.is_ok() {
state.host_blocks = false;
// The old words are of a refusal that is over.
state.notices.retain(|n| n != HOST_HOLDS);
}
}
match said {
Ok(_) => {
Self::restart(&asking);
}
Err(why) => asking.note(format!(
"Couldn't close it: {why}. In a terminal, `wanderbooks close` closes it."
)),
}
})
.is_ok();
if !started {
lock(&inner.state).host_closing = false;
}
started
}
/// Whether the start failed and a `retry` would try again.
pub fn is_down(&self) -> bool {
self.inner