Seems like there is no Server for external files ? #10
Replies: 1 comment
-
hey! this library isn't supposed to be a full web framework for plugins, but just the bare minimum needed to run a browser inside a plugin and communicate with it efficiently. that being said, it should be pretty straightforward to use this library with a development server - you'll just have to start the server yourself. of course, when distributing your plugin you'll want to bundle the entire web app in a way that doesn't require a server. this is what i'm doing in a project of mine currently: #[cfg(debug_assertions)]
let src = HTMLSource::URL("http://localhost:3000");
#[cfg(not(debug_assertions))]
let src = HTMLSource::String(include_str!("../../ui/dist/index.html"));
let editor = WebViewEditor::new(src, (950, 780)) so in development builds it's loading the page running on localhost via the URL. but when building a release build (with cargo's if you don't want to bundle everything into a single file in release builds, you could also use a custom protocol to load your assets: static WEB_ASSETS: Dir<'_> = include_dir!("../ui/dist/assets");
...
.with_custom_protocol("webview".to_owned(), |req| {
if let Some(file) = WEB_ASSETS.get_file(req.uri().path().trim_start_matches("/")) {
return Response::builder()
.header(
"content-type",
match file.path().extension().unwrap().to_str().unwrap() {
"js" => "text/javascript",
"css" => "text/css",
"ttf" => "font/ttf",
_ => "",
},
)
.header("Access-Control-Allow-Origin", "*")
.body(file.contents().into())
.map_err(Into::into);
}
panic!("Web asset not found.")
})
... with this code, the closure passed to anyway, if you just want to play around you could just use development server and worry about release builds later: let editor = WebViewEditor::new(HTMLSource::URL("http://localhost:3000"), (950, 780)) hope this helps! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am interested in your work on this nih webview demo.
I am a noobie at Rust and I’d like to find out how to do this...
I am trying to point line 134 of your lib.rs to my own index.html from an angular app.
let editor = WebViewEditor::new(HTMLSource::String(include_str!("dist/index.html")), (200, 200))…….
it is an angular app and here are the errors I’m getting:

It’s loading the index.html but it’s not getting the included files because “localhost” doesn’t seem active ?
I’m not the best rust programmer, but shouldn’t there be a web server (Tauri) underneath ?
Beta Was this translation helpful? Give feedback.
All reactions