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]

View File

@@ -79,11 +79,9 @@ fn main() {
api::profile::profile_remove,
api::profile::profile_get,
api::profile::profile_list,
api::profile::profile_sync,
api::profile::profile_install,
api::profile::profile_update_all,
api::profile::profile_update_project,
api::profile::profile_replace_project,
api::profile::profile_add_project_from_version,
api::profile::profile_add_project_from_path,
api::profile::profile_toggle_disable_project,
@@ -117,9 +115,9 @@ fn main() {
api::jre::jre_find_jre_17_jres,
api::jre::jre_find_jre_8_jres,
api::jre::jre_validate_globals,
api::jre::jre_get_optimal_jre_key,
api::jre::jre_get_optimal_jre_key_by_path,
api::jre::jre_get_jre,
api::jre::jre_auto_install_java,
api::jre::jre_get_max_memory,
api::process::process_get_all_uuids,
api::process::process_get_all_running_uuids,
api::process::process_get_uuids_by_profile_path,

View File

@@ -11,7 +11,7 @@ JavaVersion {
path: Path
version: String
}
*/
/// Get all JREs that exist on the system
@@ -50,20 +50,18 @@ export async function get_jre(path) {
return await invoke('jre_get_jre', { path })
}
// 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)
export async function get_optimal_jre_key_by_path(path) {
return await invoke('jre_get_optimal_jre_key_by_path', { path })
}
// Gets key for the optimal JRE to use, for a given profile
// The key can be used in the hashmap contained by JavaGlobals in Settings (if it exists)
export async function get_optimal_jre_key(path) {
return await invoke('jre_get_optimal_jre_key', { path })
}
// Autodetect Java globals, by searching the users computer.
// Returns a *NEW* JavaGlobals that can be put into Settings
export async function autodetect_java_globals(path) {
return await invoke('jre_autodetect_java_globals', { path })
}
// Automatically installs specified java version
export async function jre_auto_install_java(javaVersion) {
return await invoke('jre_auto_install_java', { javaVersion })
}
// Get max memory in KiB
export async function get_max_memory() {
return await invoke('jre_get_max_memory')
}

View File

@@ -46,11 +46,6 @@ export async function check_installed(path, projectId) {
return await invoke('profile_check_installed', { path, projectId })
}
// Syncs a profile with the disk
export async function sync(path) {
return await invoke('profile_sync', { path })
}
// Installs/Repairs a profile
export async function install(path) {
return await invoke('profile_install', { path })
@@ -66,12 +61,6 @@ export async function update_project(path, projectPath) {
return await invoke('profile_update_project', { path, projectPath })
}
// Replaces a given project with the specified version ID
// Returns a path to the new project file
export async function replace_project(path, projectPath, versionId) {
return await invoke('profile_replace_project', { path, projectPath, versionId })
}
// Add a project to a profile from a version
// Returns a path to the new project file
export async function add_project_from_version(path, versionId) {

View File

@@ -17,7 +17,7 @@ import {
import { BrowseIcon } from '@/assets/icons'
import { useTheming } from '@/store/state'
import { get, set } from '@/helpers/settings'
import { find_jre_8_jres, find_jre_17_jres, get_jre } from '@/helpers/jre'
import { find_jre_8_jres, find_jre_17_jres, get_jre, get_max_memory } from '@/helpers/jre'
import { open } from '@tauri-apps/api/dialog'
const themeStore = useTheming()
@@ -29,6 +29,7 @@ if (!fetchSettings.java_globals?.JAVA_8)
if (!fetchSettings.java_globals?.JAVA_17)
fetchSettings.java_globals.JAVA_17 = { path: '', version: '' }
const settings = ref(fetchSettings)
const maxMemory = ref((await get_max_memory()) / 1024)
const chosenInstallOptions = ref([])
const browsingInstall = ref(0)
@@ -285,11 +286,11 @@ const setJavaInstall = (javaInstall) => {
<div class="sliders">
<span class="slider">
Minimum Memory
<Slider v-model="settings.memory.minimum" :min="1000" :max="8200" :step="10" />
<Slider v-model="settings.memory.minimum" :min="256" :max="maxMemory" :step="10" />
</span>
<span class="slider">
Maximum Memory
<Slider v-model="settings.memory.maximum" :min="1000" :max="8200" :step="10" />
<Slider v-model="settings.memory.maximum" :min="256" :max="maxMemory" :step="10" />
</span>
</div>
</div>