From bb76f3c49b2fc1a71a749c5ed0192fb78cfc9877 Mon Sep 17 00:00:00 2001 From: "Silvio Tomatis (aider)" Date: Mon, 9 Dec 2024 14:48:40 +0100 Subject: [PATCH] feat: Dynamically compute resource path for macOS app bundle --- src/config.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8bbe528..bf99770 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,25 @@ +use std::path::PathBuf; +use std::env; + pub static VERSION: &str = "0.1.0"; pub static GETTEXT_PACKAGE: &str = "aardvark"; pub static LOCALEDIR: &str = "/app/share/locale"; + #[cfg(target_os = "macos")] -pub static PKGDATADIR: &str = "../Resources/share/aardvark"; +pub fn get_pkgdatadir() -> PathBuf { + let exe_path = env::current_exe().expect("Failed to get current executable path"); + + // Navigate to the 'Resources/share/aardvark' directory relative to the executable + let pkgdatadir = exe_path + .parent() // Goes up to 'Contents/MacOS' + .and_then(|p| p.parent()) // Goes up to 'Contents' + .map(|p| p.join("Resources/share/aardvark")) + .expect("Failed to compute PKGDATADIR"); + + pkgdatadir +} #[cfg(not(target_os = "macos"))] -pub static PKGDATADIR: &str = "/app/share/aardvark"; +pub fn get_pkgdatadir() -> PathBuf { + PathBuf::from("/app/share/aardvark") +}