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

This commit is contained in:
Lucas Fernandes Nogueira 2022-08-24 12:41:57 -03:00 committed by GitHub
parent 1f84385e8a
commit 0500d3b4b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 9 deletions

View File

@ -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"));

View File

@ -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()

View File

@ -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<()>;

View File

@ -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};

View File

@ -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)

View File

@ -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();