2023-11-17 17:23:08 +01:00
|
|
|
use std::{env::current_exe, path::PathBuf};
|
2023-08-24 19:55:35 +02:00
|
|
|
|
2023-04-20 16:02:41 +02:00
|
|
|
use anyhow::{anyhow, Result};
|
2023-05-24 11:20:13 +02:00
|
|
|
use lazy_static::lazy_static;
|
2023-06-25 15:29:52 +02:00
|
|
|
use shadow_rs::{is_debug, shadow};
|
|
|
|
|
|
|
|
shadow!(build);
|
2023-04-20 16:02:41 +02:00
|
|
|
|
2023-08-17 22:07:54 +02:00
|
|
|
pub fn get_resource_path<S: AsRef<str>>(dir: S) -> Result<std::path::PathBuf> {
|
2023-04-20 16:02:41 +02:00
|
|
|
let base_path = if is_debug() {
|
2023-11-17 17:23:08 +01:00
|
|
|
let cwd = build::CARGO_MANIFEST_DIR.parse::<PathBuf>()?;
|
|
|
|
cwd.join("./tmp/resources")
|
2023-04-20 16:02:41 +02:00
|
|
|
} else {
|
2023-08-24 19:55:35 +02:00
|
|
|
current_exe()?
|
|
|
|
.parent()
|
|
|
|
.ok_or(anyhow!("couldn't locate resource path, binary in root"))?
|
|
|
|
.join("../share/upend")
|
2023-04-20 16:02:41 +02:00
|
|
|
};
|
2023-08-17 22:07:54 +02:00
|
|
|
|
2023-04-20 16:02:41 +02:00
|
|
|
let result = base_path.join(dir.as_ref());
|
|
|
|
if result.exists() {
|
|
|
|
Ok(result)
|
|
|
|
} else {
|
|
|
|
Err(anyhow!("Path {result:?} doesn't exist."))
|
|
|
|
}
|
|
|
|
}
|
2023-05-24 11:20:13 +02:00
|
|
|
|
|
|
|
lazy_static! {
|
2023-06-25 15:29:52 +02:00
|
|
|
static ref APP_USER_AGENT: String = format!("upend / {}", build::PKG_VERSION);
|
2023-05-24 11:20:13 +02:00
|
|
|
pub static ref REQWEST_CLIENT: reqwest::blocking::Client = reqwest::blocking::Client::builder()
|
|
|
|
.user_agent(APP_USER_AGENT.as_str())
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2023-06-06 19:01:38 +02:00
|
|
|
pub static ref REQWEST_ASYNC_CLIENT: reqwest::Client = reqwest::Client::builder()
|
|
|
|
.user_agent(APP_USER_AGENT.as_str())
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
2023-05-24 11:20:13 +02:00
|
|
|
}
|
2023-10-22 21:18:00 +02:00
|
|
|
|
|
|
|
pub fn get_version() -> &'static str {
|
|
|
|
option_env!("UPEND_VERSION").unwrap_or("unknown")
|
2023-11-17 17:23:08 +01:00
|
|
|
}
|