feat: invoke bindings generation, drop overlay preview

This commit is contained in:
2025-07-14 13:44:18 -05:00
parent 2e03281a79
commit 2f41943959
8 changed files with 420 additions and 58 deletions

90
src-tauri/Cargo.lock generated
View File

@@ -1,6 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
version = 4
[[package]]
name = "Inflector"
version = "0.11.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
[[package]]
name = "addr2line"
@@ -346,9 +352,12 @@ dependencies = [
"ffprobe",
"serde",
"serde_json",
"specta",
"specta-typescript",
"tauri",
"tauri-build",
"tauri-plugin-opener",
"tauri-specta",
]
[[package]]
@@ -2460,6 +2469,12 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "pathdiff"
version = "0.2.3"
@@ -3394,6 +3409,50 @@ dependencies = [
"system-deps",
]
[[package]]
name = "specta"
version = "2.0.0-rc.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab7f01e9310a820edd31c80fde3cae445295adde21a3f9416517d7d65015b971"
dependencies = [
"paste",
"specta-macros",
"thiserror 1.0.69",
]
[[package]]
name = "specta-macros"
version = "2.0.0-rc.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0074b9e30ed84c6924eb63ad8d2fe71cdc82628525d84b1fcb1f2fd40676517"
dependencies = [
"Inflector",
"proc-macro2",
"quote",
"syn 2.0.104",
]
[[package]]
name = "specta-serde"
version = "0.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77216504061374659e7245eac53d30c7b3e5fe64b88da97c753e7184b0781e63"
dependencies = [
"specta",
"thiserror 1.0.69",
]
[[package]]
name = "specta-typescript"
version = "0.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3220a0c365e51e248ac98eab5a6a32f544ff6f961906f09d3ee10903a4f52b2d"
dependencies = [
"specta",
"specta-serde",
"thiserror 1.0.69",
]
[[package]]
name = "stable_deref_trait"
version = "1.2.0"
@@ -3592,6 +3651,7 @@ dependencies = [
"serde_json",
"serde_repr",
"serialize-to-javascript",
"specta",
"swift-rs",
"tauri-build",
"tauri-macros",
@@ -3760,6 +3820,34 @@ dependencies = [
"wry",
]
[[package]]
name = "tauri-specta"
version = "2.0.0-rc.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b23c0132dd3cf6064e5cd919b82b3f47780e9280e7b5910babfe139829b76655"
dependencies = [
"heck 0.5.0",
"serde",
"serde_json",
"specta",
"specta-typescript",
"tauri",
"tauri-specta-macros",
"thiserror 2.0.12",
]
[[package]]
name = "tauri-specta-macros"
version = "2.0.0-rc.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a4aa93823e07859546aa796b8a5d608190cd8037a3a5dce3eb63d491c34bda8"
dependencies = [
"heck 0.5.0",
"proc-macro2",
"quote",
"syn 2.0.104",
]
[[package]]
name = "tauri-utils"
version = "2.5.0"

View File

@@ -18,9 +18,12 @@ crate-type = ["staticlib", "cdylib", "rlib"]
tauri-build = { version = "2", features = [] }
[dependencies]
tauri = { version = "2", features = [] }
tauri = { version = "2.0", features = [] }
tauri-plugin-opener = "2"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
ffprobe = "0.4.0"
specta = "=2.0.0-rc.22"
specta-typescript = "0.0.9"
tauri-specta = { version = "=2.0.0-rc.21", features = ["derive", "typescript"] }

View File

@@ -1,34 +1,91 @@
use serde::{Deserialize, Serialize};
use specta::Type;
use specta_typescript::Typescript;
use std::path::Path;
use tauri_specta::{collect_commands, Builder};
#[derive(Serialize, Deserialize, Debug, Clone, Type)]
struct StreamResult {
path: String,
filename: String,
streams: Vec<StreamDetail>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Type)]
enum StreamDetail {
Video { codec: String },
Audio { codec: String },
Subtitle { codec: String },
}
#[derive(Serialize, Deserialize, Debug, Clone, Type)]
struct StreamResultError {
filename: Option<String>,
reason: String,
}
#[tauri::command]
fn has_streams(paths: Vec<String>) -> Result<Vec<bool>, String> {
let mut results = Vec::with_capacity(paths.len());
for path_str in paths {
let path = Path::new(&path_str);
if !path.is_file() {
results.push(false);
continue;
}
#[specta::specta]
fn has_streams(paths: Vec<String>) -> Result<Vec<StreamResult>, StreamResultError> {
paths
.into_iter()
.map(|path_str| {
let path = Path::new(&path_str);
let filename = path.file_name().unwrap().to_str().unwrap().to_string();
match ffprobe::ffprobe(&path_str) {
Ok(info) => {
dbg!(info);
results.push(true);
},
Err(err) => {
eprintln!("Could not analyze file with ffprobe: {:?}", err);
results.push(false);
if !path.exists() {
return Err(StreamResultError {
filename: Some(filename),
reason: "File does not exist".to_string(),
});
}
}
}
Ok(results)
if !path.is_file() {
return Err(StreamResultError {
filename: Some(filename),
reason: "Not a file".to_string(),
});
}
match ffprobe::ffprobe(&path_str) {
Ok(info) => {
dbg!(info);
Ok(StreamResult {
filename,
path: path_str,
streams: vec![],
})
}
Err(err) => {
eprintln!("Could not analyze file with ffprobe: {:?}", err);
Err(StreamResultError {
filename: Some(filename),
reason: "Could not analyze file with ffprobe".to_string(),
})
}
}
})
.collect::<Result<Vec<_>, _>>()
}
#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
let builder = Builder::<tauri::Wry>::new()
// Then register them (separated by a comma)
.commands(collect_commands![has_streams,]);
#[cfg(debug_assertions)] // <- Only export on non-release builds
builder
.export(Typescript::default(), "../src/bindings.ts")
.expect("Failed to export typescript bindings");
tauri::Builder::default()
.plugin(tauri_plugin_opener::init())
.invoke_handler(tauri::generate_handler![has_streams])
.setup(move |app| {
// Ensure you mount your events!
builder.mount_events(app);
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}