Skip to content

Commit

Permalink
Move get_pkgdatadir to main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
silviot committed Dec 9, 2024
1 parent 6bdb3d1 commit e4f4d7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
21 changes: 0 additions & 21 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
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";

pub fn get_pkgdatadir() -> PathBuf {
#[cfg(target_os = "macos")]
{
let exe_path = env::current_exe().expect("Failed to get current executable path");
// Navigate to the 'Resources/share/aardvark' directory relative to the executable
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")
}

#[cfg(not(target_os = "macos"))]
{
PathBuf::from("/app/share/aardvark")
}
}
23 changes: 22 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ mod operation;
mod window;
mod textbuffer;

use std::path::PathBuf;
use std::env;
use self::application::AardvarkApplication;
use self::window::AardvarkWindow;
use self::textbuffer::AardvarkTextBuffer;

use config::{GETTEXT_PACKAGE, LOCALEDIR, get_pkgdatadir};

use config::{GETTEXT_PACKAGE, LOCALEDIR};
use gettextrs::{bind_textdomain_codeset, bindtextdomain, textdomain};
use gtk::{gio, glib};
use gtk::prelude::*;
Expand Down Expand Up @@ -57,3 +60,21 @@ fn main() -> glib::ExitCode {
// terminal.
app.run()
}

fn get_pkgdatadir() -> PathBuf {
#[cfg(target_os = "macos")]
{
let exe_path = env::current_exe().expect("Failed to get current executable path");
// Navigate to the 'Resources/share/aardvark' directory relative to the executable
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")
}

#[cfg(not(target_os = "macos"))]
{
PathBuf::from("/app/share/aardvark")
}
}

0 comments on commit e4f4d7b

Please sign in to comment.