Launcher commands
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
use tauri::State;
|
||||
|
||||
use crate::{GameVersion, LauncherSettings, Mod, SharedState};
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_versions(state: State<SharedState>) -> Vec<GameVersion> {
|
||||
let state = state.lock().unwrap();
|
||||
state.versions.clone()
|
||||
}
|
||||
|
||||
#[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()
|
||||
}
|
||||
|
||||
#[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;
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn discover_mods(query: String) -> Vec<Mod> {
|
||||
let all = vec![Mod {
|
||||
id: "modmenu".into(),
|
||||
name: "Mod Menu".into(),
|
||||
version: "7.2.2".into(),
|
||||
author: "TerraformersMC".into(),
|
||||
description: "Adds a mod menu.".into(),
|
||||
enabled: false,
|
||||
icon: None,
|
||||
supported_versions: vec!["1.20.1".into(), "1.20.4".into(), "1.21".into()],
|
||||
}];
|
||||
|
||||
if query.is_empty() {
|
||||
return all;
|
||||
}
|
||||
|
||||
all.into_iter()
|
||||
.filter(|m| m.name.to_lowercase().contains(&query.to_lowercase()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_settings(state: State<SharedState>) -> LauncherSettings {
|
||||
state.lock().unwrap().settings.clone()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn update_settings(state: State<SharedState>, new_settings: LauncherSettings) {
|
||||
let mut state = state.lock().unwrap();
|
||||
state.settings = new_settings;
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn launch_game(version_id: String) -> Result<String, String> {
|
||||
println!("Launching Saturn Client with version {}", version_id);
|
||||
|
||||
// Replace this with real launcher logic
|
||||
std::thread::sleep(std::time::Duration::from_secs(2));
|
||||
|
||||
Ok("Game launched successfully!".into())
|
||||
}
|
||||
+91
-11
@@ -1,14 +1,94 @@
|
||||
// Learn more about Tauri commands at https://tauri.app/develop/calling-rust/
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
format!("Hello, {}! You've been greeted from Rust!", name)
|
||||
pub mod commands;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Mutex;
|
||||
|
||||
// --- Types ---
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct Mod {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub version: String,
|
||||
pub author: String,
|
||||
pub description: String,
|
||||
pub enabled: bool,
|
||||
pub icon: Option<String>,
|
||||
pub supported_versions: Vec<String>,
|
||||
}
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![greet])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct GameVersion {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
pub release_date: String,
|
||||
pub r#type: String, // "release" | "snapshot"
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
pub struct LauncherSettings {
|
||||
pub jvm_arguments: String,
|
||||
pub max_memory: u32,
|
||||
}
|
||||
|
||||
// --- App State ---
|
||||
pub struct AppState {
|
||||
pub versions: Vec<GameVersion>,
|
||||
pub mods: Vec<Mod>,
|
||||
pub settings: LauncherSettings,
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
versions: vec![
|
||||
GameVersion {
|
||||
id: "1.20.1".into(),
|
||||
name: "Fabric 1.20.1".into(),
|
||||
release_date: "2023-06-07".into(),
|
||||
r#type: "release".into(),
|
||||
},
|
||||
GameVersion {
|
||||
id: "1.20.4".into(),
|
||||
name: "Fabric 1.20.4".into(),
|
||||
release_date: "2023-12-07".into(),
|
||||
r#type: "release".into(),
|
||||
},
|
||||
GameVersion {
|
||||
id: "1.21".into(),
|
||||
name: "Fabric 1.21".into(),
|
||||
release_date: "2024-06-13".into(),
|
||||
r#type: "release".into(),
|
||||
},
|
||||
],
|
||||
mods: vec![
|
||||
Mod {
|
||||
id: "sodium".into(),
|
||||
name: "Sodium".into(),
|
||||
version: "0.5.8".into(),
|
||||
author: "jellysquid3".into(),
|
||||
description: "Modern rendering engine for Minecraft.".into(),
|
||||
enabled: true,
|
||||
icon: None,
|
||||
supported_versions: vec!["1.20.1".into(), "1.20.4".into(), "1.21".into()],
|
||||
},
|
||||
Mod {
|
||||
id: "iris".into(),
|
||||
name: "Iris".into(),
|
||||
version: "1.7.0".into(),
|
||||
author: "coderbot".into(),
|
||||
description: "A modern shaders mod for Minecraft.".into(),
|
||||
enabled: true,
|
||||
icon: None,
|
||||
supported_versions: vec!["1.20.1".into(), "1.20.4".into(), "1.21".into()],
|
||||
},
|
||||
],
|
||||
settings: LauncherSettings {
|
||||
jvm_arguments: "-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200"
|
||||
.into(),
|
||||
max_memory: 4096,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type SharedState = Mutex<AppState>;
|
||||
|
||||
+17
-1
@@ -1,6 +1,22 @@
|
||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use saturn_launcher_lib::commands::*;
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
fn main() {
|
||||
saturn_launcher_lib::run()
|
||||
tauri::Builder::default()
|
||||
.plugin(tauri_plugin_opener::init())
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
get_versions,
|
||||
get_installed_mods,
|
||||
toggle_mod,
|
||||
discover_mods,
|
||||
install_mod,
|
||||
get_settings,
|
||||
update_settings,
|
||||
launch_game
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user