An export's own result cannot get buried in the queue
Browse files at this commit601dec3f34ef478fdd9083c089b8b571b5e03d3cParent: 397bd83- fix
- an export's own result cannot get buried in the queue
2 changed files +45 -4
- crates/app/src/notices.rs +19 -4
- crates/app/src/tests/layout.rs +26 -0
crates/app/src/notices.rsmodified+19 -4
| @@ -19,9 +19,9 @@ pub(crate) const NOTICES_MAX: usize = 8; | |||
| 19 | pub(crate) const NOTICE_MIN_W: f32 = 180.; | 19 | pub(crate) const NOTICE_MIN_W: f32 = 180.; |
| 20 | 20 | ||
| 21 | /// The whole of the queue's policy, where it can be read at once and tested | 21 | /// The whole of the queue's policy, where it can be read at once and tested |
| 22 | -/// without a window: dedupe against the back, a ceiling, oldest out first. | 22 | +/// without a window: dedupe against the back, a ceiling, oldest out first -- |
| 23 | -/// [`Player::notify_user`] is the door every message comes through; this is what | 23 | +/// except an export's own outcome, which jumps to the front. [`Player::notify_user`] |
| 24 | -/// the door does. | 24 | +/// is the door every message comes through; this is what the door does. |
| 25 | pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString>, message: SharedString) { | 25 | pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString>, message: SharedString) { |
| 26 | // A repeat of what is already at the back is dropped -- holding a key that | 26 | // A repeat of what is already at the back is dropped -- holding a key that |
| 27 | // refuses would otherwise fill the queue with one sentence, and the count on | 27 | // refuses would otherwise fill the queue with one sentence, and the count on |
| @@ -32,7 +32,22 @@ pub(crate) fn push_notice(notices: &mut std::collections::VecDeque<SharedString> | |||
| 32 | if notices.len() >= NOTICES_MAX { | 32 | if notices.len() >= NOTICES_MAX { |
| 33 | notices.pop_front(); | 33 | notices.pop_front(); |
| 34 | } | 34 | } |
| 35 | - notices.push_back(message); | 35 | + // Minutes of an export land here the moment it ends, and behind two or |
| 36 | + // three progress lines (a proxy, a caption) queued while it ran, its own | ||
| 37 | + // result would sit unseen several dismissals deep. It is the one thing a | ||
| 38 | + // person started the export to read, so it goes to the front -- the | ||
| 39 | + // notice showing now -- rather than the back of the line. | ||
| 40 | + match is_completion(&message) { | ||
| 41 | + true => notices.push_front(message), | ||
| 42 | + false => notices.push_back(message), | ||
| 43 | + } | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +/// An export's own outcome: the one class of notice that outranks whatever | ||
| 47 | +/// is already queued ([`push_notice`]). Named by the same prefixes | ||
| 48 | +/// [`crate::player::export`] writes them with. | ||
| 49 | +fn is_completion(message: &str) -> bool { | ||
| 50 | + message.starts_with(EXPORT_DONE) || message.starts_with("EXPORT FAILED") | ||
| 36 | } | 51 | } |
| 37 | 52 | ||
| 38 | /// The tail an open/load notice grows when the file has sound the engine cannot | 53 | /// The tail an open/load notice grows when the file has sound the engine cannot |
crates/app/src/tests/layout.rsmodified+26 -0
| @@ -153,6 +153,32 @@ fn a_second_message_queues_behind_the_first_instead_of_erasing_it() { | |||
| 153 | assert_ne!(front, q.front().cloned()); | 153 | assert_ne!(front, q.front().cloned()); |
| 154 | } | 154 | } |
| 155 | 155 | ||
| 156 | +/// An export's own outcome is what a person started it to read, so it must | ||
| 157 | +/// never sit behind two progress lines queued while it ran: it jumps to the | ||
| 158 | +/// front and is the one showing the moment it arrives. | ||
| 159 | +#[test] | ||
| 160 | +fn an_export_outcome_jumps_the_queue() { | ||
| 161 | + let mut q = std::collections::VecDeque::new(); | ||
| 162 | + push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); | ||
| 163 | + push_notice(&mut q, "SUBTITLES b.srt — 1 track(s) in the palette".into()); | ||
| 164 | + push_notice(&mut q, format!("{EXPORT_DONE}out.mp4").into()); | ||
| 165 | + assert_eq!(q.len(), 3); | ||
| 166 | + assert_eq!( | ||
| 167 | + q.front().map(|n: &gpui::SharedString| n.as_ref()), | ||
| 168 | + Some(format!("{EXPORT_DONE}out.mp4")).as_deref(), | ||
| 169 | + "the export's result must be the notice showing, not third in line" | ||
| 170 | + ); | ||
| 171 | + | ||
| 172 | + // A failed export is the same class: the outcome, whichever it was. | ||
| 173 | + let mut q = std::collections::VecDeque::new(); | ||
| 174 | + push_notice(&mut q, "PROXY READY for a.mp4 — Proxies on cuts on it".into()); | ||
| 175 | + push_notice(&mut q, "EXPORT FAILED: disk full".into()); | ||
| 176 | + assert_eq!( | ||
| 177 | + q.front().map(|n: &gpui::SharedString| n.as_ref()), | ||
| 178 | + Some("EXPORT FAILED: disk full") | ||
| 179 | + ); | ||
| 180 | +} | ||
| 181 | + | ||
| 156 | /// The bar colours itself off the words the message already opens with, so | 182 | /// The bar colours itself off the words the message already opens with, so |
| 157 | /// the tone cannot disagree with the sentence it labels. | 183 | /// the tone cannot disagree with the sentence it labels. |
| 158 | #[test] | 184 | #[test] |