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

fix(ios, macos): Generate CFBundleShortVersionString from CFBundleVersion #12658

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
10 changes: 2 additions & 8 deletions crates/tauri-bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,6 @@ fn create_info_plist(
bundle_icon_file: Option<PathBuf>,
settings: &Settings,
) -> crate::Result<()> {
let format = time::format_description::parse("[year][month][day].[hour][minute][second]")
.map_err(time::error::Error::from)?;
let build_number = time::OffsetDateTime::now_utc()
.format(&format)
.map_err(time::error::Error::from)?;

let mut plist = plist::Dictionary::new();
plist.insert("CFBundleDevelopmentRegion".into(), "English".into());
plist.insert("CFBundleDisplayName".into(), settings.product_name().into());
Expand Down Expand Up @@ -224,9 +218,9 @@ fn create_info_plist(
plist.insert("CFBundlePackageType".into(), "APPL".into());
plist.insert(
"CFBundleShortVersionString".into(),
settings.version_string().into(),
settings.short_version_string().into(),
);
plist.insert("CFBundleVersion".into(), build_number.into());
plist.insert("CFBundleVersion".into(), settings.version_string().into());
plist.insert("CSResourcesFileMapped".into(), true.into());
if let Some(category) = settings.app_category() {
plist.insert(
Expand Down
2 changes: 1 addition & 1 deletion crates/tauri-bundler/src/bundle/macos/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn generate_info_plist(
writeln!(
file,
" <key>CFBundleShortVersionString</key>\n <string>{}</string>",
settings.version_string()
settings.short_version_string()
)?;
writeln!(
file,
Expand Down
7 changes: 7 additions & 0 deletions crates/tauri-bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ pub struct PackageSettings {
pub product_name: String,
/// the package's version.
pub version: String,
/// the package's short version.
pub short_version: String,
/// the package's description.
pub description: String,
/// the package's homepage.
Expand Down Expand Up @@ -1089,6 +1091,11 @@ impl Settings {
&self.package.version
}

/// Returns the short version string of the bundle.
pub fn short_version_string(&self) -> &str {
&self.package.short_version
}

/// Returns the copyright text.
pub fn copyright_string(&self) -> Option<&str> {
self.bundle_settings.copyright.as_deref()
Expand Down
38 changes: 25 additions & 13 deletions crates/tauri-cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,24 +1017,27 @@ impl RustAppSettings {
.workspace
.and_then(|v| v.package);

let version = config.version.clone().unwrap_or_else(|| {
cargo_package_settings
.version
.clone()
.expect("Cargo manifest must have the `package.version` field")
.resolve("version", || {
ws_package_settings
.as_ref()
.and_then(|p| p.version.clone())
.ok_or_else(|| anyhow::anyhow!("Couldn't inherit value for `version` from workspace"))
})
.expect("Cargo project does not have a version")
});

let package_settings = PackageSettings {
product_name: config
.product_name
.clone()
.unwrap_or_else(|| cargo_package_settings.name.clone()),
version: config.version.clone().unwrap_or_else(|| {
cargo_package_settings
.version
.clone()
.expect("Cargo manifest must have the `package.version` field")
.resolve("version", || {
ws_package_settings
.as_ref()
.and_then(|p| p.version.clone())
.ok_or_else(|| anyhow::anyhow!("Couldn't inherit value for `version` from workspace"))
})
.expect("Cargo project does not have a version")
}),
version: version.clone(),
short_version: Self::extract_short_version(&version),
description: cargo_package_settings
.description
.clone()
Expand Down Expand Up @@ -1119,6 +1122,15 @@ impl RustAppSettings {
.or_else(|| self.cargo_config.build().target())
}

fn extract_short_version(version: &str) -> String {
let mut parts = version.split('.');
match (parts.next(), parts.next()) {
(Some(major), Some(minor)) => format!("{}.{}", major, minor), // Create a new version String
(Some(major), None) => major.to_string(), // Convert major to version String if no minor
_ => String::new(), // Handle empty input case
}
}

pub fn out_dir(&self, options: &Options) -> crate::Result<PathBuf> {
get_target_dir(self.target(options), options)
}
Expand Down
9 changes: 8 additions & 1 deletion crates/tauri-cli/src/mobile/ios/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,14 @@ pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {

let mut plist = plist::Dictionary::new();
let version = interface.app_settings().get_package_settings().version;
plist.insert("CFBundleShortVersionString".into(), version.clone().into());
let short_version = interface
.app_settings()
.get_package_settings()
.short_version;
plist.insert(
"CFBundleShortVersionString".into(),
short_version.clone().into(),
);
plist.insert("CFBundleVersion".into(), version.into());

let info_plist_path = config
Expand Down