Przeglądaj źródła

feat(core): set macOS app bundle name in development (#4381)

Lucas Fernandes Nogueira 3 lat temu
rodzic
commit
7be997b974

+ 7 - 0
.changes/dev-app-name.md

@@ -0,0 +1,7 @@
+---
+"tauri-codegen": patch
+"tauri-macros": patch
+"tauri": patch
+---
+
+Set the bundle name in the Info.plist file in development mode.

+ 3 - 0
core/tauri-codegen/Cargo.toml

@@ -29,6 +29,9 @@ semver = "1"
 ico = "0.1"
 png = "0.17"
 
+[target."cfg(target_os = \"macos\")".dependencies]
+plist = "1"
+
 [features]
 default = [ "compression" ]
 compression = [ "brotli", "tauri-utils/compression" ]

+ 20 - 6
core/tauri-codegen/src/context.rs

@@ -261,14 +261,28 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
   let info_plist = {
     if dev {
       let info_plist_path = config_parent.join("Info.plist");
-      if info_plist_path.exists() {
-        let info_plist_path = info_plist_path.display().to_string();
-        quote!({
-          tauri::embed_plist::embed_info_plist!(#info_plist_path);
-        })
+      let mut info_plist = if info_plist_path.exists() {
+        plist::Value::from_file(&info_plist_path)
+          .unwrap_or_else(|e| panic!("failed to read plist {}: {}", info_plist_path.display(), e))
       } else {
-        quote!(())
+        plist::Value::Dictionary(Default::default())
+      };
+
+      if let Some(dict) = info_plist.as_dictionary_mut() {
+        if let Some(product_name) = &config.package.product_name {
+          dict.insert("CFBundleName".into(), product_name.clone().into());
+        }
       }
+
+      let out_path = out_dir.join("Info.plist");
+      info_plist
+        .to_file_xml(&out_path)
+        .expect("failed to write Info.plist");
+
+      let info_plist_path = out_path.display().to_string();
+      quote!({
+        tauri::embed_plist::embed_info_plist!(#info_plist_path);
+      })
     } else {
       quote!(())
     }

+ 30 - 0
examples/api/src-tauri/Cargo.lock

@@ -1622,6 +1622,15 @@ dependencies = [
  "winapi",
 ]
 
+[[package]]
+name = "line-wrap"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9"
+dependencies = [
+ "safemem",
+]
+
 [[package]]
 name = "lock_api"
 version = "0.4.7"
@@ -2289,6 +2298,20 @@ version = "0.3.25"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
 
+[[package]]
+name = "plist"
+version = "1.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd39bc6cdc9355ad1dc5eeedefee696bb35c34caf21768741e81826c0bbd7225"
+dependencies = [
+ "base64",
+ "indexmap",
+ "line-wrap",
+ "serde",
+ "time",
+ "xml-rs",
+]
+
 [[package]]
 name = "png"
 version = "0.11.0"
@@ -2634,6 +2657,12 @@ version = "1.0.10"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695"
 
+[[package]]
+name = "safemem"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
+
 [[package]]
 name = "same-file"
 version = "1.0.6"
@@ -3193,6 +3222,7 @@ dependencies = [
  "base64",
  "brotli",
  "ico",
+ "plist",
  "png 0.17.5",
  "proc-macro2",
  "quote",

+ 1 - 0
tooling/bundler/src/bundle/macos/app.rs

@@ -237,6 +237,7 @@ fn create_info_plist(
   file.flush()?;
 
   if let Some(user_plist_path) = &settings.macos().info_plist_path {
+    // TODO: use the plist crate instead
     Command::new("/usr/libexec/PlistBuddy")
       .args(&[
         "-c".into(),