Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions tooling/bundler/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use tauri_utils::display_path;
pub use self::{
category::AppCategory,
settings::{
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings, PackageType,
Settings, SettingsBuilder, UpdaterSettings, Position, Size
BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings,
PackageType, Position, Settings, SettingsBuilder, Size, UpdaterSettings,
},
};
#[cfg(target_os = "macos")]
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
19 changes: 8 additions & 11 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use notify::RecursiveMode;
use notify_debouncer_mini::new_debouncer;
use serde::Deserialize;
use tauri_bundler::{
AppCategory, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings, PackageSettings,
UpdaterSettings, WindowsSettings, Position, Size
AppCategory, BundleBinary, BundleSettings, DebianSettings, DmgSettings, MacOsSettings,
PackageSettings, Position, Size, UpdaterSettings, WindowsSettings,
};
use tauri_utils::config::parse::is_configuration_file;

Expand Down Expand Up @@ -1179,16 +1179,13 @@ fn tauri_config_to_bundle_settings(
},
dmg: DmgSettings {
background: config.dmg.background,
window_position: match config.dmg.window_position {
Some(window_position) => Some(Position {
x: window_position.x,
y: window_position.y,
}),
None => None,
},
window_position: config.dmg.window_position.map(|window_position| Position {
x: window_position.x,
y: window_position.y,
}),
window_size: Size {
width: config.dmg.window_size.width,
height: config.dmg.window_size.height,
width: config.dmg.window_size.width,
height: config.dmg.window_size.height,
},
app_position: Position {
x: config.dmg.app_position.x,
Expand Down