Better JVM detection (#494)

This commit is contained in:
Uriel authored and GitHub committed 2023-01-24 20:39:48 +02:00
1 parent 3e308b222f
commit f030496659
4 files changed
+43 -40

No files matched your search

Generated
+4 -2
View File
@@ -2560,9 +2560,9 @@ dependencies = [
[[package]]
name = "shadow-rs"
version = "0.19.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c401e795850edb4e9fdde5940f856364f0fbab573e8dea58f6ee5f85fcf471d"
checksum = "8da90bd2a722461267a2c5d20b2c6de76dba087348e60484fd6c3fbb48b766d6"
dependencies = [
"const_format",
"git2",
@@ -2609,10 +2609,12 @@ dependencies = [
name = "slimevr"
version = "0.0.0"
dependencies = [
"cfg-if",
"cfg_aliases",
"clap",
"clap-verbosity-flag",
"const_format",
"glob",
"log",
"open",
"pretty_env_logger",
+5 -3
View File
@@ -23,7 +23,7 @@ custom-protocol = ["tauri/custom-protocol"]
[build-dependencies]
tauri-build = { version = "1.2", features = [] }
cfg_aliases = "0.1"
shadow-rs = "0.19"
shadow-rs = "0.20"
[dependencies]
serde_json = "1"
@@ -36,10 +36,12 @@ clap-verbosity-flag = "2"
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/tauri-plugin-window-state", rev = "refs/pull/52/head" }
rand = "0.8.5"
tempfile = "3"
which = "4.3.0"
which = "4.3"
glob = "0.3"
open = "3"
shadow-rs = { version = "0.19", default-features = false }
shadow-rs = { version = "0.20", default-features = false }
const_format = "0.2.30"
cfg-if = "1"
[target.'cfg(windows)'.dependencies]
win32job = "1"
+33 -34
View File
@@ -5,7 +5,7 @@ use std::io::Write;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
use std::panic;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::{Child, Stdio};
use clap::Parser;
@@ -15,7 +15,6 @@ use shadow_rs::shadow;
use tauri::api::process::Command;
use tauri::Manager;
use tempfile::Builder;
use which::which_all;
#[cfg(windows)]
/// For Commands on Windows so they dont create terminals
@@ -53,41 +52,25 @@ struct Cli {
verbose: clap_verbosity_flag::Verbosity,
}
fn is_valid_path(path: &PathBuf) -> bool {
fn is_valid_path(path: &Path) -> bool {
path.join("slimevr.jar").exists()
}
fn get_launch_path(cli: Cli) -> Option<PathBuf> {
if let Some(path) = cli.launch_from_path {
if path.exists() && is_valid_path(&path) {
return Some(path);
}
}
let path = env::current_dir().unwrap();
if is_valid_path(&path) {
return Some(path);
}
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
if is_valid_path(&path) {
return Some(path);
}
let path = PathBuf::from("/usr/share/slimevr/");
if is_valid_path(&path) {
return Some(path);
}
// This is only for AppImage
if let Some(appimage) = env::var_os("APPDIR") {
let path = PathBuf::from(appimage);
if is_valid_path(&path) {
return Some(path);
}
}
None
let paths = [
cli.launch_from_path,
// AppImage passes the fakeroot in `APPDIR` env var.
env::var_os("APPDIR").map(|x| PathBuf::from(x)),
env::current_dir().ok(),
Some(PathBuf::from(env!("CARGO_MANIFEST_DIR"))),
// For flatpak container
Some(PathBuf::from("/app/share/slimevr/")),
Some(PathBuf::from("/usr/share/slimevr/")),
];
paths
.into_iter()
.filter_map(|x| x)
.find(|x| is_valid_path(x))
}
fn spawn_java(java: &OsStr, java_version: &OsStr) -> std::io::Result<Child> {
@@ -306,7 +289,23 @@ fn valid_java_paths() -> Vec<(OsString, i32)> {
// Otherwise check if anything else is a supported version
let mut childs = vec![];
for java in which_all(JAVA_BIN).unwrap() {
cfg_if::cfg_if! {
if #[cfg(target_os = "macos")] {
// TODO: Actually use macOS paths
let libs = which::which_all(JAVA_BIN).unwrap();
} else if #[cfg(unix)] {
// Linux JVMs are saved on /usr/lib/jvm from what I found out,
// there is usually a default dir and a default-runtime dir also which are linked
// to the current default runtime and the current default JDK (I think it's JDK)
let libs = glob::glob(concatcp!("/usr/lib/jvm/*/bin/", JAVA_BIN))
.unwrap()
.filter_map(|res| res.ok());
} else {
let libs = which::which_all(JAVA_BIN).unwrap();
}
}
for java in libs {
let res = spawn_java(java.as_os_str(), java_version.as_os_str());
match res {