From db0b229e52ff55ac68053ab3ca756e98c16c0b47 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Sat, 4 Apr 2026 16:45:31 +0200 Subject: [PATCH] Refactored slightly --- src/App.tsx | 4 +- src/components/ModsSection.tsx | 4 +- src/components/PlaySection.tsx | 4 +- src/components/SettingsSection.tsx | 4 +- src/lib/auth.ts | 50 ++++++++++++++++++++ src/lib/launcher.ts | 8 ++++ src/{services/SaturnApi.ts => lib/saturn.ts} | 2 +- src/{services/Types.ts => lib/types.ts} | 0 src/services/LauncherApi.ts | 13 ----- 9 files changed, 67 insertions(+), 22 deletions(-) create mode 100644 src/lib/auth.ts create mode 100644 src/lib/launcher.ts rename src/{services/SaturnApi.ts => lib/saturn.ts} (96%) rename src/{services/Types.ts => lib/types.ts} (100%) delete mode 100644 src/services/LauncherApi.ts diff --git a/src/App.tsx b/src/App.tsx index c86fdeb..0121e90 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -8,7 +8,7 @@ import { User, LogOut, } from "lucide-react"; -import { getVersions } from "./services/SaturnApi"; +import { getVersions } from "./lib/saturn"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; import Logo from "@/assets/logo.png"; @@ -22,7 +22,7 @@ function cn(...inputs: ClassValue[]) { import PlaySection from "./components/PlaySection"; import ModsSection from "./components/ModsSection"; import SettingsSection from "./components/SettingsSection"; -import { GameVersion } from "./services/Types"; +import { GameVersion } from "./lib/types"; type Section = "play" | "mods" | "settings"; diff --git a/src/components/ModsSection.tsx b/src/components/ModsSection.tsx index 7a9cf0e..c2419f5 100644 --- a/src/components/ModsSection.tsx +++ b/src/components/ModsSection.tsx @@ -14,11 +14,11 @@ import { getVersions, toggleMod, installMod, -} from "../services/SaturnApi"; +} from "../lib/saturn"; import { clsx, type ClassValue } from "clsx"; import { twMerge } from "tailwind-merge"; import { motion, AnimatePresence } from "framer-motion"; -import { GameVersion, Mod } from "@/services/Types"; +import { GameVersion, Mod } from "@/lib/types"; function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); diff --git a/src/components/PlaySection.tsx b/src/components/PlaySection.tsx index 990c271..9c7b399 100644 --- a/src/components/PlaySection.tsx +++ b/src/components/PlaySection.tsx @@ -3,8 +3,8 @@ import { Play, Loader2 } from "lucide-react"; // import { launchGame } from "../services/SaturnApi"; import Bg from "@/assets/bg.png"; import { listen } from "@tauri-apps/api/event"; -import { GameVersion } from "@/services/Types"; -import { launch } from "@/services/LauncherApi"; +import { GameVersion } from "@/lib/types"; +import { launch } from "@/lib/launcher"; interface PlaySectionProps { version: GameVersion; diff --git a/src/components/SettingsSection.tsx b/src/components/SettingsSection.tsx index 9fc2ec8..ba690f3 100644 --- a/src/components/SettingsSection.tsx +++ b/src/components/SettingsSection.tsx @@ -7,9 +7,9 @@ import { Info, AlertTriangle, } from "lucide-react"; -import { getSettings, updateSettings } from "../services/SaturnApi"; +import { getSettings, updateSettings } from "../lib/saturn"; import { motion } from "framer-motion"; -import { LauncherSettings } from "@/services/Types"; +import { LauncherSettings } from "@/lib/types"; const SettingsSection: React.FC = () => { const [settings, setSettings] = useState(null); diff --git a/src/lib/auth.ts b/src/lib/auth.ts new file mode 100644 index 0000000..9a7d33b --- /dev/null +++ b/src/lib/auth.ts @@ -0,0 +1,50 @@ +import { invoke } from "@tauri-apps/api/core"; + +/** + * Create Microsoft login URL + */ +export async function authCreateLink(): Promise { + return await invoke("auth_create_link"); +} + +/** + * Exchange auth code for account + */ +export async function authLogin(code: string) { + return await invoke("auth_login", { code }); +} + +/** + * Refresh account by UUID + */ +export async function authRefresh(uuid: string) { + return await invoke("auth_refresh", { uuid }); +} + +/** + * Get all stored accounts + */ +export async function authList() { + return await invoke("auth_list"); +} + +/** + * Remove account by UUID + */ +export async function authRemove(uuid: string) { + return await invoke("auth_remove", { uuid }); +} + +/** + * Validate token (not expired) + */ +export async function authValidate(uuid: string): Promise { + return await invoke("auth_validate", { uuid }); +} + +/** + * Get valid account (auto-refresh if needed) + */ +export async function authGetValid(uuid: string) { + return await invoke("auth_get_valid", { uuid }); +} diff --git a/src/lib/launcher.ts b/src/lib/launcher.ts new file mode 100644 index 0000000..2dec8bf --- /dev/null +++ b/src/lib/launcher.ts @@ -0,0 +1,8 @@ +import { invoke } from "@tauri-apps/api/core"; + +/** + * Launch the game with the selected account and version + */ +export async function launch() { + return await invoke("launch_game"); +} diff --git a/src/services/SaturnApi.ts b/src/lib/saturn.ts similarity index 96% rename from src/services/SaturnApi.ts rename to src/lib/saturn.ts index 82b5ed9..f196c06 100644 --- a/src/services/SaturnApi.ts +++ b/src/lib/saturn.ts @@ -1,5 +1,5 @@ import { invoke } from "@tauri-apps/api/core"; -import { GameVersion, LauncherSettings, Mod } from "./Types"; +import { GameVersion, LauncherSettings, Mod } from "./types"; // --- Versions --- export async function getVersions(): Promise { diff --git a/src/services/Types.ts b/src/lib/types.ts similarity index 100% rename from src/services/Types.ts rename to src/lib/types.ts diff --git a/src/services/LauncherApi.ts b/src/services/LauncherApi.ts deleted file mode 100644 index 81a8fcd..0000000 --- a/src/services/LauncherApi.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { invoke } from "@tauri-apps/api/core"; - -const clientId = "74909cec-49b6-4fee-aa60-1b2a57ef72e1"; - -export async function authenticate() { - return await invoke("plugin:lighty-launcher|authenticate", { - client_id: clientId, - }); -} - -export async function launch() { - return await invoke("launch_game"); -}