Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboarding #132

Merged
merged 16 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion theseus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "theseus"
version = "0.1.0"
version = "0.2.0"
authors = ["Jai A <jaiagr+gpg@pm.me>"]
edition = "2018"

Expand Down
89 changes: 34 additions & 55 deletions theseus/src/api/jre.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub const JAVA_18PLUS_KEY: &str = "JAVA_18PLUS";
// Autodetect JavaSettings default
// Make a guess for what the default Java global settings should be
pub async fn autodetect_java_globals() -> crate::Result<JavaGlobals> {
let mut java_8 = find_java8_jres().await?;
let mut java_17 = find_java17_jres().await?;
let mut java_18plus = find_java18plus_jres().await?;
let mut java_8 = find_filtered_jres("1.8").await?;
let mut java_17 = find_filtered_jres("1.17").await?;
let mut java_18plus = find_filtered_jres("1.18").await?;

// Simply select last one found for initial guess
let mut java_globals = JavaGlobals::new();
Expand All @@ -37,55 +37,19 @@ pub async fn autodetect_java_globals() -> crate::Result<JavaGlobals> {
Ok(java_globals)
}

// Searches for jres on the system that are 1.18 or higher
pub async fn find_java18plus_jres() -> crate::Result<Vec<JavaVersion>> {
let version = extract_java_majorminor_version("1.18")?;
let jres = jre::get_all_jre().await?;
// Filter out JREs that are not 1.17 or higher
Ok(jres
.into_iter()
.filter(|jre| {
let jre_version = extract_java_majorminor_version(&jre.version);
if let Ok(jre_version) = jre_version {
jre_version >= version
} else {
false
}
})
.collect())
}

// Searches for jres on the system that are 1.8 exactly
pub async fn find_java8_jres() -> crate::Result<Vec<JavaVersion>> {
let version = extract_java_majorminor_version("1.8")?;
// Searches for jres on the system given a java version (ex: 1.8, 1.17, 1.18)
pub async fn find_filtered_jres(
version: &str,
) -> crate::Result<Vec<JavaVersion>> {
let version = extract_java_majorminor_version(version)?;
let jres = jre::get_all_jre().await?;

// Filter out JREs that are not 1.8
Ok(jres
.into_iter()
.filter(|jre| {
let jre_version = extract_java_majorminor_version(&jre.version);
if let Ok(jre_version) = jre_version {
jre_version == version
} else {
false
}
})
.collect())
}

// Searches for jres on the system that are 1.17 exactly
pub async fn find_java17_jres() -> crate::Result<Vec<JavaVersion>> {
let version = extract_java_majorminor_version("1.17")?;
let jres = jre::get_all_jre().await?;

// Filter out JREs that are not 1.8
Ok(jres
.into_iter()
.filter(|jre| {
let jre_version = extract_java_majorminor_version(&jre.version);
if let Ok(jre_version) = jre_version {
jre_version == version
jre_version >= version
} else {
false
}
Expand Down Expand Up @@ -157,16 +121,31 @@ pub async fn auto_install_java(java_version: u32) -> crate::Result<PathBuf> {
))
})?;
emit_loading(&loading_bar, 10.0, Some("Done extracting java")).await?;
Ok(path
.join(
download
.name
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_string(),
)
.join(format!("zulu-{}.jre/Contents/Home/bin/java", java_version)))
let mut base_path = path.join(
download
.name
.file_stem()
.unwrap_or_default()
.to_string_lossy()
.to_string(),
);

#[cfg(target_os = "macos")]
{
base_path = base_path
.join(format!("zulu-{}.jre", java_version))
.join("Contents")
.join("Home")
.join("bin")
.join("java")
}

#[cfg(not(target_os = "macos"))]
{
base_path = base_path.join("bin").join(jre::JAVA_BIN)
}

Ok(base_path)
} else {
Err(crate::ErrorKind::LauncherError(format!(
"No Java Version found for Java version {}, OS {}, and Architecture {}",
Expand Down
3 changes: 3 additions & 0 deletions theseus/src/state/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct Settings {
pub opt_out_analytics: bool,
#[serde(default)]
pub advanced_rendering: bool,
#[serde(default)]
pub onboarded: bool,
}

impl Default for Settings {
Expand All @@ -52,6 +54,7 @@ impl Default for Settings {
developer_mode: false,
opt_out_analytics: false,
advanced_rendering: true,
onboarded: false,
}
}
}
Expand Down
Loading
Loading