今日已更新 80 条资讯 | 累计 20052 条内容
关于我们

QuickLook Integration in a Tauri App — Native macOS File Preview

hiyoyo 2026年06月05日 11:36 4 次阅读 来源:Dev.to

All tests run on an 8-year-old MacBook Air. All results from shipping 7 Mac apps as a solo developer. No sponsored opinion. HiyokoKit's MTP file manager includes QuickLook preview. Press Space, see the file. Native macOS behavior in a Tauri app. Here's how it works — and why it's worth doing. What QuickLook Is QuickLook is macOS's built-in file preview system. Press Space on any file in Finder — that's QuickLook. It handles images, PDFs, videos, and documents without opening separate apps. For a file manager, QuickLook preview is table stakes on macOS. Users expect it. If it's missing, the app feels unfinished. Triggering QuickLook from Rust The qlmanage command-line tool can trigger QuickLook from any process: use std :: process :: Command ; #[tauri::command] async fn preview_file ( file_path : String ) -> Result < (), AppError > { Command :: new ( "qlmanage" ) .args ([ "-p" , & file_path ]) .spawn () .map_err (| e | AppError :: Preview ( e .to_string ())) ? ; Ok (()) } qlmanage -p opens a native QuickLook preview window for the specified path. That's it on the Rust side for local files. For MTP Files: Download First, Preview, Cleanup Files on an Android device don't have a local path — they live on the device over MTP. The flow is: download to a temp file → preview → clean up. #[tauri::command] async fn preview_mtp_file ( device_path : String , filename : String , ) -> Result < (), AppError > { // Download to temp let temp_path = std :: env :: temp_dir () .join ( & filename ); download_from_device ( & device_path , & temp_path ) .await ? ; // Open QuickLook Command :: new ( "qlmanage" ) .args ([ "-p" , temp_path .to_str () .unwrap ()]) .spawn () ? ; // Schedule cleanup after delay let temp_clone = temp_path .clone (); tokio :: spawn ( async move { tokio :: time :: sleep ( Duration :: from_secs ( 30 )) .await ; std :: fs :: remove_file ( temp_clone ) .ok (); }); Ok (()) } 30 seconds gives the user time to view before cleanup. For large files (RAW photos, videos), y

本文内容来源于互联网,版权归原作者所有
查看原文