|
4 | 4 |
|
5 | 5 | //! Platform helper functions. |
6 | 6 |
|
7 | | -use std::{ |
8 | | - fmt::Display, |
9 | | - path::{Path, PathBuf, MAIN_SEPARATOR}, |
10 | | -}; |
| 7 | +use std::{fmt::Display, path::PathBuf}; |
11 | 8 |
|
12 | 9 | use serde::{Deserialize, Serialize}; |
13 | 10 |
|
14 | 11 | use crate::{Env, PackageInfo}; |
15 | 12 |
|
16 | 13 | mod starting_binary; |
17 | 14 |
|
| 15 | +/// URI prefix of a Tauri asset. |
| 16 | +/// |
| 17 | +/// This is referenced in the Tauri Android library, |
| 18 | +/// which resolves these assets to a file descriptor. |
18 | 19 | #[cfg(target_os = "android")] |
19 | 20 | pub const ANDROID_ASSET_PROTOCOL_URI_PREFIX: &str = "asset://localhost/"; |
20 | 21 |
|
@@ -225,16 +226,16 @@ pub fn target_triple() -> crate::Result<String> { |
225 | 226 | Ok(format!("{arch}-{os}")) |
226 | 227 | } |
227 | 228 |
|
228 | | -#[cfg(not(test))] |
229 | | -fn is_cargo_output_directory(path: &Path) -> bool { |
| 229 | +#[cfg(all(not(test), not(target_os = "android")))] |
| 230 | +fn is_cargo_output_directory(path: &std::path::Path) -> bool { |
230 | 231 | path.join(".cargo-lock").exists() |
231 | 232 | } |
232 | 233 |
|
233 | 234 | #[cfg(test)] |
234 | 235 | const CARGO_OUTPUT_DIRECTORIES: &[&str] = &["debug", "release", "custom-profile"]; |
235 | 236 |
|
236 | 237 | #[cfg(test)] |
237 | | -fn is_cargo_output_directory(path: &Path) -> bool { |
| 238 | +fn is_cargo_output_directory(path: &std::path::Path) -> bool { |
238 | 239 | let last_component = path |
239 | 240 | .components() |
240 | 241 | .last() |
@@ -265,21 +266,30 @@ fn is_cargo_output_directory(path: &Path) -> bool { |
265 | 266 | /// Android uses a special URI prefix that is resolved by the Tauri file system plugin `asset://localhost/` |
266 | 267 | pub fn resource_dir(package_info: &PackageInfo, env: &Env) -> crate::Result<PathBuf> { |
267 | 268 | #[cfg(target_os = "android")] |
268 | | - return Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX)); |
269 | | - let exe = current_exe()?; |
270 | | - resource_dir_from(exe, package_info, env) |
| 269 | + return resource_dir_android(package_info, env); |
| 270 | + #[cfg(not(target_os = "android"))] |
| 271 | + { |
| 272 | + let exe = current_exe()?; |
| 273 | + resource_dir_from(exe, package_info, env) |
| 274 | + } |
| 275 | +} |
| 276 | + |
| 277 | +#[cfg(target_os = "android")] |
| 278 | +fn resource_dir_android(_package_info: &PackageInfo, _env: &Env) -> crate::Result<PathBuf> { |
| 279 | + Ok(PathBuf::from(ANDROID_ASSET_PROTOCOL_URI_PREFIX)) |
271 | 280 | } |
272 | 281 |
|
| 282 | +#[cfg(not(target_os = "android"))] |
273 | 283 | #[allow(unused_variables)] |
274 | | -fn resource_dir_from<P: AsRef<Path>>( |
| 284 | +fn resource_dir_from<P: AsRef<std::path::Path>>( |
275 | 285 | exe: P, |
276 | 286 | package_info: &PackageInfo, |
277 | 287 | env: &Env, |
278 | 288 | ) -> crate::Result<PathBuf> { |
279 | 289 | let exe_dir = exe.as_ref().parent().expect("failed to get exe directory"); |
280 | 290 | let curr_dir = exe_dir.display().to_string(); |
281 | 291 |
|
282 | | - let parts: Vec<&str> = curr_dir.split(MAIN_SEPARATOR).collect(); |
| 292 | + let parts: Vec<&str> = curr_dir.split(std::path::MAIN_SEPARATOR).collect(); |
283 | 293 | let len = parts.len(); |
284 | 294 |
|
285 | 295 | // Check if running from the Cargo output directory, which means it's an executable in a development machine |
|
0 commit comments