|
@@ -42,6 +42,7 @@ use std::{
|
|
sync::{Arc, Mutex, MutexGuard},
|
|
sync::{Arc, Mutex, MutexGuard},
|
|
};
|
|
};
|
|
use tauri_macros::default_runtime;
|
|
use tauri_macros::default_runtime;
|
|
|
|
+use url::Url;
|
|
use uuid::Uuid;
|
|
use uuid::Uuid;
|
|
|
|
|
|
const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
|
|
const WINDOW_RESIZED_EVENT: &str = "tauri://resize";
|
|
@@ -180,20 +181,27 @@ impl<R: Runtime> WindowManager<R> {
|
|
self.inner.menu_ids.clone()
|
|
self.inner.menu_ids.clone()
|
|
}
|
|
}
|
|
|
|
|
|
- // setup content for dev-server
|
|
|
|
|
|
+ /// Get the base path to serve data from.
|
|
|
|
+ ///
|
|
|
|
+ /// * In dev mode, this will be based on the `devPath` configuration value.
|
|
|
|
+ /// * Otherwise, this will be based on the `distDir` configuration value.
|
|
|
|
+ #[cfg(custom_protocol)]
|
|
|
|
+ fn base_path(&self) -> &AppUrl {
|
|
|
|
+ &self.inner.config.build.dist_dir
|
|
|
|
+ }
|
|
|
|
+
|
|
#[cfg(dev)]
|
|
#[cfg(dev)]
|
|
- fn get_url(&self) -> String {
|
|
|
|
- match &self.inner.config.build.dev_path {
|
|
|
|
- AppUrl::Url(WindowUrl::External(url)) => url.to_string(),
|
|
|
|
- _ => "tauri://localhost".into(),
|
|
|
|
- }
|
|
|
|
|
|
+ fn base_path(&self) -> &AppUrl {
|
|
|
|
+ &self.inner.config.build.dev_path
|
|
}
|
|
}
|
|
|
|
|
|
- #[cfg(custom_protocol)]
|
|
|
|
- fn get_url(&self) -> String {
|
|
|
|
- match &self.inner.config.build.dist_dir {
|
|
|
|
- AppUrl::Url(WindowUrl::External(url)) => url.to_string(),
|
|
|
|
- _ => "tauri://localhost".into(),
|
|
|
|
|
|
+ /// Get the base URL to use for webview requests.
|
|
|
|
+ ///
|
|
|
|
+ /// In dev mode, this will be based on the `devPath` configuration value.
|
|
|
|
+ fn get_url(&self) -> Cow<'_, Url> {
|
|
|
|
+ match self.base_path() {
|
|
|
|
+ AppUrl::Url(WindowUrl::External(url)) => Cow::Borrowed(url),
|
|
|
|
+ _ => Cow::Owned(Url::parse("tauri://localhost").unwrap()),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -505,10 +513,10 @@ mod test {
|
|
);
|
|
);
|
|
|
|
|
|
#[cfg(custom_protocol)]
|
|
#[cfg(custom_protocol)]
|
|
- assert_eq!(manager.get_url(), "tauri://localhost");
|
|
|
|
|
|
+ assert_eq!(manager.get_url().to_string(), "tauri://localhost");
|
|
|
|
|
|
#[cfg(dev)]
|
|
#[cfg(dev)]
|
|
- assert_eq!(manager.get_url(), "http://localhost:4000/");
|
|
|
|
|
|
+ assert_eq!(manager.get_url().to_string(), "http://localhost:4000/");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -561,13 +569,16 @@ impl<R: Runtime> WindowManager<R> {
|
|
true,
|
|
true,
|
|
// ignore "index.html" just to simplify the url
|
|
// ignore "index.html" just to simplify the url
|
|
if path.to_str() != Some("index.html") {
|
|
if path.to_str() != Some("index.html") {
|
|
- format!("{}/{}", url, path.to_string_lossy())
|
|
|
|
- } else {
|
|
|
|
url
|
|
url
|
|
|
|
+ .join(&*path.to_string_lossy())
|
|
|
|
+ .map_err(crate::Error::InvalidUrl)?
|
|
|
|
+ .to_string()
|
|
|
|
+ } else {
|
|
|
|
+ url.to_string()
|
|
},
|
|
},
|
|
)
|
|
)
|
|
}
|
|
}
|
|
- WindowUrl::External(url) => (url.as_str().starts_with("tauri://"), url.to_string()),
|
|
|
|
|
|
+ WindowUrl::External(url) => (url.scheme() == "tauri", url.to_string()),
|
|
_ => unimplemented!(),
|
|
_ => unimplemented!(),
|
|
};
|
|
};
|
|
|
|
|