Refactor state system #7

This commit is contained in:
2026-04-04 22:04:53 +02:00
parent faf3e4ffef
commit 02454625d6
5 changed files with 112 additions and 58 deletions
+25 -24
View File
@@ -1,35 +1,17 @@
use tauri::State;
use crate::{LauncherSettings, Mod, SharedState};
use crate::{save_state, LauncherSettings, Mod, SharedState};
#[tauri::command]
pub fn get_installed_mods(state: State<SharedState>, version_id: String) -> Vec<Mod> {
let state = state.lock().unwrap();
state
.mods
.iter()
.filter(|m| m.supported_versions.contains(&version_id))
.cloned()
.collect()
Vec::new()
}
#[tauri::command]
pub fn toggle_mod(state: State<SharedState>, mod_id: String) {
let mut state = state.lock().unwrap();
if let Some(mod_item) = state.mods.iter_mut().find(|m| m.id == mod_id) {
mod_item.enabled = !mod_item.enabled;
}
}
pub fn toggle_mod(state: State<SharedState>, mod_id: String) {}
#[tauri::command]
pub fn install_mod(state: State<SharedState>, mut mod_item: Mod) {
let mut state = state.lock().unwrap();
if !state.mods.iter().any(|m| m.id == mod_item.id) {
mod_item.enabled = true;
state.mods.push(mod_item);
}
}
pub fn install_mod(state: State<SharedState>, mut mod_item: Mod) {}
#[tauri::command]
pub fn get_settings(state: State<SharedState>) -> LauncherSettings {
@@ -38,6 +20,25 @@ pub fn get_settings(state: State<SharedState>) -> LauncherSettings {
#[tauri::command]
pub fn update_settings(state: State<SharedState>, new_settings: LauncherSettings) {
let mut state = state.lock().unwrap();
state.settings = new_settings;
{
let mut state = state.lock().unwrap();
state.settings = new_settings;
}
save_state(&state);
}
#[tauri::command]
pub fn get_version(state: State<SharedState>) -> String {
state.lock().unwrap().version.clone()
}
#[tauri::command]
pub fn update_version(state: State<SharedState>, version: String) {
{
let mut state = state.lock().unwrap();
state.version = version;
}
save_state(&state);
}