Fix: auth not refreshing on launch #15
This commit is contained in:
@@ -125,8 +125,11 @@ pub async fn auth_refresh(uuid: String) -> Result<MinecraftAccount, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
pub fn auth_list() -> Result<Vec<MinecraftAccount>, String> {
|
pub fn auth_list() -> Result<Vec<(String, String)>, String> {
|
||||||
Ok(load_accounts())
|
Ok(load_accounts()
|
||||||
|
.iter()
|
||||||
|
.map(|account| (account.uuid.clone(), account.username.clone()))
|
||||||
|
.collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
|
|||||||
+3
-4
@@ -6,7 +6,6 @@ import ModsSection from "./components/ModsSection";
|
|||||||
import SettingsSection from "./components/SettingsSection";
|
import SettingsSection from "./components/SettingsSection";
|
||||||
import { versions } from "./lib/launcher";
|
import { versions } from "./lib/launcher";
|
||||||
import { GameVersion } from "./lib/types";
|
import { GameVersion } from "./lib/types";
|
||||||
import { MinecraftAccount } from "./lib/auth";
|
|
||||||
import { getVersion, installPaths, updateVersion } from "./lib/saturn";
|
import { getVersion, installPaths, updateVersion } from "./lib/saturn";
|
||||||
import { getCurrentWindow } from "@tauri-apps/api/window";
|
import { getCurrentWindow } from "@tauri-apps/api/window";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
@@ -26,8 +25,8 @@ export default function App() {
|
|||||||
const versionRef = useRef<HTMLDivElement | null>(null);
|
const versionRef = useRef<HTMLDivElement | null>(null);
|
||||||
const accountRef = useRef<HTMLDivElement | null>(null);
|
const accountRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const [accounts, setAccounts] = useState<MinecraftAccount[]>([]);
|
const [accounts, setAccounts] = useState<[string, string][]>([]);
|
||||||
const [activeAccount, setActiveAccount] = useState<MinecraftAccount | null>(
|
const [activeAccount, setActiveAccount] = useState<[string, string] | null>(
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -137,7 +136,7 @@ export default function App() {
|
|||||||
|
|
||||||
<div className="flex-1 p-8 overflow-y-scroll">
|
<div className="flex-1 p-8 overflow-y-scroll">
|
||||||
{active === "play" && (
|
{active === "play" && (
|
||||||
<PlaySection version={selectedVersion} account={activeAccount} />
|
<PlaySection version={selectedVersion} activeAccount={activeAccount} setActiveAccount={setActiveAccount} accounts={accounts} setAccounts={setAccounts} />
|
||||||
)}
|
)}
|
||||||
{active === "mods" && selectedVersion && (
|
{active === "mods" && selectedVersion && (
|
||||||
<ModsSection version={selectedVersion} />
|
<ModsSection version={selectedVersion} />
|
||||||
|
|||||||
@@ -1,19 +1,22 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { Play, Loader2 } from "lucide-react";
|
import { Play, Loader2 } from "lucide-react";
|
||||||
// import { launchGame } from "../services/SaturnApi";
|
|
||||||
import Bg from "@/assets/bg.png";
|
import Bg from "@/assets/bg.png";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
import { GameVersion } from "@/lib/types";
|
import { GameVersion } from "@/lib/types";
|
||||||
import { launch } from "@/lib/launcher";
|
import { launch } from "@/lib/launcher";
|
||||||
import { MinecraftAccount } from "@/lib/auth";
|
import { authGetValid } from "@/lib/auth";
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
import { SetState } from "./layout/props";
|
||||||
|
|
||||||
interface PlaySectionProps {
|
interface PlaySectionProps {
|
||||||
version: GameVersion | null;
|
version: GameVersion | null;
|
||||||
account: MinecraftAccount | null;
|
activeAccount: [string, string] | null;
|
||||||
|
setActiveAccount: SetState<[string, string] | null>,
|
||||||
|
accounts: [string, string][],
|
||||||
|
setAccounts: SetState<[string, string][]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const PlaySection: React.FC<PlaySectionProps> = ({ version, account }) => {
|
const PlaySection: React.FC<PlaySectionProps> = ({ version, activeAccount: account }) => {
|
||||||
const [isLaunching, setIsLaunching] = useState(false);
|
const [isLaunching, setIsLaunching] = useState(false);
|
||||||
const [launchStatus, setLaunchStatus] = useState("");
|
const [launchStatus, setLaunchStatus] = useState("");
|
||||||
const [progress, setProgress] = useState(0);
|
const [progress, setProgress] = useState(0);
|
||||||
@@ -39,6 +42,13 @@ const PlaySection: React.FC<PlaySectionProps> = ({ version, account }) => {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleLaunch = async () => {
|
||||||
|
if (version && account) {
|
||||||
|
const validAccount = await authGetValid(account[0]);
|
||||||
|
launch(version, validAccount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full relative">
|
<div className="h-full relative">
|
||||||
{/* Background Image */}
|
{/* Background Image */}
|
||||||
@@ -54,7 +64,7 @@ const PlaySection: React.FC<PlaySectionProps> = ({ version, account }) => {
|
|||||||
<div className="absolute -inset-1 bg-linear-to-r from-blue-600 to-cyan-500 rounded-lg blur opacity-25 group-hover:opacity-50 transition duration-1000 group-hover:duration-200"></div>
|
<div className="absolute -inset-1 bg-linear-to-r from-blue-600 to-cyan-500 rounded-lg blur opacity-25 group-hover:opacity-50 transition duration-1000 group-hover:duration-200"></div>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
onClick={() => version && account && launch(version, account)}
|
onClick={handleLaunch}
|
||||||
disabled={isLaunching || !version || !account}
|
disabled={isLaunching || !version || !account}
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative btn-primary px-16 py-4 text-xl flex items-center gap-3 min-w-60 justify-center",
|
"relative btn-primary px-16 py-4 text-xl flex items-center gap-3 min-w-60 justify-center",
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import {
|
|||||||
authRemove,
|
authRemove,
|
||||||
authCreateLink,
|
authCreateLink,
|
||||||
authLogin,
|
authLogin,
|
||||||
MinecraftAccount,
|
|
||||||
} from "@/lib/auth";
|
} from "@/lib/auth";
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { listen } from "@tauri-apps/api/event";
|
||||||
|
|
||||||
@@ -64,7 +63,7 @@ export default function AccountDropdown({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Switch account
|
// Switch account
|
||||||
function switchAccount(acc: MinecraftAccount) {
|
function switchAccount(acc: [string, string]) {
|
||||||
setActiveAccount(acc);
|
setActiveAccount(acc);
|
||||||
setIsAccountDropdownOpen(false);
|
setIsAccountDropdownOpen(false);
|
||||||
}
|
}
|
||||||
@@ -73,7 +72,7 @@ export default function AccountDropdown({
|
|||||||
async function logout() {
|
async function logout() {
|
||||||
if (!activeAccount) return;
|
if (!activeAccount) return;
|
||||||
|
|
||||||
await authRemove(activeAccount.uuid);
|
await authRemove(activeAccount[0]);
|
||||||
|
|
||||||
const updated = await authList();
|
const updated = await authList();
|
||||||
setAccounts(updated);
|
setAccounts(updated);
|
||||||
@@ -91,7 +90,7 @@ export default function AccountDropdown({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const otherAccounts = accounts.filter((a) => a.uuid !== activeAccount?.uuid);
|
const otherAccounts = accounts.filter((a) => a[0] !== activeAccount?.[0]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={accountRef} className="relative group overflow-visible">
|
<div ref={accountRef} className="relative group overflow-visible">
|
||||||
@@ -106,7 +105,7 @@ export default function AccountDropdown({
|
|||||||
<div className="absolute -top-2 left-4 group-hover:scale-110 transition-transform duration-700 w-12 overflow-hidden z-20">
|
<div className="absolute -top-2 left-4 group-hover:scale-110 transition-transform duration-700 w-12 overflow-hidden z-20">
|
||||||
{activeAccount && (
|
{activeAccount && (
|
||||||
<img
|
<img
|
||||||
src={`https://render.crafty.gg/3d/bust/${activeAccount.uuid}`}
|
src={`https://render.crafty.gg/3d/bust/${activeAccount[0]}`}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
@@ -123,7 +122,7 @@ export default function AccountDropdown({
|
|||||||
Playing as
|
Playing as
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm font-bold text-white">
|
<p className="text-sm font-bold text-white">
|
||||||
{activeAccount?.username || "No Account"}
|
{activeAccount?.[1] || "No Account"}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</button>
|
</button>
|
||||||
@@ -140,17 +139,17 @@ export default function AccountDropdown({
|
|||||||
{/* Current account */}
|
{/* Current account */}
|
||||||
{activeAccount && (
|
{activeAccount && (
|
||||||
<UserComponent
|
<UserComponent
|
||||||
username={activeAccount.username}
|
username={activeAccount[1]}
|
||||||
uuid={activeAccount.uuid}
|
uuid={activeAccount[0]}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Other accounts */}
|
{/* Other accounts */}
|
||||||
{otherAccounts.map((acc) => (
|
{otherAccounts.map((acc) => (
|
||||||
<UserComponent
|
<UserComponent
|
||||||
key={acc.uuid}
|
key={acc[0]}
|
||||||
username={acc.username}
|
username={acc[1]}
|
||||||
uuid={acc.uuid}
|
uuid={acc[0]}
|
||||||
onClick={() => switchAccount(acc)}
|
onClick={() => switchAccount(acc)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { MinecraftAccount } from "@/lib/auth";
|
|
||||||
import { GameVersion } from "@/lib/types";
|
import { GameVersion } from "@/lib/types";
|
||||||
|
|
||||||
export type SetState<T> = React.Dispatch<React.SetStateAction<T>>;
|
export type SetState<T> = React.Dispatch<React.SetStateAction<T>>;
|
||||||
@@ -17,9 +16,9 @@ export interface Props {
|
|||||||
versionRef: React.RefObject<HTMLDivElement | null>;
|
versionRef: React.RefObject<HTMLDivElement | null>;
|
||||||
accountRef: React.RefObject<HTMLDivElement | null>;
|
accountRef: React.RefObject<HTMLDivElement | null>;
|
||||||
|
|
||||||
accounts: MinecraftAccount[];
|
accounts: [string, string][];
|
||||||
setAccounts: SetState<MinecraftAccount[]>;
|
setAccounts: SetState<[string, string][]>;
|
||||||
|
|
||||||
activeAccount: MinecraftAccount | null;
|
activeAccount: [string, string] | null;
|
||||||
setActiveAccount: SetState<MinecraftAccount | null>;
|
setActiveAccount: SetState<[string, string] | null>;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -33,8 +33,9 @@ export async function authRefresh(uuid: string): Promise<MinecraftAccount> {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all stored accounts
|
* Get all stored accounts
|
||||||
|
* Format [UUID, Username]
|
||||||
*/
|
*/
|
||||||
export async function authList(): Promise<MinecraftAccount[]> {
|
export async function authList(): Promise<[string, string][]> {
|
||||||
return await invoke("auth_list");
|
return await invoke("auth_list");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user