| 132 | 132 | | matches!(url.scheme(), "http" | "https") && origin(url) == origin(&server(app)) |
| 133 | 133 | | } |
| 134 | 134 | | |
| 135 | + | /// Where the bundled pages are served under `tauri dev`: with no `devUrl` |
| 136 | + | /// in tauri.conf.json, the Tauri CLI serves `launcher/` itself, from |
| 137 | + | /// localhost, and the window starts there. Unset in a release build, which |
| 138 | + | /// serves them from inside the app. |
| 139 | + | static DEV_SERVER: std::sync::OnceLock<Option<Url>> = std::sync::OnceLock::new(); |
| 140 | + | |
| 141 | + | /// Notes the dev server, once, as the app starts. |
| 142 | + | pub fn note_dev_server(app: &AppHandle) { |
| 143 | + | let dev = if cfg!(debug_assertions) { app.config().build.dev_url.clone() } else { None }; |
| 144 | + | let _ = DEV_SERVER.set(dev); |
| 145 | + | } |
| 146 | + | |
| 147 | + | pub fn dev_server() -> Option<&'static Url> { |
| 148 | + | DEV_SERVER.get().and_then(Option::as_ref) |
| 149 | + | } |
| 150 | + | |
| 135 | 151 | | /// Whether a page is the launcher, bundled with the app. |
| 136 | 152 | | pub fn is_launcher(url: &Url) -> bool { |
| 137 | | − | url.scheme() == "tauri" || (matches!(url.scheme(), "http" | "https") && url.host_str() == Some("tauri.localhost")) |
| 153 | + | url.scheme() == "tauri" |
| 154 | + | || (matches!(url.scheme(), "http" | "https") && url.host_str() == Some("tauri.localhost")) |
| 155 | + | || dev_server().is_some_and(|dev| origin(dev) == origin(url)) |
| 138 | 156 | | } |
| 139 | 157 | | |
| 140 | 158 | | /// What the server's pages may call: the bridge's commands (bridge.rs). |