use spotiflac_extensions::ffmpeg::{CommandRegistry, CommandResult, RegistryClosed}; use std::sync::Arc; #[derive(Debug, thiserror::Error, uniffi::Error)] #[uniffi(flat_error)] pub enum FfmpegError { #[error("FFmpeg command registry closed")] Closed, } impl From for FfmpegError { fn from(_: RegistryClosed) -> Self { Self::Closed } } /// All handles returned by one environment refer to its single command queue. #[derive(uniffi::Object)] pub struct FfmpegCommands { pub(crate) inner: Arc, } #[uniffi::export] impl FfmpegCommands { pub fn wait_pending(&self, timeout_ms: i64) -> Result { self.inner.wait_pending_json(timeout_ms).map_err(Into::into) } pub fn get_command(&self, command_id: String) -> Result { Ok(self .inner .get(&command_id)? .map_or_else(String::new, |command| { serde_json::to_string(&command).expect("FFmpeg command JSON") })) } pub fn complete( &self, command_id: String, success: bool, output: String, error: String, ) -> Result { self.inner .complete( &command_id, CommandResult { success, output, error, }, ) .map_err(Into::into) } pub fn shutdown(&self) { self.inner.shutdown(); } }