Fix cli with an AppImage

This commit is contained in:
lights0123 2021-04-05 16:57:18 -04:00
parent 697a7365f3
commit d2a30f97f8
No known key found for this signature in database
GPG key ID: 28F315322E37972F

View file

@ -57,6 +57,16 @@ fn get_dev() -> Option<libnspire::Handle<rusb::GlobalContext>> {
.map(|dev| libnspire::Handle::new(dev.open().unwrap()).unwrap()) .map(|dev| libnspire::Handle::new(dev.open().unwrap()).unwrap())
} }
pub fn cwd() -> PathBuf {
#[cfg(target_os = "linux")]
if std::env::var_os("APPIMAGE").is_some() && std::env::var_os("APPDIR").is_some() {
if let Some(cwd) = std::env::var_os("OWD") {
return cwd.into();
}
};
std::env::current_dir().expect("Couldn't get current directory")
}
pub fn run() -> bool { pub fn run() -> bool {
let opt: Opt = Opt::parse(); let opt: Opt = Opt::parse();
if let Some(cmd) = opt.cmd { if let Some(cmd) = opt.cmd {
@ -65,7 +75,10 @@ pub fn run() -> bool {
if let Some(handle) = get_dev() { if let Some(handle) = get_dev() {
for file in files { for file in files {
let mut buf = vec![]; let mut buf = vec![];
File::open(&file).unwrap().read_to_end(&mut buf).unwrap(); File::open(cwd().join(&file))
.unwrap()
.read_to_end(&mut buf)
.unwrap();
let name = file let name = file
.file_name() .file_name()
.expect("Failed to get file name") .expect("Failed to get file name")