diff --git a/crates/app/src/importing.rs b/crates/app/src/importing.rs index 97b6748..7ace767 100644 --- a/crates/app/src/importing.rs +++ b/crates/app/src/importing.rs @@ -86,7 +86,13 @@ pub(crate) enum Proxy { /// own state because it is what makes "how many are in flight" a number: /// the answer comes back on a worker, and until it does this file may still /// turn into an encode. - Asked, + /// + /// Carries the flag [`engine::proxy::generate_if_wanted`] polls at the door + /// and around the header read: the same shape [`Self::Making`] carries a + /// cancellable [`engine::proxy::Job`] with, one step earlier -- there is no + /// `Job` yet to hold, so the raw flag is what a stop asked during this + /// state has to set. + Asked(std::sync::Arc), /// A file this machine cuts at speed as it is: no stand-in, and none /// wanted ([`engine::proxy::wanted`]). Native, diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index ed2128a..68f1a71 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -621,18 +621,15 @@ impl Player { /// film's stand-in has asked, and is told by the row how far it has got. pub(crate) fn start_proxy_for(&mut self, path: &std::path::Path, cx: &mut Context) { let path = path.to_path_buf(); - self.proxies.insert(path.clone(), Proxy::Asked); + // The same flag [`engine::proxy::generate_if_wanted`] polls at the door + // and around the header read: a click on the row while the header is + // still being walked ([`Player::toggle_proxy`]'s `Asked` arm) sets it, + // so the walk unwinds mid-read instead of running to completion. + let cancel = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); + self.proxies.insert(path.clone(), Proxy::Asked(cancel.clone())); let started = cx.background_executor().spawn({ let path = path.clone(); - // deferred: DEBT #91 wires only the engine's header-read cancel - // (crates/engine/src/proxy.rs); the app has no cancel to hand it - // yet -- a stop asked during Asked still lands the way it always - // has, by the `stopped` check below once the ask returns. Wiring - // this flag to `toggle_proxy` is the next slice. - async move { - let uncancelled = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)); - engine::proxy::generate_if_wanted(&path, &uncancelled) - } + async move { engine::proxy::generate_if_wanted(&path, &cancel) } }); cx.spawn(async move |this, cx| { let started = started.await; @@ -644,7 +641,7 @@ impl Player { // half of a click made during the ask is an encoder nothing in // the map can reach -- and it finishes minutes later and puts // back the stand-in somebody switched off. - let stopped = !matches!(this.proxies.get(&path), Some(Proxy::Asked)); + let stopped = !matches!(this.proxies.get(&path), Some(Proxy::Asked(_))); let state = match started { // Cancelled and *held*, exactly as a stop of a running one // is: the worker's own answer is what settles it, so an @@ -718,7 +715,11 @@ impl Player { Some(Proxy::Making(_)) => self.cancel_proxy(path, cx), // Already winding down: the second click on a stop is nothing. Some(Proxy::Cancelling(_)) => {} - Some(Proxy::Asked) => { + Some(Proxy::Asked(cancel)) => { + // Wakes the header read mid-walk ([`engine::proxy::started`]): + // without this the stop only ever landed once the read had + // already run to completion on its own (DEBT #91). + cancel.store(true, std::sync::atomic::Ordering::Release); engine::proxy::set_off(path, true); self.proxies.insert(path.to_path_buf(), Proxy::Cancelled); let text = format!("STOPPING the stand-in for {}…", file_name(path)); @@ -868,7 +869,7 @@ impl Player { pub(crate) fn in_flight_proxies(&self) -> usize { self.proxies .values() - .filter(|p| matches!(p, Proxy::Asked | Proxy::Making(_) | Proxy::Cancelling(_))) + .filter(|p| matches!(p, Proxy::Asked(_) | Proxy::Making(_) | Proxy::Cancelling(_))) .count() } diff --git a/crates/app/src/tests/cards.rs b/crates/app/src/tests/cards.rs index 9202847..21a3b9f 100644 --- a/crates/app/src/tests/cards.rs +++ b/crates/app/src/tests/cards.rs @@ -2084,3 +2084,28 @@ fn darkroom_source_rows_keep_proxy_add_and_media_audio_text_paths() { ); } } + +/// DEBT #91: a click-to-stop while a stand-in's header is still being read +/// must reach the flag the read itself polls (`engine::proxy::started`), not +/// only relabel the row. Read off the source and not run, the way the row +/// above it is -- there is no `TestAppContext` in this binary to construct a +/// `Context` and call `toggle_proxy` on. On the state this fix +/// replaced, `start_proxy_for` handed the header read a flag nothing outside +/// it could reach and `Proxy::Asked` carried no field to store a stop into, +/// so `library.find("Proxy::Asked(cancel)")` below has nothing to find. +#[test] +fn toggle_proxy_wakes_the_asked_phase_it_stops() { + let library = src_text("player/library.rs"); + let start = &library[library.find("fn start_proxy_for(").expect("start_proxy_for")..]; + assert!( + start.contains("generate_if_wanted(&path, &cancel)"), + "start_proxy_for no longer hands the header read a cancel flag anyone can reach" + ); + let toggle = &library[library.find("fn toggle_proxy(").expect("toggle_proxy")..]; + let asked_arm = + &toggle[toggle.find("Proxy::Asked(cancel)").expect("the Asked arm's own flag")..]; + assert!( + asked_arm.contains("cancel.store(true"), + "a stop asked during Asked no longer sets the flag the header read polls" + ); +} diff --git a/crates/app/src/ui/dock_stance.rs b/crates/app/src/ui/dock_stance.rs index 45b7750..b982345 100644 --- a/crates/app/src/ui/dock_stance.rs +++ b/crates/app/src/ui/dock_stance.rs @@ -293,7 +293,7 @@ fn source_row( true, format!("Stopping the stand-in for {}…", row.name), ), - Some(Proxy::Asked) => ( + Some(Proxy::Asked(_)) => ( "○", false, None,