[fix](trx-wefax): auto-save in-progress image on decoder reset
decoder.reset() now finalises and saves any partially-received image before returning to Idle. The server emits the completion event so the image appears in the frontend history and is persisted to disk. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stan Grams <sjg@haxx.space>
This commit is contained in:
@@ -325,8 +325,15 @@ impl WefaxDecoder {
|
||||
events
|
||||
}
|
||||
|
||||
/// Reset the decoder, discarding any in-progress image.
|
||||
pub fn reset(&mut self) {
|
||||
/// Reset the decoder. Saves the in-progress image (if any) before
|
||||
/// returning to Idle. Returns any completion events produced.
|
||||
pub fn reset(&mut self) -> Vec<WefaxEvent> {
|
||||
let events = match self.state {
|
||||
State::Receiving { ioc, lpm } | State::Phasing { ioc, lpm } => {
|
||||
self.finalize_image(ioc, lpm)
|
||||
}
|
||||
_ => Vec::new(),
|
||||
};
|
||||
let default_lpm = self.config.lpm.unwrap_or(120);
|
||||
self.state = State::Idle;
|
||||
self.resampler.reset();
|
||||
@@ -341,6 +348,7 @@ impl WefaxDecoder {
|
||||
self.sent_idle_event = false;
|
||||
self.signal_detect_count = 0;
|
||||
self.signal_detect_buf.clear();
|
||||
events
|
||||
}
|
||||
|
||||
/// Check if the decoder is currently receiving an image.
|
||||
|
||||
@@ -2742,7 +2742,13 @@ pub async fn run_wefax_decoder(
|
||||
|
||||
if reset_seq != last_reset_seq {
|
||||
last_reset_seq = reset_seq;
|
||||
decoder.reset();
|
||||
// Reset saves any in-progress image.
|
||||
for evt in decoder.reset() {
|
||||
if let WefaxEvent::Complete(msg) = evt {
|
||||
histories.record_wefax_message(msg.clone());
|
||||
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||
}
|
||||
}
|
||||
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
||||
pcm_rx = pcm_rx.resubscribe();
|
||||
continue;
|
||||
@@ -2750,7 +2756,12 @@ pub async fn run_wefax_decoder(
|
||||
|
||||
if !process_enabled {
|
||||
if was_active {
|
||||
decoder.reset();
|
||||
for evt in decoder.reset() {
|
||||
if let WefaxEvent::Complete(msg) = evt {
|
||||
histories.record_wefax_message(msg.clone());
|
||||
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||
}
|
||||
}
|
||||
was_active = false;
|
||||
}
|
||||
active = false;
|
||||
@@ -2778,7 +2789,12 @@ pub async fn run_wefax_decoder(
|
||||
state_rx.borrow().reset_seqs.wefax_decode_reset_seq;
|
||||
if latest_reset_seq != reset_seq {
|
||||
last_reset_seq = latest_reset_seq;
|
||||
decoder.reset();
|
||||
for evt in decoder.reset() {
|
||||
if let WefaxEvent::Complete(msg) = evt {
|
||||
histories.record_wefax_message(msg.clone());
|
||||
let _ = decode_tx.send(DecodedMessage::Wefax(msg));
|
||||
}
|
||||
}
|
||||
info!("WEFAX decoder reset (seq={})", last_reset_seq);
|
||||
pcm_rx = pcm_rx.resubscribe();
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user