complete Tauri v2 port with runtime fixes

This commit is contained in:
2026-02-19 12:44:57 +02:00
parent 61379d9b64
commit 1d6d761a63
22 changed files with 11665 additions and 5408 deletions

View File

@@ -2,7 +2,7 @@
use std::sync::Mutex;
use tauri::Manager;
use tutorialdock_lib::{commands, ffmpeg, fonts, library, prefs, video_protocol, AppPaths};
use tutorialvault_lib::{commands, ffmpeg, fonts, library, prefs, video_protocol, AppPaths};
fn main() {
// 1. Resolve exe directory for portability.
@@ -41,6 +41,7 @@ fn main() {
// Discover ffmpeg/ffprobe.
let ff_paths = ffmpeg::discover(&paths.exe_dir, &paths.state_dir);
let needs_ffmpeg_download = ff_paths.ffprobe.is_none() || ff_paths.ffmpeg.is_none();
lib.ffprobe = ff_paths.ffprobe;
lib.ffmpeg = ff_paths.ffmpeg;
@@ -91,22 +92,22 @@ fn main() {
// Configure window from saved prefs and launch.
builder
.setup(|app| {
.setup(move |app| {
let prefs_state = app.state::<Mutex<prefs::Prefs>>();
let p = prefs_state.lock().unwrap();
let win = app.get_webview_window("main").unwrap();
if let Some(x) = p.window.x {
if let Some(y) = p.window.y {
// Only restore position/size if values are sane (not minimized/offscreen).
let w = p.window.width.max(640) as u32;
let h = p.window.height.max(480) as u32;
if let (Some(x), Some(y)) = (p.window.x, p.window.y) {
if x > -10000 && y > -10000 && x < 10000 && y < 10000 {
let _ = win.set_position(tauri::Position::Physical(
tauri::PhysicalPosition::new(x, y),
));
}
}
let _ = win.set_size(tauri::Size::Physical(tauri::PhysicalSize::new(
p.window.width as u32,
p.window.height as u32,
)));
let _ = win.set_size(tauri::Size::Physical(tauri::PhysicalSize::new(w, h)));
let _ = win.set_always_on_top(p.always_on_top);
drop(p);
@@ -119,6 +120,32 @@ fn main() {
let _ = fonts::ensure_fontawesome_local(&fa_dir).await;
});
// Auto-download ffmpeg/ffprobe if not found locally.
if needs_ffmpeg_download {
let handle = app.handle().clone();
tauri::async_runtime::spawn(async move {
let sd = handle.state::<AppPaths>().state_dir.clone();
let (tx, _rx) = tokio::sync::mpsc::channel(16);
match ffmpeg::download_ffmpeg(&sd, tx).await {
Ok(paths) => {
let lib_state = handle.state::<Mutex<library::Library>>();
if let Ok(mut lib) = lib_state.lock() {
if lib.ffprobe.is_none() {
lib.ffprobe = paths.ffprobe;
}
if lib.ffmpeg.is_none() {
lib.ffmpeg = paths.ffmpeg;
}
}
eprintln!("[ffmpeg] Auto-download complete");
}
Err(e) => {
eprintln!("[ffmpeg] Auto-download failed: {}", e);
}
}
});
}
Ok(())
})
.run(tauri::generate_context!())