| ... | ... | @@ -417,7 +417,8 @@ enum Replay { |
| 417 | 417 | /// Waits for nothing to be on its way, then writes the window's accessibility tree as |
| 418 | 418 | /// text where given, and answers. |
| 419 | 419 | Settle(Option<PathBuf>, std::sync::mpsc::Sender<()>), |
| 420 | | /// A frame during a wait, as a visible window's display would ask for. |
| 420 | /// A frame during a wait, as a visible window's display would ask for; one at a time |
| 421 | /// (`TICKING`), so a window drawing slower than the display falls no further behind. |
| 421 | 422 | Tick, |
| 422 | 423 | /// What the window sent itself when it found nothing on its way, at that instant: once it |
| 423 | 424 | /// arrives, so has every event sent before. |
| ... | ... | @@ -6645,6 +6646,9 @@ fn page_text(editor: &CanvasEditor) -> String { |
| 6645 | 6646 | /// Work [`spawn`] started that has not ended. |
| 6646 | 6647 | static RUNNING: AtomicUsize = AtomicUsize::new(0); |
| 6647 | 6648 | |
| 6649 | /// A replay's tick is on its way and not yet drawn. |
| 6650 | static TICKING: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); |
| 6651 | |
| 6648 | 6652 | fn spawn(work: impl FnOnce() + Send + 'static) { |
| 6649 | 6653 | RUNNING.fetch_add(1, Ordering::Relaxed); |
| 6650 | 6654 | let work = move || { |
| ... | ... | @@ -6801,7 +6805,8 @@ impl State { |
| 6801 | 6805 | Replay::Settle(path, settled) => { |
| 6802 | 6806 | self.replay_settle = Some((path, settled, None)); |
| 6803 | 6807 | } |
| 6804 | | Replay::Tick | Replay::Mark(_) | Replay::Quit => {} |
| 6808 | Replay::Tick => TICKING.store(false, Ordering::Release), |
| 6809 | Replay::Mark(_) | Replay::Quit => {} |
| 6805 | 6810 | Replay::Appearance(appearance) => { |
| 6806 | 6811 | self.window.set_theme(Some(appearance)); |
| 6807 | 6812 | self.set_appearance(appearance); |
| ... | ... | @@ -6972,6 +6977,7 @@ impl ApplicationHandler<UserEvent> for App { |
| 6972 | 6977 | UserEvent::Quit => self.close(event_loop), |
| 6973 | 6978 | // A cold launch's documents arrive before the window opens. |
| 6974 | 6979 | UserEvent::Open(paths) => self.opening.extend(paths), |
| 6980 | UserEvent::Replay(Replay::Tick) => TICKING.store(false, Ordering::Release), |
| 6975 | 6981 | _ => {} |
| 6976 | 6982 | } |
| 6977 | 6983 | return; |
| ... | ... | @@ -7244,6 +7250,16 @@ fn write_png(path: &Path, size: [u32; 2], pixels: &[u8]) -> Result<(), Box<dyn E |
| 7244 | 7250 | Ok(()) |
| 7245 | 7251 | } |
| 7246 | 7252 | |
| 7253 | #[cfg(not(target_arch = "wasm32"))] |
| 7254 | /// Asks for a replay's frame, unless the last one asked for is not yet drawn. |
| 7255 | fn tick(proxy: &EventLoopProxy<UserEvent>) { |
| 7256 | if !TICKING.swap(true, Ordering::AcqRel) |
| 7257 | && proxy.send_event(UserEvent::Replay(Replay::Tick)).is_err() |
| 7258 | { |
| 7259 | TICKING.store(false, Ordering::Release); |
| 7260 | } |
| 7261 | } |
| 7262 | |
| 7247 | 7263 | /// Feeds a development script to the window from another thread, one command per line |
| 7248 | 7264 | /// in logical pixels: `move X Y`, `press [right]`, `release [right]`, `wheel DX DY`, |
| 7249 | 7265 | /// `pressure LEVEL|none`, `pinch FACTOR`, `key NAME`, `type TEXT`, `modifiers [shift] |
| ... | ... | @@ -7388,15 +7404,20 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy |
| 7388 | 7404 | } |
| 7389 | 7405 | let settling = matches!(replay, Replay::Settle(..)); |
| 7390 | 7406 | let _ = proxy.send_event(UserEvent::Replay(replay)); |
| 7391 | | // Frames tick until settled; a minute bounds a page that never lands. |
| 7407 | // Frames tick until settled; a minute bounds a page that never lands, and |
| 7408 | // a replay that waited out its minute fails rather than going on without |
| 7409 | // what the step was to write. |
| 7392 | 7410 | let start = Instant::now(); |
| 7393 | 7411 | while settling |
| 7394 | | && start.elapsed().as_secs() < 60 |
| 7395 | 7412 | && settled |
| 7396 | 7413 | .recv_timeout(std::time::Duration::from_micros(16_667)) |
| 7397 | 7414 | .is_err() |
| 7398 | 7415 | { |
| 7399 | | let _ = proxy.send_event(UserEvent::Replay(Replay::Tick)); |
| 7416 | if start.elapsed().as_secs() >= 60 { |
| 7417 | eprintln!("The replay never settled"); |
| 7418 | std::process::exit(1); |
| 7419 | } |
| 7420 | tick(&proxy); |
| 7400 | 7421 | } |
| 7401 | 7422 | } |
| 7402 | 7423 | Err(duration) => { |
| ... | ... | @@ -7409,7 +7430,7 @@ fn replay(script: String, proxy: EventLoopProxy<UserEvent>) -> Result<(), Box<dy |
| 7409 | 7430 | tick += period; |
| 7410 | 7431 | } |
| 7411 | 7432 | std::thread::sleep(tick - Instant::now()); |
| 7412 | | let _ = proxy.send_event(UserEvent::Replay(Replay::Tick)); |
| 7433 | self::tick(&proxy); |
| 7413 | 7434 | } |
| 7414 | 7435 | } |
| 7415 | 7436 | } |