mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-19 19:14:53 +00:00
feat: get sys data path as relative from the executable (for supporting appimage)
This commit is contained in:
parent
6614c2bf26
commit
f139857d92
10 changed files with 56 additions and 29 deletions
|
@ -31,7 +31,7 @@ appdata_file = i18n.merge_file(
|
|||
output: '@BASENAME@',
|
||||
configuration: global_conf
|
||||
),
|
||||
output: '@0@.metainfo.xml'.format(application_id),
|
||||
output: '@0@.appdata.xml'.format(application_id),
|
||||
po_dir: podir,
|
||||
install: true,
|
||||
install_dir: datadir / 'metainfo'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use expect_dialog::ExpectDialog;
|
||||
use crate::{constants::PKG_DATA_DIR, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
|
||||
|
||||
pub fn get_build_basalt_runner(profile: Profile) -> Runner {
|
||||
let mut args = vec![
|
||||
|
@ -17,7 +17,7 @@ pub fn get_build_basalt_runner(profile: Profile) -> Runner {
|
|||
}
|
||||
let runner = Runner::new(
|
||||
None,
|
||||
format!("{sysdata}/scripts/build_basalt.sh", sysdata = PKG_DATA_DIR),
|
||||
format!("{sysdata}/scripts/build_basalt.sh", sysdata = pkg_data_dir()),
|
||||
args,
|
||||
);
|
||||
runner
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::PKG_DATA_DIR, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
|
||||
use expect_dialog::ExpectDialog;
|
||||
|
||||
pub fn get_build_libsurvive_runner(profile: Profile) -> Runner {
|
||||
|
@ -19,7 +19,7 @@ pub fn get_build_libsurvive_runner(profile: Profile) -> Runner {
|
|||
None,
|
||||
format!(
|
||||
"{sysdata}/scripts/build_libsurvive.sh",
|
||||
sysdata = PKG_DATA_DIR
|
||||
sysdata = pkg_data_dir()
|
||||
),
|
||||
args,
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::PKG_DATA_DIR, file_utils::get_cache_dir, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, file_utils::get_cache_dir, profile::Profile, runner::Runner};
|
||||
|
||||
pub fn get_build_mercury_runner(profile: Profile) -> Runner {
|
||||
let args = vec![profile.prefix, get_cache_dir()];
|
||||
|
@ -6,7 +6,7 @@ pub fn get_build_mercury_runner(profile: Profile) -> Runner {
|
|||
None,
|
||||
format!(
|
||||
"{sysdata}/scripts/build_mercury.sh",
|
||||
sysdata = PKG_DATA_DIR
|
||||
sysdata = pkg_data_dir()
|
||||
),
|
||||
args,
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::PKG_DATA_DIR, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
|
||||
|
||||
pub fn get_build_monado_runner(profile: Profile) -> Runner {
|
||||
let mut args = vec![
|
||||
|
@ -14,7 +14,7 @@ pub fn get_build_monado_runner(profile: Profile) -> Runner {
|
|||
}
|
||||
let runner = Runner::new(
|
||||
None,
|
||||
format!("{sysdata}/scripts/build_monado.sh", sysdata = PKG_DATA_DIR),
|
||||
format!("{sysdata}/scripts/build_monado.sh", sysdata = pkg_data_dir()),
|
||||
args,
|
||||
);
|
||||
runner
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::PKG_DATA_DIR, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
|
||||
|
||||
pub fn get_build_opencomposite_runner(profile: Profile) -> Runner {
|
||||
let mut args = vec![
|
||||
|
@ -15,7 +15,7 @@ pub fn get_build_opencomposite_runner(profile: Profile) -> Runner {
|
|||
None,
|
||||
format!(
|
||||
"{sysdata}/scripts/build_opencomposite.sh",
|
||||
sysdata = PKG_DATA_DIR
|
||||
sysdata = pkg_data_dir()
|
||||
),
|
||||
args,
|
||||
);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{constants::PKG_DATA_DIR, profile::Profile, runner::Runner};
|
||||
use crate::{constants::pkg_data_dir, profile::Profile, runner::Runner};
|
||||
|
||||
pub fn get_build_wivrn_runner(profile: Profile) -> Runner {
|
||||
let mut args = vec![
|
||||
|
@ -14,7 +14,7 @@ pub fn get_build_wivrn_runner(profile: Profile) -> Runner {
|
|||
}
|
||||
let runner = Runner::new(
|
||||
None,
|
||||
format!("{sysdata}/scripts/build_wivrn.sh", sysdata = PKG_DATA_DIR),
|
||||
format!("{sysdata}/scripts/build_wivrn.sh", sysdata = pkg_data_dir()),
|
||||
args,
|
||||
);
|
||||
runner
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use crate::file_utils::get_exec_prefix;
|
||||
|
||||
pub const APP_NAME: &str = "@PRETTY_NAME@";
|
||||
pub const APP_ID: &str = "@APP_ID@";
|
||||
pub const PKG_DATA_DIR: &str = "@PKGDATADIR@";
|
||||
|
@ -13,3 +15,11 @@ pub const BUILD_PROFILE: &str = "@PROFILE@";
|
|||
pub fn get_developers() -> Vec<String> {
|
||||
vec!["Gabriele Musco <gabmus@disroot.org>".to_string()]
|
||||
}
|
||||
|
||||
pub fn pkg_data_dir() -> String {
|
||||
format!("{}/share/rex2", get_exec_prefix())
|
||||
}
|
||||
|
||||
pub fn resources() -> String {
|
||||
format!("{}/resources.gresource", pkg_data_dir())
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ use crate::{constants::CMD_NAME, runner::Runner};
|
|||
use expect_dialog::ExpectDialog;
|
||||
use std::{
|
||||
env,
|
||||
fs::{self, create_dir_all, OpenOptions, File},
|
||||
io::{BufWriter, BufReader},
|
||||
fs::{self, create_dir_all, File, OpenOptions},
|
||||
io::{BufReader, BufWriter},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
|
@ -36,24 +36,20 @@ pub fn get_reader(path_s: &String) -> Option<BufReader<File>> {
|
|||
println!("Error opening {}: {}", path_s, e);
|
||||
return None;
|
||||
}
|
||||
Ok(fd) => {
|
||||
Some(BufReader::new(fd))
|
||||
}
|
||||
Ok(fd) => Some(BufReader::new(fd)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_file<T: serde::de::DeserializeOwned>(path_s: &String) -> Option<T> {
|
||||
match get_reader(&path_s) {
|
||||
None => None,
|
||||
Some(reader) => {
|
||||
match serde_json::from_reader(reader) {
|
||||
Err(e) => {
|
||||
println!("Failed to deserialize {}: {}", path_s, e);
|
||||
None
|
||||
}
|
||||
Ok(res) => Some(res)
|
||||
Some(reader) => match serde_json::from_reader(reader) {
|
||||
Err(e) => {
|
||||
println!("Failed to deserialize {}: {}", path_s, e);
|
||||
None
|
||||
}
|
||||
}
|
||||
Ok(res) => Some(res),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +91,11 @@ pub fn get_data_dir() -> String {
|
|||
}
|
||||
|
||||
pub fn get_cache_dir() -> String {
|
||||
format!("{cache}/{name}", cache = get_xdg_cache_dir(), name = CMD_NAME)
|
||||
format!(
|
||||
"{cache}/{name}",
|
||||
cache = get_xdg_cache_dir(),
|
||||
name = CMD_NAME
|
||||
)
|
||||
}
|
||||
|
||||
pub fn set_file_radonly(path_s: &String, readonly: bool) {
|
||||
|
@ -120,3 +120,20 @@ pub fn setcap_cap_sys_nice_eip(file: String) {
|
|||
runner.start();
|
||||
runner.join();
|
||||
}
|
||||
|
||||
pub fn get_exec_prefix() -> String {
|
||||
let p = Path::new("/proc/self/exe");
|
||||
if !p.is_symlink() {
|
||||
panic!("/proc/self/exe is not a symlink!");
|
||||
}
|
||||
p.read_link()
|
||||
.unwrap()
|
||||
.as_path()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.to_str()
|
||||
.unwrap()
|
||||
.to_string()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use constants::{APP_ID, APP_NAME, GETTEXT_PACKAGE, LOCALE_DIR, RESOURCES};
|
||||
use constants::{APP_ID, APP_NAME, GETTEXT_PACKAGE, LOCALE_DIR, resources};
|
||||
use gettextrs::LocaleCategory;
|
||||
use relm4::{
|
||||
adw,
|
||||
|
@ -37,7 +37,7 @@ fn main() -> Result<()> {
|
|||
glib::set_application_name(APP_NAME);
|
||||
|
||||
{
|
||||
let res = gio::Resource::load(RESOURCES).expect("Could not load gresource file");
|
||||
let res = gio::Resource::load(resources()).expect("Could not load gresource file");
|
||||
gio::resources_register(&res);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue