Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

refactor: remove convert module and associated state management

Tonho5edab58400a7
diff --git a/src-tauri/omniget-plugin-convert/src/commands/convert.rs b/src-tauri/omniget-plugin-convert/src/commands/convert.rs
deleted file mode 100644
index b6f44991..00000000
--- a/src-tauri/omniget-plugin-convert/src/commands/convert.rs
+++ /dev/null
@@ -1,126 +0,0 @@
-use serde::Serialize;
-use tauri::Emitter;
-use tokio::sync::mpsc;
-use tokio_util::sync::CancellationToken;
-
-use omniget_core::core::ffmpeg::{self, ConversionOptions, ConversionResult, MediaProbeInfo};
-use omniget_core::core::hwaccel::{self, HwAccelInfo};
-use crate::state::ConvertState;
-
-#[derive(Clone, Serialize)]
-struct ConvertProgressEvent {
- id: u64,
- percent: f64,
-}
-
-#[derive(Clone, Serialize)]
-struct ConvertCompleteEvent {
- id: u64,
- success: bool,
- result: Option<ConversionResult>,
- error: Option<String>,
-}
-
-#[tauri::command]
-pub async fn probe_file(path: String) -> Result<MediaProbeInfo, String> {
- ffmpeg::probe(std::path::Path::new(&path))
- .await
- .map_err(|e| e.to_string())
-}
-
-#[tauri::command]
-pub async fn convert_file(
- app: tauri::AppHandle,
- state: tauri::State<'_, ConvertState>,
- options: ConversionOptions,
-) -> Result<u64, String> {
- let conversion_id = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_millis() as u64;
-
- let cancel_token = CancellationToken::new();
-
- {
- let mut map = state.active_conversions.lock().await;
- map.insert(conversion_id, cancel_token.clone());
- }
-
- let active = state.active_conversions.clone();
-
- tokio::spawn(async move {
- let (tx, mut rx) = mpsc::channel::<f64>(32);
-
- let app_progress = app.clone();
- let cid = conversion_id;
- let progress_forwarder = tokio::spawn(async move {
- while let Some(percent) = rx.recv().await {
- let _ = app_progress.emit(
- "convert-progress",
- ConvertProgressEvent {
- id: cid,
- percent,
- },
- );
- }
- });
-
- let result = ffmpeg::convert(&options, cancel_token, tx).await;
-
- let _ = progress_forwarder.await;
-
- {
- let mut map = active.lock().await;
- map.remove(&conversion_id);
- }
-
- match result {
- Ok(conv_result) => {
- let success = conv_result.success;
- let error = conv_result.error.clone();
- let _ = app.emit(
- "convert-complete",
- ConvertCompleteEvent {
- id: conversion_id,
- success,
- result: Some(conv_result),
- error,
- },
- );
- }
- Err(e) => {
- let _ = app.emit(
- "convert-complete",
- ConvertCompleteEvent {
- id: conversion_id,
- success: false,
- result: None,
- error: Some(e.to_string()),
- },
- );
- }
- }
- });
-
- Ok(conversion_id)
-}
-
-#[tauri::command]
-pub async fn cancel_conversion(
- state: tauri::State<'_, ConvertState>,
- conversion_id: u64,
-) -> Result<String, String> {
- let mut map = state.active_conversions.lock().await;
- match map.remove(&conversion_id) {
- Some(token) => {
- token.cancel();
- Ok("Conversion cancelled".to_string())
- }
- None => Err("No active conversion for this ID".to_string()),
- }
-}
-
-#[tauri::command]
-pub async fn get_hwaccel_info() -> Result<HwAccelInfo, String> {
- Ok(hwaccel::detect_hwaccel().await)
-}
diff --git a/src-tauri/omniget-plugin-convert/src/commands/mod.rs b/src-tauri/omniget-plugin-convert/src/commands/mod.rs
deleted file mode 100644
index b5b67213..00000000
--- a/src-tauri/omniget-plugin-convert/src/commands/mod.rs
+++ /dev/null
@@ -1 +0,0 @@
-pub mod convert;
diff --git a/src-tauri/omniget-plugin-convert/src/state.rs b/src-tauri/omniget-plugin-convert/src/state.rs
deleted file mode 100644
index bd3abd3e..00000000
--- a/src-tauri/omniget-plugin-convert/src/state.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-use std::collections::HashMap;
-use std::sync::Arc;
-use tokio_util::sync::CancellationToken;
-
-pub struct ConvertState {
- pub active_conversions: Arc<tokio::sync::Mutex<HashMap<u64, CancellationToken>>>,
-}
-
-impl Default for ConvertState {
- fn default() -> Self {
- Self {
- active_conversions: Arc::new(tokio::sync::Mutex::new(HashMap::new())),
- }
- }
-}