| 1 | //! Tauri command: `app_build_version` |
| 2 | //! |
| 3 | //! Exposes the native build number so Settings can show a real version string |
| 4 | //! instead of a hardcoded one. The marketing version (`CFBundleShortVersionString`) |
| 5 | //! comes from `tauri.conf.json` and is read on the JS side via the app plugin's |
| 6 | //! `getVersion()`; the build number (`CFBundleVersion`) is Apple-specific and |
| 7 | //! lives only in the shipped bundle, so it needs a native read. |
| 8 | |
| 9 | /// Return the app's build version (`CFBundleVersion`). |
| 10 | /// |
| 11 | /// On Apple platforms this reads `CFBundleVersion` from the running bundle's |
| 12 | /// Info.plist — the exact value App Store Connect and TestFlight show, stamped |
| 13 | /// at build time by the release scripts as `YYYYMMDD.HHMM`. Returns `None` when |
| 14 | /// it cannot be resolved so the UI can fall back to the marketing version alone. |
| 15 | #[cfg(any(target_os = "ios", target_os = "macos"))] |
| 16 | #[tauri::command] |
| 17 | pub fn app_build_version() -> Option<String> { |
| 18 | use objc2_foundation::{NSBundle, NSString}; |
| 19 | |
| 20 | let bundle = NSBundle::mainBundle(); |
| 21 | let value = bundle.objectForInfoDictionaryKey(&NSString::from_str("CFBundleVersion"))?; |
| 22 | let version = value.downcast::<NSString>().ok()?; |
| 23 | Some(version.to_string()) |
| 24 | } |
| 25 | |
| 26 | /// Non-Apple builds have no `CFBundleVersion`; fall back to the marketing version. |
| 27 | #[cfg(not(any(target_os = "ios", target_os = "macos")))] |
| 28 | #[tauri::command] |
| 29 | pub fn app_build_version() -> Option<String> { |
| 30 | None |
| 31 | } |