Skip to content

Commit

Permalink
fix(bundler): lint and cleanup for #7964
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Nov 20, 2023
1 parent b0c5b06 commit df19015
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 64 deletions.
36 changes: 11 additions & 25 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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>
Expand Down
61 changes: 26 additions & 35 deletions tooling/bundler/src/bundle/macos/dmg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")?;
Expand Down
5 changes: 1 addition & 4 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,13 +1179,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,
Expand Down

0 comments on commit df19015

Please sign in to comment.