[feat] basic steam user parse

todo: steamid32 + avatar
This commit is contained in:
Purp1e
2025-03-23 21:55:17 +08:00
parent 03e5704a6e
commit 45e4ab1c6a
23 changed files with 6158 additions and 50 deletions

View File

@@ -10,7 +10,7 @@ export default function Page() {
<p>{steam.state.cs2Dir}</p>
<p>Steam路径有效{steam.state.steamDirValid ? "是" : "否"}</p>
<p>{steam.state.cs2DirValid ? "是" : "否"}</p>
<p>Steam账号{steam.currentUser()?.accountName || " "}</p>
<p>Steam账号{steam.currentUser()?.account_name || " "}</p>
</div>
)
}

View File

@@ -15,12 +15,18 @@ export default function RootLayout({ children }: { children: React.ReactNode })
const steam = useSteamStore()
const debounceSteamDir = useDebounce(steam.state.steamDir, {wait: 500, leading: true, trailing: true, maxWait: 2500})
const debounceCs2Dir = useDebounce(steam.state.cs2Dir, {wait: 500, leading: true, trailing: true, maxWait: 2500})
const debounceSteamDirValid = useDebounce(steam.state.steamDirValid, {wait: 500, leading: true, trailing: true, maxWait: 2500})
useEffect(() => {
void steam.checkSteamDirValid()
}, [debounceSteamDir])
useEffect(() => {
void steam.checkCs2DirValid()
}, [debounceCs2Dir])
useEffect(() => {
if (debounceSteamDirValid) {
void steam.getUsers()
}
}, [debounceSteamDirValid])
return (
<html lang="en">

View File

@@ -1,10 +1,23 @@
import { User } from "@icon-park/react"
import { Card, CardBody, CardHeader, CardIcon } from "../window/Card"
import { Button, Chip } from "@heroui/react"
import { Refresh, User } from "@icon-park/react"
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { addToast, Button, Chip } from "@heroui/react"
import { useSteamStore } from "@/store/steam"
import { ToolButton } from "../window/ToolButton"
import { useAutoAnimate } from "@formkit/auto-animate/react"
const SteamUsers = ({ className }: { className?: string }) => {
const steam = useSteamStore()
const [parent /* , enableAnimations */] = useAutoAnimate(/* optional config */)
const getUsers = async (toast?: boolean) => {
if (!steam.state.steamDirValid) {
if (toast) addToast({ title: "Steam路径不可用", color: "warning" })
return
}
await steam.getUsers()
if (toast) addToast({ title: `已获取Steam用户` })
}
return (
<Card /* className={cn("max-w-96", className)} */>
@@ -12,12 +25,18 @@ const SteamUsers = ({ className }: { className?: string }) => {
<CardIcon>
<User /> Steam用户
</CardIcon>
<CardTool>
<ToolButton onClick={() => getUsers(true)}>
<Refresh />
</ToolButton>
</CardTool>
</CardHeader>
<CardBody>
<ul>
{steam.state.users.map((user) => (
<ul className="flex flex-col gap-3 mt-1" ref={parent}>
{steam.state.users.map((user, id) => (
<li
key={user.accountName}
key={user.account_name}
className="flex gap-2 transition rounded-lg bg-zinc-50 dark:bg-zinc-900"
>
<img
@@ -26,22 +45,33 @@ const SteamUsers = ({ className }: { className?: string }) => {
className="w-20 h-20 rounded-l-lg"
/>
<div className="flex flex-col flex-grow justify-center gap-2 p-0.5">
<h3 className="text-2xl font-semibold">{user.personaName}</h3>
<h3 className="text-xl font-semibold">{user.persona_name}</h3>
<div className="flex gap-3">
<Chip size="sm" className="bg-zinc-200 dark:bg-zinc-800">
{user.accountName}
{user.account_name}
</Chip>
<Chip size="sm" className="bg-zinc-200 dark:bg-zinc-800">
{user.steamID32}
{user.steam_id32}
</Chip>
<Chip size="sm" className="bg-zinc-200 dark:bg-zinc-800">
{user.steamID64}
{user.steam_id64?.toString()}
</Chip>
<Chip size="sm" className="bg-zinc-200 dark:bg-zinc-800">
{user.recent}
</Chip>
<Chip size="sm" className="bg-zinc-200 dark:bg-zinc-800">
{user.avatar}
</Chip>
</div>
</div>
<div className="flex items-end gap-2 p-2">
<Button size="sm"></Button>
<Button size="sm"></Button>
<Button size="sm" onPress={() => steam.switchLoginUser(id)}>
</Button>
<Button size="sm" onPress={() => steam.selectUser(id)}>
</Button>
</div>
</li>
))}

View File

@@ -146,7 +146,7 @@ const VideoSetting = () => {
</span>
</li>
{videoSettings.map((vid, index) => (
<li className="flex flex-col gap-1.5">
<li className="flex flex-col gap-1.5" key={index}>
<span className="ml-2">{vid.title}</span>
<Tabs
selectedKey={vid.value}

View File

@@ -5,11 +5,11 @@ const Header = () => {
return (
<div className="pt-6 select-none pb-9" data-tauri-drag-region>
<h1 className="mb-0.5 text-xl font-medium tracking-wide w-fit">
{steam.currentUser()?.personaName || 'CS工具箱'}
<h1 className="mb-0.5 text-xl font-semibold tracking-wide w-fit">
{steam.currentUser()?.persona_name || 'CS工具箱'}
</h1>
<p className="text-sm font-light tracking-wide text-zinc-400 w-fit">
{steam.currentUser()?.accountName || '本周使用CS工具箱 114 小时'}
{steam.currentUser()?.account_name || '本周使用CS工具箱 114 小时'}
</p>
</div>
)

View File

@@ -37,6 +37,9 @@ export const useSteamStore = () => {
checkSteamDirValid,
checkCs2DirValid,
currentUser,
getUsers,
selectUser,
switchLoginUser,
resetSteamStore,
}
}
@@ -61,29 +64,29 @@ const setCs2DirValid = (valid: boolean) => {
steamStore.state.cs2DirValid = valid
}
const SetSteamDirChecking = (checking: boolean) => {
const setSteamDirChecking = (checking: boolean) => {
steamStore.state.steamDirChecking = checking
}
const SetCs2DirChecking = (checking: boolean) => {
const setCs2DirChecking = (checking: boolean) => {
steamStore.state.cs2DirChecking = checking
}
const checkSteamDirValid = async () => {
SetSteamDirChecking(true)
setSteamDirChecking(true)
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.steamDir })
setSteamDirValid(pathExist)
setTimeout(() => {
SetSteamDirChecking(false)
setSteamDirChecking(false)
}, 500)
}
const checkCs2DirValid = async () => {
SetCs2DirChecking(true)
setCs2DirChecking(true)
const pathExist = await invoke<boolean>("check_path", { path: steamStore.state.cs2Dir })
setCs2DirValid(pathExist)
setTimeout(() => {
SetCs2DirChecking(false)
setCs2DirChecking(false)
}, 500)
}
@@ -91,12 +94,37 @@ const currentUser = () => {
return steamStore.state.users.at(0) || undefined
}
const getUsers = async () => {
const users = await invoke<SteamUser[]>("get_steam_users", { steamDir: steamStore.state.steamDir })
console.log(users)
setUsers(users)
}
const selectUser = async (index: number) => {
const user = steamStore.state.users.at(index)
console.log(index, user)
if (user) {
setUsers([
user,
...steamStore.state.users.slice(0, index),
...steamStore.state.users.slice(index + 1),
])
}
}
const switchLoginUser = async (index: number) => {
const user = steamStore.state.users.at(index)
if (user) {
await invoke<SteamUser[]>("set_auto_login_user", { user: user.account_name })
}
}
const resetSteamStore = () => {
setDir(defaultValue.steamDir)
setCsDir(defaultValue.cs2Dir)
setUsers(defaultValue.users)
setSteamDirValid(defaultValue.steamDirValid)
setCs2DirValid(defaultValue.cs2DirValid)
SetSteamDirChecking(defaultValue.steamDirChecking)
SetCs2DirChecking(defaultValue.cs2DirChecking)
setSteamDirChecking(defaultValue.steamDirChecking)
setCs2DirChecking(defaultValue.cs2DirChecking)
}

View File

@@ -1,10 +1,10 @@
import type { AdvancedListItem } from "@/types/common"
export interface SteamUser extends AdvancedListItem {
steamID64: string
steamID32: string
accountName: string
personaName: string
steam_id64: BigInt
steam_id32: number
account_name: string
persona_name: string
recent: number
avatar: string
}