Profile Options (#120)

* init profile settings

* more work

* finish everything

* Switch to index approach

* Fix settings str split

* Run lint
This commit is contained in:
Geometrically
2023-05-19 18:59:32 -07:00
committed by GitHub
parent 4df7605b8d
commit 6014172046
43 changed files with 1108 additions and 709 deletions

View File

@@ -4,7 +4,6 @@ use theseus::prelude::*;
/// Authenticate a user with Hydra - part 1
/// This begins the authentication flow quasi-synchronously, returning a URL to visit (that the user will sign in at)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_authenticate_begin_flow() -> Result<url::Url> {
Ok(auth::authenticate_begin_flow().await?)
}
@@ -13,7 +12,6 @@ pub async fn auth_authenticate_begin_flow() -> Result<url::Url> {
/// This completes the authentication flow quasi-synchronously, returning the sign-in credentials
/// (and also adding the credentials to the state)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_authenticate_await_completion() -> Result<Credentials> {
Ok(auth::authenticate_await_complete_flow().await?)
}
@@ -21,13 +19,11 @@ pub async fn auth_authenticate_await_completion() -> Result<Credentials> {
/// Refresh some credentials using Hydra, if needed
// invoke('auth_refresh',user)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_refresh(user: uuid::Uuid) -> Result<Credentials> {
Ok(auth::refresh(user).await?)
}
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_remove_user(user: uuid::Uuid) -> Result<()> {
Ok(auth::remove_user(user).await?)
}
@@ -35,7 +31,6 @@ pub async fn auth_remove_user(user: uuid::Uuid) -> Result<()> {
/// Check if a user exists in Theseus
// invoke('auth_has_user',user)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_has_user(user: uuid::Uuid) -> Result<bool> {
Ok(auth::has_user(user).await?)
}
@@ -43,7 +38,6 @@ pub async fn auth_has_user(user: uuid::Uuid) -> Result<bool> {
/// Get a copy of the list of all user credentials
// invoke('auth_users',user)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_users() -> Result<Vec<Credentials>> {
Ok(auth::users().await?)
}
@@ -52,7 +46,6 @@ pub async fn auth_users() -> Result<Vec<Credentials>> {
/// Prefer to use refresh instead, as it will refresh the credentials as well
// invoke('auth_users',user)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn auth_get_user(user: uuid::Uuid) -> Result<Credentials> {
Ok(auth::get_user(user).await?)
}

View File

@@ -6,28 +6,24 @@ use theseus::prelude::*;
/// Get all JREs that exist on the system
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_get_all_jre() -> Result<Vec<JavaVersion>> {
Ok(jre::get_all_jre().await?)
}
// Finds the isntallation of Java 7, if it exists
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_find_jre_8_jres() -> Result<Vec<JavaVersion>> {
Ok(jre::find_java8_jres().await?)
}
// finds the installation of Java 17, if it exists
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_find_jre_17_jres() -> Result<Vec<JavaVersion>> {
Ok(jre::find_java17_jres().await?)
}
// Finds the highest version of Java 18+, if it exists
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_find_jre_18plus_jres() -> Result<Vec<JavaVersion>> {
Ok(jre::find_java18plus_jres().await?)
}
@@ -35,7 +31,6 @@ pub async fn jre_find_jre_18plus_jres() -> Result<Vec<JavaVersion>> {
// Autodetect Java globals, by searching the users computer.
// Returns a *NEW* JavaGlobals that can be put into Settings
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_autodetect_java_globals() -> Result<JavaGlobals> {
Ok(jre::autodetect_java_globals().await?)
}
@@ -43,7 +38,6 @@ pub async fn jre_autodetect_java_globals() -> Result<JavaGlobals> {
// Validates java globals, by checking if the paths exist
// If false, recommend to direct them to reassign, or to re-guess
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn jre_validate_globals() -> Result<bool> {
Ok(jre::validate_globals().await?)
}
@@ -51,21 +45,18 @@ pub async fn jre_validate_globals() -> Result<bool> {
// Validates JRE at a given path
// Returns None if the path is not a valid JRE
#[tauri::command]
#[theseus_macros::debug_pin]
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]
#[theseus_macros::debug_pin]
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]
#[theseus_macros::debug_pin]
pub async fn jre_get_max_memory() -> Result<u64> {
Ok(jre::get_max_memory().await?)
}

View File

@@ -14,7 +14,6 @@ pub struct Logs {
/// Get all Logs for a profile, sorted by datetime
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_get_logs(
profile_uuid: Uuid,
clear_contents: Option<bool>,
@@ -30,7 +29,6 @@ pub async fn logs_get_logs(
/// Get a Log struct for a profile by profile id and datetime string
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_get_logs_by_datetime(
profile_uuid: Uuid,
datetime_string: String,
@@ -40,7 +38,6 @@ pub async fn logs_get_logs_by_datetime(
/// Get the stdout for a profile by profile id and datetime string
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_get_stdout_by_datetime(
profile_uuid: Uuid,
datetime_string: String,
@@ -50,7 +47,6 @@ pub async fn logs_get_stdout_by_datetime(
/// Get the stderr for a profile by profile id and datetime string
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_get_stderr_by_datetime(
profile_uuid: Uuid,
datetime_string: String,
@@ -60,14 +56,12 @@ pub async fn logs_get_stderr_by_datetime(
/// Delete all logs for a profile by profile id
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_delete_logs(profile_uuid: Uuid) -> Result<()> {
Ok(logs::delete_logs(profile_uuid).await?)
}
/// Delete a log for a profile by profile id and datetime string
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn logs_delete_logs_by_datetime(
profile_uuid: Uuid,
datetime_string: String,

View File

@@ -4,28 +4,24 @@ use daedalus::modded::Manifest;
/// Gets the game versions from daedalus
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn metadata_get_game_versions() -> Result<VersionManifest> {
Ok(theseus::metadata::get_minecraft_versions().await?)
}
/// Gets the fabric versions from daedalus
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn metadata_get_fabric_versions() -> Result<Manifest> {
Ok(theseus::metadata::get_fabric_versions().await?)
}
/// Gets the forge versions from daedalus
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn metadata_get_forge_versions() -> Result<Manifest> {
Ok(theseus::metadata::get_forge_versions().await?)
}
/// Gets the quilt versions from daedalus
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn metadata_get_quilt_versions() -> Result<Manifest> {
Ok(theseus::metadata::get_quilt_versions().await?)
}

View File

@@ -47,7 +47,6 @@ where
// Create a new HashMap with the same keys
// Values provided should not be used directly, as they are not guaranteed to be up-to-date
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn progress_bars_list(
) -> Result<std::collections::HashMap<uuid::Uuid, theseus::LoadingBar>> {
let res = theseus::EventState::list_progress_bars().await?;

View File

@@ -3,7 +3,6 @@ use std::path::{Path, PathBuf};
use theseus::prelude::*;
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn pack_install_version_id(
version_id: String,
pack_title: String,
@@ -16,7 +15,6 @@ pub async fn pack_install_version_id(
}
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn pack_install_file(path: &Path) -> Result<PathBuf> {
let res = pack::install_pack_from_file(path.to_path_buf()).await?;
Ok(res)

View File

@@ -6,14 +6,12 @@ use uuid::Uuid;
// Checks if a process has finished by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_has_finished_by_uuid(uuid: Uuid) -> Result<bool> {
Ok(process::has_finished_by_uuid(&uuid).await?)
}
// Gets process exit status by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_exit_status_by_uuid(
uuid: Uuid,
) -> Result<Option<i32>> {
@@ -22,21 +20,18 @@ pub async fn process_get_exit_status_by_uuid(
// Gets all process UUIDs
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_all_uuids() -> Result<Vec<Uuid>> {
Ok(process::get_all_uuids().await?)
}
// Gets all running process UUIDs
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_all_running_uuids() -> Result<Vec<Uuid>> {
Ok(process::get_all_running_uuids().await?)
}
// Gets all process UUIDs by profile path
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_uuids_by_profile_path(
profile_path: &Path,
) -> Result<Vec<Uuid>> {
@@ -45,42 +40,36 @@ pub async fn process_get_uuids_by_profile_path(
// Gets the Profile paths of each *running* stored process in the state
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_all_running_profile_paths() -> Result<Vec<PathBuf>> {
Ok(process::get_all_running_profile_paths().await?)
}
// Gets the Profiles (cloned) of each *running* stored process in the state
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_all_running_profiles() -> Result<Vec<Profile>> {
Ok(process::get_all_running_profiles().await?)
}
// Gets process stderr by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_stderr_by_uuid(uuid: Uuid) -> Result<String> {
Ok(process::get_stderr_by_uuid(&uuid).await?)
}
// Gets process stdout by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_get_stdout_by_uuid(uuid: Uuid) -> Result<String> {
Ok(process::get_stdout_by_uuid(&uuid).await?)
}
// Kill a process by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_kill_by_uuid(uuid: Uuid) -> Result<()> {
Ok(process::kill_by_uuid(&uuid).await?)
}
// Wait for a process to finish by process UUID
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn process_wait_for_by_uuid(uuid: Uuid) -> Result<()> {
Ok(process::wait_for_by_uuid(&uuid).await?)
}

View File

@@ -9,7 +9,6 @@ use uuid::Uuid;
// Remove a profile
// invoke('profile_add_path',path)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_remove(path: &Path) -> Result<()> {
profile::remove(path).await?;
Ok(())
@@ -18,7 +17,6 @@ pub async fn profile_remove(path: &Path) -> Result<()> {
// Get a profile by path
// invoke('profile_add_path',path)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_get(
path: &Path,
clear_projects: Option<bool>,
@@ -27,10 +25,18 @@ pub async fn profile_get(
Ok(res)
}
// Get optimal java version from profile
#[tauri::command]
pub async fn profile_get_optimal_jre_key(
path: &Path,
) -> Result<Option<JavaVersion>> {
let res = profile::get_optimal_jre_key(path).await?;
Ok(res)
}
// Get a copy of the profile set
// invoke('profile_list')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_list(
clear_projects: Option<bool>,
) -> Result<HashMap<PathBuf, Profile>> {
@@ -39,7 +45,6 @@ pub async fn profile_list(
}
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_check_installed(
path: &Path,
project_id: String,
@@ -62,7 +67,6 @@ pub async fn profile_check_installed(
/// Installs/Repairs a profile
/// invoke('profile_install')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_install(path: &Path) -> Result<()> {
profile::install(path).await?;
Ok(())
@@ -71,7 +75,6 @@ pub async fn profile_install(path: &Path) -> Result<()> {
/// Updates all of the profile's projects
/// invoke('profile_update_all')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_update_all(
path: &Path,
) -> Result<HashMap<PathBuf, PathBuf>> {
@@ -81,7 +84,6 @@ pub async fn profile_update_all(
/// Updates a specified project
/// invoke('profile_update_project')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_update_project(
path: &Path,
project_path: &Path,
@@ -92,7 +94,6 @@ pub async fn profile_update_project(
// Adds a project to a profile from a version ID
// invoke('profile_add_project_from_version')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_add_project_from_version(
path: &Path,
version_id: String,
@@ -103,7 +104,6 @@ pub async fn profile_add_project_from_version(
// Adds a project to a profile from a path
// invoke('profile_add_project_from_path')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_add_project_from_path(
path: &Path,
project_path: &Path,
@@ -117,7 +117,6 @@ pub async fn profile_add_project_from_path(
// Toggles disabling a project from its path
// invoke('profile_toggle_disable_project')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_toggle_disable_project(
path: &Path,
project_path: &Path,
@@ -128,7 +127,6 @@ pub async fn profile_toggle_disable_project(
// Removes a project from a profile
// invoke('profile_remove_project')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_remove_project(
path: &Path,
project_path: &Path,
@@ -141,7 +139,6 @@ pub async fn profile_remove_project(
// for the actual Child in the state.
// invoke('profile_run', path)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_run(path: &Path) -> Result<Uuid> {
let minecraft_child = profile::run(path).await?;
let uuid = minecraft_child.read().await.uuid;
@@ -151,7 +148,6 @@ pub async fn profile_run(path: &Path) -> Result<Uuid> {
// Run Minecraft using a profile using the default credentials, and wait for the result
// invoke('profile_run_wait', path)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_run_wait(path: &Path) -> Result<()> {
let proc_lock = profile::run(path).await?;
let mut proc = proc_lock.write().await;
@@ -163,7 +159,6 @@ pub async fn profile_run_wait(path: &Path) -> Result<()> {
// for the actual Child in the state.
// invoke('profile_run_credentials', {path, credentials})')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_run_credentials(
path: &Path,
credentials: Credentials,
@@ -176,7 +171,6 @@ pub async fn profile_run_credentials(
// Run Minecraft using a profile using the chosen credentials, and wait for the result
// invoke('profile_run_wait', {path, credentials)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_run_wait_credentials(
path: &Path,
credentials: Credentials,
@@ -206,7 +200,6 @@ pub struct EditProfileMetadata {
// Edits a profile
// invoke('profile_edit', {path, editProfile})
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_edit(
path: &Path,
edit_profile: EditProfile,
@@ -236,3 +229,14 @@ pub async fn profile_edit(
Ok(())
}
// Edits a profile's icon
// invoke('profile_edit_icon')
#[tauri::command]
pub async fn profile_edit_icon(
path: &Path,
icon_path: Option<&Path>,
) -> Result<()> {
profile::edit_icon(path, icon_path).await?;
Ok(())
}

View File

@@ -5,7 +5,6 @@ use theseus::prelude::*;
// Generic basic profile creation tool.
// Creates an essentially empty dummy profile with profile_create
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_create_empty() -> Result<PathBuf> {
let res = profile_create::profile_create_empty().await?;
Ok(res)
@@ -14,19 +13,18 @@ pub async fn profile_create_empty() -> Result<PathBuf> {
// Creates a profile at the given filepath and adds it to the in-memory state
// invoke('profile_add',profile)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn profile_create(
name: String, // the name of the profile, and relative path
game_version: String, // the game version of the profile
modloader: ModLoader, // the modloader to use
loader_version: String, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader
icon: Option<PathBuf>, // the icon for the profile
name: String, // the name of the profile, and relative path
game_version: String, // the game version of the profile
modloader: ModLoader, // the modloader to use
loader_version: Option<String>, // the modloader version to use, set to "latest", "stable", or the ID of your chosen loader
icon: Option<PathBuf>, // the icon for the profile
) -> Result<PathBuf> {
let res = profile_create::profile_create(
name,
game_version,
modloader,
Some(loader_version),
loader_version,
icon,
None,
None,

View File

@@ -23,68 +23,15 @@ pub struct FrontendSettings {
// Get full settings
// invoke('settings_get')
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn settings_get() -> Result<FrontendSettings> {
let backend_settings = settings::get().await?;
let frontend_settings = FrontendSettings {
theme: backend_settings.theme,
memory: backend_settings.memory,
game_resolution: backend_settings.game_resolution,
custom_java_args: backend_settings.custom_java_args.join(" "),
custom_env_args: backend_settings
.custom_env_args
.into_iter()
.map(|(s1, s2)| format!("{s1}={s2}"))
.collect::<Vec<String>>()
.join(" "),
java_globals: backend_settings.java_globals,
default_user: backend_settings.default_user,
hooks: backend_settings.hooks,
max_concurrent_downloads: backend_settings.max_concurrent_downloads,
max_concurrent_writes: backend_settings.max_concurrent_writes,
version: backend_settings.version,
collapsed_navigation: backend_settings.collapsed_navigation,
};
Ok(frontend_settings)
pub async fn settings_get() -> Result<Settings> {
let res = settings::get().await?;
Ok(res)
}
// Set full settings
// invoke('settings_set', settings)
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn settings_set(settings: FrontendSettings) -> Result<()> {
let custom_env_args: Vec<(String, String)> = settings
.custom_env_args
.split_whitespace()
.map(|s| s.to_string())
.flat_map(|f| {
let mut split = f.split('=');
if let (Some(name), Some(value)) = (split.next(), split.next()) {
Some((name.to_string(), value.to_string()))
} else {
None
}
})
.collect::<Vec<(String, String)>>();
let backend_settings = Settings {
theme: settings.theme,
memory: settings.memory,
game_resolution: settings.game_resolution,
custom_java_args: settings
.custom_java_args
.split_whitespace()
.map(|s| s.to_string())
.collect(),
custom_env_args,
java_globals: settings.java_globals,
default_user: settings.default_user,
hooks: settings.hooks,
max_concurrent_downloads: settings.max_concurrent_downloads,
max_concurrent_writes: settings.max_concurrent_writes,
version: settings.version,
collapsed_navigation: settings.collapsed_navigation,
};
settings::set(backend_settings).await?;
pub async fn settings_set(settings: Settings) -> Result<()> {
settings::set(settings).await?;
Ok(())
}

View File

@@ -3,42 +3,36 @@ use theseus::tags::{Category, DonationPlatform, GameVersion, Loader, Tags};
/// Gets cached category tags from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_categories() -> Result<Vec<Category>> {
Ok(theseus::tags::get_category_tags().await?)
}
/// Gets cached report type tags from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_report_types() -> Result<Vec<String>> {
Ok(theseus::tags::get_report_type_tags().await?)
}
/// Gets cached loader tags from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_loaders() -> Result<Vec<Loader>> {
Ok(theseus::tags::get_loader_tags().await?)
}
/// Gets cached game version tags from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_game_versions() -> Result<Vec<GameVersion>> {
Ok(theseus::tags::get_game_version_tags().await?)
}
/// Gets cached donation platform tags from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_donation_platforms() -> Result<Vec<DonationPlatform>> {
Ok(theseus::tags::get_donation_platform_tags().await?)
}
/// Gets cached tag bundle from the database
#[tauri::command]
#[theseus_macros::debug_pin]
pub async fn tags_get_tag_bundle() -> Result<Tags> {
Ok(theseus::tags::get_tag_bundle().await?)
}