feat: adiciona funcionalidade de cancelamento de geração de faixas de áudio e atualiza o painel de execução

This commit is contained in:
2026-02-28 14:57:11 -03:00
parent 02c6d8ede2
commit 4dec1ef8ed
4 changed files with 83 additions and 33 deletions
+22 -2
View File
@@ -45,6 +45,9 @@ pub struct App {
// Canal de comunicação do background thread
bg_rx: Option<mpsc::Receiver<BackgroundMsg>>,
// Sender para cancelar a geração em andamento
cancel_tx: Option<tokio::sync::oneshot::Sender<()>>,
// Mensagem de erro global (ex: dependências ausentes)
global_error: Option<String>,
}
@@ -68,6 +71,7 @@ impl App {
add_subtitle_form: AddSubtitleForm::new(),
execution_panel: ExecutionPanel::new(),
bg_rx: None,
cancel_tx: None,
global_error,
}
}
@@ -148,6 +152,9 @@ impl App {
self.execution_panel.state = ExecutionState::Running;
self.execution_panel.log_lines.clear();
let (cancel_tx, cancel_rx) = tokio::sync::oneshot::channel::<()>();
self.cancel_tx = Some(cancel_tx);
std::thread::spawn(move || {
// Canal std para receber linhas de log do run_ffmpeg_async
let (log_tx, log_rx) = std::sync::mpsc::channel::<String>();
@@ -163,7 +170,7 @@ impl App {
});
let rt = tokio::runtime::Runtime::new().expect("Falha ao criar runtime tokio");
let result = rt.block_on(run_ffmpeg_async(args, log_tx));
let result = rt.block_on(run_ffmpeg_async(args, log_tx, cancel_rx));
// Aguarda o encaminhador consumir todas as linhas pendentes
// antes de enviar Done/Error, garantindo ordem correta no log
@@ -180,6 +187,15 @@ impl App {
ctx.request_repaint();
});
}
/// Cancela a geração em andamento, encerrando o processo FFmpeg.
fn cancel_generation(&mut self) {
if let Some(tx) = self.cancel_tx.take() {
let _ = tx.send(());
}
self.bg_rx = None;
self.execution_panel.state = ExecutionState::Cancelled;
}
}
impl eframe::App for App {
@@ -215,10 +231,14 @@ impl eframe::App for App {
.show(ctx, |ui| {
ui.add_space(4.0);
let can_generate = self.pending_source.is_some() && self.pending_output.is_some();
if self.execution_panel.ui(ui, can_generate) {
let (generate, cancel) = self.execution_panel.ui(ui, can_generate);
if generate {
let ctx_clone = ctx.clone();
self.start_generation(ctx_clone);
}
if cancel {
self.cancel_generation();
}
ui.add_space(4.0);
});