2023-05-16 15:30:04 -07:00
|
|
|
use std::path::PathBuf;
|
2023-04-07 13:31:06 -07:00
|
|
|
|
|
|
|
|
use crate::api::Result;
|
2023-06-28 09:58:58 -07:00
|
|
|
use tauri::plugin::TauriPlugin;
|
2023-04-07 13:31:06 -07:00
|
|
|
use theseus::prelude::JavaVersion;
|
|
|
|
|
use theseus::prelude::*;
|
|
|
|
|
|
2023-06-28 09:58:58 -07:00
|
|
|
pub fn init<R: tauri::Runtime>() -> TauriPlugin<R> {
|
|
|
|
|
tauri::plugin::Builder::new("jre")
|
|
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
jre_find_filtered_jres,
|
|
|
|
|
jre_get_jre,
|
2023-09-12 09:27:03 -07:00
|
|
|
jre_test_jre,
|
2023-06-28 09:58:58 -07:00
|
|
|
jre_auto_install_java,
|
|
|
|
|
jre_get_max_memory,
|
|
|
|
|
])
|
|
|
|
|
.build()
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-20 22:03:59 -04:00
|
|
|
// Finds the installation of Java 8, if it exists
|
2023-04-07 13:31:06 -07:00
|
|
|
#[tauri::command]
|
2023-06-28 09:58:58 -07:00
|
|
|
pub async fn jre_find_filtered_jres(
|
2024-04-18 20:28:52 -07:00
|
|
|
version: Option<u32>,
|
2023-06-28 09:58:58 -07:00
|
|
|
) -> Result<Vec<JavaVersion>> {
|
2024-04-18 20:28:52 -07:00
|
|
|
Ok(jre::find_filtered_jres(version).await?)
|
2023-04-07 13:31:06 -07:00
|
|
|
}
|
2023-04-17 12:40:27 -07:00
|
|
|
|
|
|
|
|
// Validates JRE at a given path
|
|
|
|
|
// Returns None if the path is not a valid JRE
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn jre_get_jre(path: PathBuf) -> Result<Option<JavaVersion>> {
|
|
|
|
|
jre::check_jre(path).await.map_err(|e| e.into())
|
|
|
|
|
}
|
2023-05-16 15:30:04 -07:00
|
|
|
|
2023-09-12 09:27:03 -07:00
|
|
|
// Tests JRE of a certain version
|
|
|
|
|
#[tauri::command]
|
2024-04-18 20:28:52 -07:00
|
|
|
pub async fn jre_test_jre(path: PathBuf, major_version: u32) -> Result<bool> {
|
|
|
|
|
Ok(jre::test_jre(path, major_version).await?)
|
2023-09-12 09:27:03 -07:00
|
|
|
}
|
|
|
|
|
|
2023-05-16 15:30:04 -07:00
|
|
|
// Auto installs java for the given java version
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn jre_auto_install_java(java_version: u32) -> Result<PathBuf> {
|
|
|
|
|
Ok(jre::auto_install_java(java_version).await?)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gets the maximum memory a system has available.
|
|
|
|
|
#[tauri::command]
|
|
|
|
|
pub async fn jre_get_max_memory() -> Result<u64> {
|
|
|
|
|
Ok(jre::get_max_memory().await?)
|
|
|
|
|
}
|