2024-02-14 20:33:07 +00:00
|
|
|
//! This example shows how to load in custom assets with the use_asset_handler hook.
|
|
|
|
//!
|
|
|
|
//! This hook is currently only available on desktop and allows you to intercept any request made by the webview
|
|
|
|
//! and respond with your own data. You could use this to load in custom videos, streams, stylesheets, images,
|
|
|
|
//! or any asset that isn't known at compile time.
|
|
|
|
|
2024-01-20 00:36:40 +00:00
|
|
|
use dioxus::desktop::{use_asset_handler, wry::http::Response};
|
2023-12-17 23:14:55 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
2024-07-25 21:58:00 +00:00
|
|
|
const STYLE: &str = asset!("./examples/assets/custom_assets.css");
|
2024-07-23 17:29:37 +00:00
|
|
|
|
2023-12-17 23:14:55 +00:00
|
|
|
fn main() {
|
2024-01-16 17:45:02 +00:00
|
|
|
launch_desktop(app);
|
2023-12-17 23:14:55 +00:00
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
|
|
|
use_asset_handler("logos", |request, response| {
|
2024-01-21 21:38:25 +00:00
|
|
|
// We get the original path - make sure you handle that!
|
|
|
|
if request.uri().path() != "/logos/logo.png" {
|
2024-01-06 02:08:04 +00:00
|
|
|
return;
|
2023-12-17 23:14:55 +00:00
|
|
|
}
|
2024-01-06 02:08:04 +00:00
|
|
|
|
|
|
|
response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
|
2023-12-17 23:14:55 +00:00
|
|
|
});
|
|
|
|
|
2024-01-16 19:18:46 +00:00
|
|
|
rsx! {
|
2024-07-25 21:58:00 +00:00
|
|
|
head::Link { rel: "stylesheet", href: STYLE }
|
2024-02-14 20:33:07 +00:00
|
|
|
h1 { "Dynamic Assets" }
|
|
|
|
img { src: "/logos/logo.png" }
|
2024-01-11 20:11:27 +00:00
|
|
|
}
|
2023-12-17 23:14:55 +00:00
|
|
|
}
|