Working interface between rust and web
This commit is contained in:
@@ -27,28 +27,6 @@ pub fn toggle_mod(state: State<SharedState>, mod_id: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[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]
|
#[tauri::command]
|
||||||
pub fn install_mod(state: State<SharedState>, mut mod_item: Mod) {
|
pub fn install_mod(state: State<SharedState>, mut mod_item: Mod) {
|
||||||
let mut state = state.lock().unwrap();
|
let mut state = state.lock().unwrap();
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||||
|
|
||||||
use saturn_launcher_lib::commands::*;
|
use saturn_launcher_lib::{commands::*, AppState};
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
|
.manage(Mutex::new(AppState::default()))
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
get_versions,
|
get_versions,
|
||||||
get_installed_mods,
|
get_installed_mods,
|
||||||
toggle_mod,
|
toggle_mod,
|
||||||
discover_mods,
|
|
||||||
install_mod,
|
install_mod,
|
||||||
get_settings,
|
get_settings,
|
||||||
update_settings,
|
update_settings,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// Saturn Client Launcher Centralized Service Layer
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
// Handles all data fetching, mod management, and launch logic.
|
|
||||||
|
|
||||||
|
// --- Types ---
|
||||||
export interface Mod {
|
export interface Mod {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
@@ -21,84 +21,21 @@ export interface GameVersion {
|
|||||||
|
|
||||||
export interface LauncherSettings {
|
export interface LauncherSettings {
|
||||||
jvmArguments: string;
|
jvmArguments: string;
|
||||||
maxMemory: number; // in MB
|
maxMemory: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Internal state ---
|
|
||||||
const versions: GameVersion[] = [
|
|
||||||
{
|
|
||||||
id: "1.20.1",
|
|
||||||
name: "Fabric 1.20.1",
|
|
||||||
releaseDate: "2023-06-07",
|
|
||||||
type: "release",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "1.20.4",
|
|
||||||
name: "Fabric 1.20.4",
|
|
||||||
releaseDate: "2023-12-07",
|
|
||||||
type: "release",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "1.21",
|
|
||||||
name: "Fabric 1.21",
|
|
||||||
releaseDate: "2024-06-13",
|
|
||||||
type: "release",
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const installedMods: Mod[] = [
|
|
||||||
{
|
|
||||||
id: "sodium",
|
|
||||||
name: "Sodium",
|
|
||||||
version: "0.5.8",
|
|
||||||
author: "jellysquid3",
|
|
||||||
description: "Modern rendering engine for Minecraft.",
|
|
||||||
enabled: true,
|
|
||||||
supportedVersions: ["1.20.1", "1.20.4", "1.21"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "iris",
|
|
||||||
name: "Iris",
|
|
||||||
version: "1.7.0",
|
|
||||||
author: "coderbot",
|
|
||||||
description: "A modern shaders mod for Minecraft.",
|
|
||||||
enabled: true,
|
|
||||||
supportedVersions: ["1.20.1", "1.20.4", "1.21"],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: "lithium",
|
|
||||||
name: "Lithium",
|
|
||||||
version: "0.11.2",
|
|
||||||
author: "jellysquid3",
|
|
||||||
description: "General-purpose optimization mod for Minecraft.",
|
|
||||||
enabled: false,
|
|
||||||
supportedVersions: ["1.20.1", "1.20.4"],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
let settings: LauncherSettings = {
|
|
||||||
jvmArguments:
|
|
||||||
"-XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200",
|
|
||||||
maxMemory: 4096,
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Versions ---
|
// --- Versions ---
|
||||||
export async function getVersions(): Promise<GameVersion[]> {
|
export async function getVersions(): Promise<GameVersion[]> {
|
||||||
return [...versions];
|
return await invoke("get_versions");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Mods ---
|
// --- Mods ---
|
||||||
export async function getInstalledMods(versionId: string): Promise<Mod[]> {
|
export async function getInstalledMods(versionId: string): Promise<Mod[]> {
|
||||||
return installedMods.filter((mod) =>
|
return await invoke("get_installed_mods", { versionId });
|
||||||
mod.supportedVersions.includes(versionId),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function toggleMod(modId: string): Promise<void> {
|
export async function toggleMod(modId: string): Promise<void> {
|
||||||
const mod = installedMods.find((m) => m.id === modId);
|
await invoke("toggle_mod", { modId });
|
||||||
if (mod) {
|
|
||||||
mod.enabled = !mod.enabled;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function discoverMods(query: string): Promise<Mod[]> {
|
export async function discoverMods(query: string): Promise<Mod[]> {
|
||||||
@@ -143,37 +80,23 @@ export async function installMod(
|
|||||||
mod: Mod,
|
mod: Mod,
|
||||||
versionsList: string[],
|
versionsList: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
console.log(`Installing ${mod.name} to versions: ${versionsList.join(", ")}`);
|
await invoke("install_mod", { modItem: mod });
|
||||||
|
|
||||||
if (!installedMods.find((m) => m.id === mod.id)) {
|
|
||||||
installedMods.push({
|
|
||||||
...mod,
|
|
||||||
enabled: true,
|
|
||||||
supportedVersions: versionsList,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Settings ---
|
// --- Settings ---
|
||||||
export async function getSettings(): Promise<LauncherSettings> {
|
export async function getSettings(): Promise<LauncherSettings> {
|
||||||
return { ...settings };
|
return await invoke("get_settings");
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateSettings(
|
export async function updateSettings(
|
||||||
newSettings: Partial<LauncherSettings>,
|
newSettings: Partial<LauncherSettings>,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
settings = { ...settings, ...newSettings };
|
await invoke("update_settings", { newSettings });
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Launch ---
|
// --- Launch ---
|
||||||
export async function launchGame(
|
export async function launchGame(
|
||||||
versionId: string,
|
versionId: string,
|
||||||
): Promise<{ success: boolean; message: string }> {
|
): Promise<{ success: boolean; message: string }> {
|
||||||
console.log(`Launching Saturn Client with version ${versionId}...`);
|
return await invoke("launch_game", { versionId });
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve({ success: true, message: "Game launched successfully!" });
|
|
||||||
}, 2000);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user