Various final backend fixes (#117)

* Various final backend fixes

* Add FS watching

* run lint

* Autodetect installed jars
This commit is contained in:
Geometrically
2023-05-16 15:30:04 -07:00
committed by GitHub
parent 5cb54b44be
commit 3fa0e99de2
26 changed files with 941 additions and 529 deletions

View File

@@ -1,11 +1,9 @@
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use crate::api::Result;
use theseus::prelude::JavaVersion;
use theseus::prelude::*;
use super::TheseusSerializableError;
/// Get all JREs that exist on the system
#[tauri::command]
pub async fn jre_get_all_jre() -> Result<Vec<JavaVersion>> {
@@ -37,23 +35,6 @@ pub async fn jre_autodetect_java_globals() -> Result<JavaGlobals> {
Ok(jre::autodetect_java_globals().await?)
}
// Gets key for the optimal JRE to use, for a given profile Profile
// The key can be used in the hashmap contained by JavaGlobals in Settings (if it exists)
#[tauri::command]
pub async fn jre_get_optimal_jre_key(profile: Profile) -> Result<String> {
Ok(jre::get_optimal_jre_key(&profile).await?)
}
// Gets key for the optimal JRE to use, for a given profile path
// The key can be used in the hashmap contained by JavaGlobals in Settings (if it exists)
#[tauri::command]
pub async fn jre_get_optimal_jre_key_by_path(path: &Path) -> Result<String> {
let profile = profile::get(path, Some(true)).await?.ok_or_else(|| {
TheseusSerializableError::NoProfileFound(path.display().to_string())
})?;
Ok(jre::get_optimal_jre_key(&profile).await?)
}
// Validates java globals, by checking if the paths exist
// If false, recommend to direct them to reassign, or to re-guess
#[tauri::command]
@@ -67,3 +48,15 @@ pub async fn jre_validate_globals() -> Result<bool> {
pub async fn jre_get_jre(path: PathBuf) -> Result<Option<JavaVersion>> {
jre::check_jre(path).await.map_err(|e| e.into())
}
// 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?)
}

View File

@@ -31,9 +31,6 @@ pub enum TheseusSerializableError {
#[error("IO error: {0}")]
IO(#[from] std::io::Error),
#[error("No profile found at {0}")]
NoProfileFound(String),
}
// Generic implementation of From<T> for ErrorTypeA
@@ -92,6 +89,5 @@ macro_rules! impl_serialize {
// Use the macro to implement Serialize for TheseusSerializableError
impl_serialize! {
IO,
NoProfileFound,
IO
}

View File

@@ -54,14 +54,6 @@ pub async fn profile_check_installed(
}
}
/// Syncs a profile's in memory state with the state on the disk
/// // invoke('profile_sync')
#[tauri::command]
pub async fn profile_sync(path: &Path) -> Result<()> {
profile::sync(path).await?;
Ok(())
}
/// Installs/Repairs a profile
/// invoke('profile_install')
#[tauri::command]
@@ -89,18 +81,6 @@ pub async fn profile_update_project(
Ok(())
}
/// Replaces a project with the given version ID
/// invoke('profile_replace_project')
#[tauri::command]
pub async fn profile_replace_project(
path: &Path,
project: &Path,
version_id: String,
) -> Result<PathBuf> {
let res = profile::replace_project(path, project, version_id).await?;
Ok(res)
}
// Adds a project to a profile from a version ID
// invoke('profile_add_project_from_version')
#[tauri::command]