Hey
I'm trying to use custom protocol in macOS to load local resources.
However it crash once the request is made
Crash:
mounted request
thread 'main' panicked at src/lib.rs:8:50:
called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
fatal runtime error: failed to initiate panic, error 5
Code
use std::{fs, str::FromStr};
use tauri::{Url, WebviewWindow};
pub fn run() {
tauri::Builder::default()
.register_uri_scheme_protocol("mounted", move |app, request| {
println!("mounted request");
let content = fs::read("index.html").unwrap();
tauri::http::Response::builder()
.status(200)
.header("Content-Type", "text/html")
.body(content)
.unwrap()
})
.setup(|app| {
WebviewWindow::builder(
app,
"main",
tauri::WebviewUrl::External(Url::from_str("mounted://hello").unwrap()),
)
.build()
.unwrap();
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
It only crash if I read the file there. Maybe memory (drop) issues?
Another issue: if the URL doesn't have path eg only mounted:// the custom protocol handler not being called. I think it should act as / path