Skip to content

Commit

Permalink
feat: Dynamically compute resource path for macOS app bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
silviot committed Dec 9, 2024
1 parent fb55ee8 commit bb76f3c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit bb76f3c

Please sign in to comment.