From 0500d3b4b1ba03804981e74be28488fd21572b27 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Wed, 24 Aug 2022 12:41:57 -0300 Subject: [PATCH] fix(core): mobile app name must match the crate name (#5027) --- core/tauri-build/src/lib.rs | 6 +----- core/tauri-macros/src/mobile.rs | 2 +- tooling/cli/src/interface/mod.rs | 2 +- tooling/cli/src/interface/rust.rs | 2 +- tooling/cli/src/interface/rust/manifest.rs | 2 +- tooling/cli/src/mobile/mod.rs | 14 ++++++++++++++ 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/tauri-build/src/lib.rs b/core/tauri-build/src/lib.rs index 98ad640ae..7b9723668 100644 --- a/core/tauri-build/src/lib.rs +++ b/core/tauri-build/src/lib.rs @@ -221,19 +221,15 @@ pub fn try_build(attributes: Attributes) -> Result<()> { let s = config.tauri.bundle.identifier.split('.'); let last = s.clone().count() - 1; - let mut app_name = String::new(); let mut domain = String::new(); for (i, w) in s.enumerate() { - if i == last { - app_name.push_str(w); - } else { + if i != last { domain.push_str(w); domain.push('_'); } } domain.pop(); println!("cargo:rustc-env=TAURI_ANDROID_DOMAIN={}", domain); - println!("cargo:rustc-env=TAURI_ANDROID_APP_NAME={}", app_name); cfg_alias("dev", !has_feature("custom-protocol")); diff --git a/core/tauri-macros/src/mobile.rs b/core/tauri-macros/src/mobile.rs index e98b647de..3bd170075 100644 --- a/core/tauri-macros/src/mobile.rs +++ b/core/tauri-macros/src/mobile.rs @@ -32,7 +32,7 @@ pub fn entry_point(_attributes: TokenStream, item: TokenStream) -> TokenStream { let mut error = None; let domain = get_env_var("TAURI_ANDROID_DOMAIN", &mut error, &function); - let app_name = get_env_var("TAURI_ANDROID_APP_NAME", &mut error, &function); + let app_name = get_env_var("CARGO_PKG_NAME", &mut error, &function); if let Some(e) = error { quote!(#e).into() diff --git a/tooling/cli/src/interface/mod.rs b/tooling/cli/src/interface/mod.rs index e946f071d..178eead72 100644 --- a/tooling/cli/src/interface/mod.rs +++ b/tooling/cli/src/interface/mod.rs @@ -12,7 +12,7 @@ use std::{ use crate::helpers::config::Config; use tauri_bundler::bundle::{PackageType, Settings, SettingsBuilder}; -pub use rust::{MobileOptions, Options, Rust as AppInterface}; +pub use rust::{manifest, MobileOptions, Options, Rust as AppInterface}; pub trait DevProcess { fn kill(&mut self) -> std::io::Result<()>; diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 0357934fc..bd4692658 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/tooling/cli/src/interface/rust.rs @@ -36,7 +36,7 @@ use crate::helpers::{ mod cargo_config; mod desktop; -mod manifest; +pub mod manifest; use cargo_config::Config as CargoConfig; use manifest::{rewrite_manifest, Manifest}; diff --git a/tooling/cli/src/interface/rust/manifest.rs b/tooling/cli/src/interface/rust/manifest.rs index d19ad8370..3b257edba 100644 --- a/tooling/cli/src/interface/rust/manifest.rs +++ b/tooling/cli/src/interface/rust/manifest.rs @@ -82,7 +82,7 @@ fn get_enabled_features(list: &HashMap>, feature: &str) -> V f } -fn read_manifest(manifest_path: &Path) -> crate::Result { +pub fn read_manifest(manifest_path: &Path) -> crate::Result { let mut manifest_str = String::new(); let mut manifest_file = File::open(manifest_path) diff --git a/tooling/cli/src/mobile/mod.rs b/tooling/cli/src/mobile/mod.rs index ee2de83b9..f3ddea067 100644 --- a/tooling/cli/src/mobile/mod.rs +++ b/tooling/cli/src/mobile/mod.rs @@ -147,6 +147,20 @@ fn get_config(config: &TauriConfig) -> (Config, Metadata) { } domain.pop(); + let manifest_path = tauri_dir().join("Cargo.toml"); + let app_name = if let Ok(manifest) = crate::interface::manifest::read_manifest(&manifest_path) { + manifest + .as_table() + .get("package") + .and_then(|p| p.as_table()) + .and_then(|p| p.get("name")) + .and_then(|n| n.as_str()) + .map(|n| n.to_string()) + .unwrap_or(app_name) + } else { + app_name + }; + #[cfg(target_os = "macos")] let ios_options = read_options(config, Target::Ios).unwrap_or_default(); let android_options = read_options(config, Target::Android).unwrap_or_default();