Pārlūkot izejas kodu

fix(core): mobile app name must match the crate name (#5027)

Lucas Fernandes Nogueira 3 gadi atpakaļ
vecāks
revīzija
0500d3b4b1

+ 1 - 5
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"));
 

+ 1 - 1
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()

+ 1 - 1
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<()>;

+ 1 - 1
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};
 

+ 1 - 1
tooling/cli/src/interface/rust/manifest.rs

@@ -82,7 +82,7 @@ fn get_enabled_features(list: &HashMap<String, Vec<String>>, feature: &str) -> V
   f
 }
 
-fn read_manifest(manifest_path: &Path) -> crate::Result<Document> {
+pub fn read_manifest(manifest_path: &Path) -> crate::Result<Document> {
   let mut manifest_str = String::new();
 
   let mut manifest_file = File::open(manifest_path)

+ 14 - 0
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();