Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bundler): add dmg settings, closes #4669 #7964

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

Andreybest
Copy link
Contributor

@Andreybest Andreybest commented Oct 5, 2023

Added new "dmg" param to tauri.conf.json. It provides more settings to "create-dmg" cli and allows to customise DMG files with:

  • background image
  • Installer window size
  • Installer window position
  • Application position
  • Application folder position

DMG view before:
image

DMG view after:
image

New part of tauri.conf.json looks like this:

{
  "tauri": {
    "bundle": {
      "dmg": {
        "background": "images/background.png",
        "appPosition": {
          "x": 180,
          "y": 170
        },
        "applicationFolderPosition": {
          "x": 480,
          "y": 170
        },
        "windowSize": {
          "height": 400,
          "width": 660
        },
        "windowPosition": {
          "x": 200,
          "y": 180
        }
      }
    }
  }
}

Resolves #4669

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Docs
  • New Binding issue #___
  • Code style update
  • Refactor
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes, and the changes were approved in issue #___
  • No

Checklist

  • When resolving issues, they are referenced in the PR's title (e.g fix: remove a typo, closes #___, #___)
  • A change file is added if any packages will require a version bump due to this PR per the instructions in the readme.
  • I have added a convincing reason for adding this feature, if necessary

Other information

Small note. I've never used commit signing, but saw that it's required after creating PR (after first commit). So I have only 1 out of 2 commit signed, I hope it's not a big deal 🙂

@lucasfernog
Copy link
Member

@Andreybest this is looking amazing! I wanted to push a cleanup but I don't have access to your fork :D mostly fixing clippy warnings and using .to_string_lossy() on the dmg args.

diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs
index 185dd7bc7..10286331b 100644
--- a/core/tauri-utils/src/config.rs
+++ b/core/tauri-utils/src/config.rs
@@ -304,8 +304,6 @@ pub struct Size {
   pub height: u32,
 }
 
-
-
 /// Configuration for Apple Disk Image (.dmg) bundles.
 ///
 /// See more: https://tauri.app/v1/api/config#dmgconfig
@@ -319,20 +317,14 @@ pub struct DmgConfig {
   /// Position of volume window on screen.
   pub window_position: Option<Position>,
   /// Size of volume window.
-  #[serde(
-    default = "window_size",
-    alias = "window-size"
-  )]
+  #[serde(default = "dmg_window_size", alias = "window-size")]
   pub window_size: Size,
   /// Position of app file on window.
-  #[serde(
-    default = "app_position",
-    alias = "app-position"
-  )]
+  #[serde(default = "dmg_app_position", alias = "app-position")]
   pub app_position: Position,
   /// Position of application folder on window.
   #[serde(
-    default = "application_folder_position",
+    default = "dmg_application_folder_position",
     alias = "application-folder-position"
   )]
   pub application_folder_position: Position,
@@ -343,32 +335,26 @@ impl Default for DmgConfig {
     Self {
       background: None,
       window_position: None,
-      window_size: window_size(),
-      app_position: app_position(),
-      application_folder_position: application_folder_position(),
+      window_size: dmg_window_size(),
+      app_position: dmg_app_position(),
+      application_folder_position: dmg_application_folder_position(),
     }
   }
 }
 
-fn window_size() -> Size {
+fn dmg_window_size() -> Size {
   Size {
     width: 660,
     height: 400,
   }
 }
 
-fn app_position() -> Position {
-  Position {
-    x: 180,
-    y: 170,
-  }
+fn dmg_app_position() -> Position {
+  Position { x: 180, y: 170 }
 }
 
-fn application_folder_position() -> Position {
-  Position {
-    x: 480,
-    y: 170,
-  }
+fn dmg_application_folder_position() -> Position {
+  Position { x: 480, y: 170 }
 }
 
 fn de_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
diff --git a/tooling/bundler/src/bundle/macos/dmg.rs b/tooling/bundler/src/bundle/macos/dmg.rs
index c5273f755..73cf62b7f 100644
--- a/tooling/bundler/src/bundle/macos/dmg.rs
+++ b/tooling/bundler/src/bundle/macos/dmg.rs
@@ -109,7 +109,9 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
   let window_size_width = window_size.width.to_string();
   let window_size_height = window_size.height.to_string();
 
-  let mut args = vec![
+  let mut bundle_dmg_cmd = Command::new(&bundle_script_path);
+
+  bundle_dmg_cmd.args([
     "--volname",
     product_name,
     "--icon",
@@ -124,71 +126,60 @@ pub fn bundle_project(settings: &Settings, bundles: &[Bundle]) -> crate::Result<
     &window_size_height,
     "--hide-extension",
     &bundle_file_name,
-  ];
+  ]);
 
-  let window_position = dmg_settings.window_position.as_ref().map(|position| {
-    (position.x.to_string(), position.y.to_string())
-  });
+  let window_position = dmg_settings
+    .window_position
+    .as_ref()
+    .map(|position| (position.x.to_string(), position.y.to_string()));
 
   if let Some(window_position) = &window_position {
-    args.push("--window-pos");
-    args.push(&window_position.0);
-    args.push(&window_position.1);
+    bundle_dmg_cmd.arg("--window-pos");
+    bundle_dmg_cmd.arg(&window_position.0);
+    bundle_dmg_cmd.arg(&window_position.1);
   }
 
-  let background_path_string = if let Some(background_path) = &dmg_settings.background {
-    Some(
-      env::current_dir()?
-        .join(background_path)
-        .to_string_lossy()
-        .to_string(),
-    )
+  let background_path = if let Some(background_path) = &dmg_settings.background {
+    Some(env::current_dir()?.join(background_path))
   } else {
     None
   };
 
-  if let Some(background_path_string) = &background_path_string {
-    args.push("--background");
-    args.push(background_path_string);
+  if let Some(background_path) = &background_path {
+    bundle_dmg_cmd.arg("--background");
+    bundle_dmg_cmd.arg(background_path);
   }
 
-  let icns_icon_path =
-    create_icns_file(&output_path, settings)?.map(|path| path.to_string_lossy().to_string());
+  let icns_icon_path = create_icns_file(&output_path, settings)?;
   if let Some(icon) = &icns_icon_path {
-    args.push("--volicon");
-    args.push(icon);
+    bundle_dmg_cmd.arg("--volicon");
+    bundle_dmg_cmd.arg(icon);
   }
 
-  let license_path_string = if let Some(license_path) = &settings.macos().license {
-    Some(
-      env::current_dir()?
-        .join(license_path)
-        .to_string_lossy()
-        .to_string(),
-    )
+  let license_path = if let Some(license_path) = &settings.macos().license {
+    Some(env::current_dir()?.join(license_path))
   } else {
     None
   };
 
-  if let Some(license_path) = &license_path_string {
-    args.push("--eula");
-    args.push(license_path);
+  if let Some(license_path) = &license_path {
+    bundle_dmg_cmd.arg("--eula");
+    bundle_dmg_cmd.arg(license_path);
   }
 
   // Issue #592 - Building MacOS dmg files on CI
   // https://github.com/tauri-apps/tauri/issues/592
   if let Some(value) = env::var_os("CI") {
     if value == "true" {
-      args.push("--skip-jenkins");
+      bundle_dmg_cmd.arg("--skip-jenkins");
     }
   }
 
   info!(action = "Running"; "bundle_dmg.sh");
 
   // execute the bundle script
-  Command::new(&bundle_script_path)
+  bundle_dmg_cmd
     .current_dir(bundle_dir.clone())
-    .args(args)
     .args(vec![dmg_name.as_str(), bundle_file_name.as_str()])
     .output_ok()
     .context("error running bundle_dmg.sh")?;
diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs
index c13d0bbdc..3885e6571 100644
--- a/tooling/cli/src/interface/rust.rs
+++ b/tooling/cli/src/interface/rust.rs
@@ -1175,13 +1175,10 @@ fn tauri_config_to_bundle_settings(
     },
     dmg: DmgSettings {
       background: config.dmg.background,
-      window_position: match config.dmg.window_position {
-        Some(window_position) => Some(Position {
+      window_position: config.dmg.window_position.map(|window_position| Position {
           x: window_position.x,
           y: window_position.y,
         }),
-        None => None,
-      },
       window_size: Size {
           width: config.dmg.window_size.width,
           height: config.dmg.window_size.height,

@hjmallon
Copy link

Is it worth mentioning in the docs that macOS seems to want the image to be 72dpi? I accidentally save a PNG out as 96dpi from Inkscape and it did not fill the window correctly.

@lucasfernog
Copy link
Member

Yes we should document that. Issue: create-dmg/create-dmg#20 (comment)

@hjmallon
Copy link

@lucasfernog : It would be great to see this change in a Tauri release. Is it worth recreating the MR to apply those fixes?

@lucasfernog
Copy link
Member

Yeah I'll see if I can merge this one as is then open a separate PR with the fixes.

@lucasfernog lucasfernog merged commit b0c5b06 into tauri-apps:dev Nov 20, 2023
25 of 31 checks passed
lucasfernog added a commit that referenced this pull request Nov 20, 2023
lucasfernog added a commit that referenced this pull request Nov 21, 2023
@hjmallon
Copy link

hjmallon commented Dec 4, 2023

@lucasfernog : How do I request backporting this to 1.x? Should I cherry pick it and make a new pull request?

@FabianLars
Copy link
Member

FabianLars commented Dec 4, 2023

Yep, if possible cherry picking would be the way to go here. (The branch diverged quite a lot though so it may have to be a more manual process)

hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Dec 4, 2023
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Dec 4, 2023
@hjmallon
Copy link

hjmallon commented Dec 4, 2023

Cherry pick PR is here #8334

@Andreybest
Copy link
Contributor Author

Hey @lucasfernog! So sorry for not responding to your comment. For some reason I totally forgot about this PR...
Thank you very much for merging! Glad that it can help other people 😀

DannyAziz pushed a commit to General-Collaboration/tauri that referenced this pull request Feb 7, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Mar 2, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Mar 2, 2024
@Pylogmon Pylogmon mentioned this pull request Jun 5, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Jun 5, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Jun 5, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Jun 5, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Jun 5, 2024
hjmallon pushed a commit to hjmallon/tauri that referenced this pull request Jun 5, 2024
FabianLars added a commit that referenced this pull request Jun 17, 2024
* feat(bundler): add dmg settings, closes #4669 (#7964)

* fix(bundler): lint and cleanup for #7964 (#8275)

* fmt

---------

Co-authored-by: Andrew <[email protected]>
Co-authored-by: Lucas Fernandes Nogueira <[email protected]>
Co-authored-by: FabianLars <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔎 In audit
Development

Successfully merging this pull request may close these issues.

[feat] Background image needed for DMG distribution file for OSX
4 participants