#I don't understand how to use PathResolver and AssetResolver
47 messages · Page 1 of 1 (latest)
you need to get them via asset_resolver() and path_resolver() from the App or AppHandle
ohhh
I have a text file with an image stored in base64 and I wanted to read the text. For some reason, I got the html of my frontend with this code:
let asset_resolver = app.asset_resolver();
let text = asset_resolver.get("assets/icon_base64.txt".into());
match text {
Some(text) => {
let bytes = text.bytes;
let str = match String::from_utf8(bytes) {
Ok(v) => v,
Err(err) => panic!("Invalid UTF-8 sequence: {err:#?}"),
};
println!("result: {}", str);
}
None => println!("No text found"),
}
result: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body style="margin: 0%;">
<script type="module" src="/scripts/index.js" defer></script>
<link rel="stylesheet" href="styles/style.css">
<div id="main_div"
style="position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);text-align: center;">
<a id="progress_text" style="font-size: 4vw;"></a>
<div id="border_div"
style="margin-top:1.3vw; border:#FBF5F3; border-width: 1.8vh; border-style: solid; width: 70vw; height: 5vh;">
<div id="progress_bar" style="background-color: #004FFF; width:0%; height:100%"></div>
</div>
<a class="error_text" id="error_text" style="margin-top: 1.3vw; display:block;"></a>
</div>
</body>
</html>```
Btw, do you automatically get notifications or do I need to ping you in threads? @gloomy stag
I just realised what happened after removing the println!.
ssets/icon_base64.txt??
i get notifications for everything, or if not, i still see discord's unread messages thingy
nice
oh yeah, i remember that. because assetresolver is actually used internally for serving your frontend it expects a / in front and always removes the first char without checking what specific char it is
it really is
maybe a different error when it doesn't have / in front?
also since we're on the topic of these messages, is there any way to make it stop searching for favicon.ico?
yeah idk, exposing AssetResolver as-is was maybe not the best idea lol
No that's a webview/browser thing. they always search for it for some reason
ah
well that's sad
what if I name my icon favicon.ico?
I think it's called transparentcon.ico right now
yeah that would "fix" it
Hmm
it still can't find the asset
Am I supposed to specify an assets folder somewhere?
the assetresolver server whatever is in your distDir, with the same directory structure
ohh, just noticed that it's inside your backend source
my distDir is ./ui
and my devPath is the same
I guess I could change distDir to ./assets
you're probably looking for https://doc.rust-lang.org/std/macro.include_str.html instead in this case, since assetresolver is only used to access your frontend files
no don't, that will break your app. distDir must point to your frontend
what if i just put the text in ui?
oh
then you could access it with pathresolver too, correct
nice
but it still doesn't work
hmmmmmmmmm
the specified path is /assets/icon_base64.txt
and the file is in ui/assets/icon_base64.txt ?
okay 
This just worked, but i'm concerned about not being able to include assets in the frontend either