fix: asset protocol CORS on Windows

This commit is contained in:
Lucas Nogueira 2021-12-13 14:37:37 -03:00
parent 26dab690b7
commit d56a7fc7f7
No known key found for this signature in database
GPG Key ID: D59F1874CB5198CF

View File

@ -304,16 +304,21 @@ impl<R: Runtime> WindowManager<R> {
}
if !registered_scheme_protocols.contains(&"asset".into()) {
let window_url = Url::parse(&pending.url).unwrap();
let window_origin = format!(
"{}://{}{}",
window_url.scheme(),
window_url.host().unwrap(),
if let Some(port) = window_url.port() {
format!(":{}", port)
let window_origin =
if cfg!(windows) && window_url.scheme() != "http" && window_url.scheme() != "https" {
format!("https://{}.localhost", window_url.scheme())
} else {
"".into()
}
);
format!(
"{}://{}{}",
window_url.scheme(),
window_url.host().unwrap(),
if let Some(port) = window_url.port() {
format!(":{}", port)
} else {
"".into()
}
)
};
pending.register_uri_scheme_protocol("asset", move |request| {
#[cfg(target_os = "windows")]
let path = request.uri().replace("asset://localhost/", "");