[dep] update to eslint 9

This commit is contained in:
Purp1e
2024-11-11 10:04:00 +08:00
parent e308309fb8
commit b1d505fd6b
36 changed files with 353 additions and 218 deletions

View File

@@ -7,13 +7,22 @@
], ],
"parser": "@typescript-eslint/parser", "parser": "@typescript-eslint/parser",
"parserOptions": { "parserOptions": {
"project": ["./tsconfig.json"] "project": [
"./tsconfig.json"
]
}, },
"plugins": ["@typescript-eslint"], "plugins": [
"@typescript-eslint"
],
"rules": { "rules": {
"eqeqeq": "error", "eqeqeq": "error",
"no-else-return": "error", "no-else-return": "error",
"no-implicit-coercion": ["error", { "disallowTemplateShorthand": true }], "no-implicit-coercion": [
"error",
{
"disallowTemplateShorthand": true
}
],
"no-unneeded-ternary": "error", "no-unneeded-ternary": "error",
"no-useless-call": "error", "no-useless-call": "error",
"no-useless-computed-key": "error", "no-useless-computed-key": "error",
@@ -23,7 +32,10 @@
"prefer-rest-params": "error", "prefer-rest-params": "error",
"prefer-spread": "error", "prefer-spread": "error",
"prefer-template": "error", "prefer-template": "error",
"radix": ["error", "always"], "radix": [
"error",
"always"
],
"react-hooks/exhaustive-deps": "error", "react-hooks/exhaustive-deps": "error",
"@typescript-eslint/no-misused-promises": [ "@typescript-eslint/no-misused-promises": [
"error", "error",
@@ -31,9 +43,10 @@
"checksVoidReturn": false "checksVoidReturn": false
} }
], ],
"@typescript-eslint/no-confusing-void-expression":"off", "@typescript-eslint/no-confusing-void-expression": "off",
"@typescript-eslint/no-unsafe-return": "off", "@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-unsafe-call": "off", "@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off" "@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/no-unsafe-member-access": "warn"
} }
} }

View File

@@ -1,5 +1,5 @@
{ {
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json", "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
"organizeImports": { "organizeImports": {
"enabled": true "enabled": true
}, },
@@ -18,7 +18,7 @@
"formatter": { "formatter": {
"semicolons": "asNeeded", "semicolons": "asNeeded",
"lineEnding": "lf", "lineEnding": "lf",
"trailingComma": "all" "trailingCommas": "all"
} }
} }
} }

BIN
bun.lockb

Binary file not shown.

View File

@@ -7,12 +7,13 @@
"email": "zx8244@qq.com" "email": "zx8244@qq.com"
}, },
"scripts": { "scripts": {
"next-start": "cross-env BROWSER=none next dev", "next-start": "cross-env BROWSER=none next dev --turbo",
"next-build": "next build", "next-build": "next build",
"tauri": "tauri", "tauri": "tauri",
"build": "tauri build", "build": "tauri build",
"dev": "tauri dev", "dev": "tauri dev",
"lint": "next lint && biome check src/", "lint": "next lint && biome check src/",
"fix": "next lint --fix && biome check src/ --fix",
"prepare": "husky" "prepare": "husky"
}, },
"dependencies": { "dependencies": {
@@ -54,8 +55,8 @@
"clsx": "^2.1.1", "clsx": "^2.1.1",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"cssnano": "^7.0.6", "cssnano": "^7.0.6",
"eslint": "^8.57.1", "eslint": "9.14.0",
"eslint-config-next": "^14.2.17", "eslint-config-next": "15.0.3",
"husky": "^9.1.6", "husky": "^9.1.6",
"lint-staged": "^15.2.10", "lint-staged": "^15.2.10",
"postcss": "^8.4.48", "postcss": "^8.4.48",

View File

@@ -1,3 +1,3 @@
export default function Page() { export default function Page() {
return <div>Console</div>; return <div>Console</div>
} }

View File

@@ -1,3 +1,3 @@
export default function Page() { export default function Page() {
return <div>Gear</div>; return <div>Gear</div>
} }

View File

@@ -1,12 +1,12 @@
"use client"; "use client"
import CommonDir from "@/components/cstb/CommonDir"; import CommonDir from "@/components/cstb/CommonDir"
import FastLaunch from "@/components/cstb/FastLaunch"; import FastLaunch from "@/components/cstb/FastLaunch"
import ForceQuit from "@/components/cstb/ForceQuit"; import ForceQuit from "@/components/cstb/ForceQuit"
import LaunchOption from "@/components/cstb/LaunchOption"; import LaunchOption from "@/components/cstb/LaunchOption"
import Notice from "@/components/cstb/Notice"; import Notice from "@/components/cstb/Notice"
import PowerPlan from "@/components/cstb/PowerPlan"; import PowerPlan from "@/components/cstb/PowerPlan"
import SmartTransfer from "@/components/cstb/SmartTranser"; import SmartTransfer from "@/components/cstb/SmartTranser"
const Home = () => { const Home = () => {
return ( return (
@@ -25,7 +25,7 @@ const Home = () => {
<FastLaunch /> <FastLaunch />
</div> </div>
</section> </section>
); )
}; }
export default Home; export default Home

View File

@@ -1,14 +1,14 @@
"use client" "use client"
import Header from "@/components/window/Header"; import Header from "@/components/window/Header"
import Nav from "@/components/window/Nav"; import Nav from "@/components/window/Nav"
import SideBar from "@/components/window/SideBar"; import SideBar from "@/components/window/SideBar"
import clsx from "clsx"; import clsx from "clsx"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
export default function BaseLayout({ export default function BaseLayout({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode
}) { }) {
return ( return (
<div className="w-full h-full bg-transparent"> <div className="w-full h-full bg-transparent">
@@ -20,7 +20,7 @@ export default function BaseLayout({
<main <main
className={clsx( className={clsx(
"flex flex-col h-full pb-5 pr-5 ml-20 overflow-hidden" "flex flex-col h-full pb-5 pr-5 ml-20 overflow-hidden",
// platform() === "windows" ? "ml-20" : "ml-[4.25rem]" // platform() === "windows" ? "ml-20" : "ml-[4.25rem]"
)} )}
> >

View File

@@ -1,3 +1,3 @@
export default function Page() { export default function Page() {
return <div>Movie</div>; return <div>Movie</div>
} }

View File

@@ -1,12 +1,26 @@
"use client" "use client"
import { Card, CardHeader, CardIcon, CardTool, CardBody } from "@/components/window/Card" import {
Card,
CardBody,
CardHeader,
CardIcon,
CardTool,
} from "@/components/window/Card"
import { ToolButton } from "@/components/window/ToolButton" import { ToolButton } from "@/components/window/ToolButton"
import { SettingConfig, UploadOne, HardDisk, AssemblyLine, Videocamera } from "@icon-park/react" import {
AssemblyLine,
HardDisk,
SettingConfig,
UploadOne,
Videocamera,
} from "@icon-park/react"
import clsx from "clsx" import clsx from "clsx"
import { usePathname, useRouter } from "next/navigation" import { usePathname, useRouter } from "next/navigation"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
export default function PreferenceLayout({ children }: { children: React.ReactNode }) { export default function PreferenceLayout({
children,
}: { children: React.ReactNode }) {
const router = useRouter() const router = useRouter()
const pathname = usePathname() const pathname = usePathname()

View File

@@ -1,3 +1,3 @@
export default function Page() { export default function Page() {
return <div>Tool</div>; return <div>Tool</div>
} }

View File

@@ -8,8 +8,8 @@ body {
margin: 0; margin: 0;
width: 100%; width: 100%;
height: 100%; height: 100%;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
/* background: transparent; */ /* background: transparent; */
background: rgba(242, 241, 243, 0.65); background: rgba(242, 241, 243, 0.65);
border-radius: 10px; border-radius: 10px;

View File

@@ -2,9 +2,9 @@ export const metadata = {
title: "CS工具箱", title: "CS工具箱",
description: "Generated by Next.js", description: "Generated by Next.js",
icons: ["/favicon.ico"], icons: ["/favicon.ico"],
}; }
import "./globals.css"; import "./globals.css"
export default function RootLayout({ export default function RootLayout({
children, children,

View File

@@ -1,20 +1,26 @@
"use client"; "use client"
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation"
const Home = () => { const Home = () => {
const router = useRouter(); const router = useRouter()
return ( return (
<main <main
className="flex flex-col items-center justify-center w-full h-screen gap-6" className="flex flex-col items-center justify-center w-full h-screen gap-6"
data-tauri-drag-region data-tauri-drag-region
> >
<h1 className="text-4xl font-bold tracking-wide text-zinc-800">CS </h1> <h1 className="text-4xl font-bold tracking-wide text-zinc-800">
<button onClick={() => router.push("/home")} className="px-4 py-1 rounded bg-zinc-200"> CS
</h1>
<button
type="button"
onClick={() => router.push("/home")}
className="px-4 py-1 rounded bg-zinc-200"
>
</button> </button>
</main> </main>
) )
}; }
export default Home; export default Home

View File

@@ -1,6 +1,8 @@
import Nav from "@/components/window/Nav" import Nav from "@/components/window/Nav"
export default function BaseLayout({ children }: { children: React.ReactNode }) { export default function BaseLayout({
children,
}: { children: React.ReactNode }) {
return ( return (
<div className="w-full h-full"> <div className="w-full h-full">
<Nav /> <Nav />

View File

@@ -8,7 +8,9 @@ export default function Page() {
className="flex flex-col items-center justify-center w-full h-screen gap-6" className="flex flex-col items-center justify-center w-full h-screen gap-6"
data-tauri-drag-region data-tauri-drag-region
> >
<h1 className="text-4xl font-bold tracking-wide text-zinc-800">CS工具箱</h1> <h1 className="text-4xl font-bold tracking-wide text-zinc-800">
CS工具箱
</h1>
<p></p> <p></p>
<div className="flex flex-col w-full gap-6 p-5 border rounded-lg bg-white/40"> <div className="flex flex-col w-full gap-6 p-5 border rounded-lg bg-white/40">

View File

@@ -1,27 +1,27 @@
"use client" "use client"
import { CardButton } from "@/components/test/CardButton"; import { CardButton } from "@/components/test/CardButton"
import { useGlobalShortcut } from "@/hooks/tauri/shortcuts"; import { useGlobalShortcut } from "@/hooks/tauri/shortcuts"
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core"
import { useCallback, useState } from "react"; import { useCallback, useState } from "react"
export default function Page() { export default function Page() {
const [buttonDesc, setButtonDesc] = useState<string>( const [buttonDesc, setButtonDesc] = useState<string>(
"Waiting to be clicked. This calls 'on_button_clicked' from Rust." "Waiting to be clicked. This calls 'on_button_clicked' from Rust.",
); )
const onButtonClick = () => { const onButtonClick = () => {
invoke<string>("on_button_clicked") invoke<string>("on_button_clicked")
.then((value) => { .then((value) => {
setButtonDesc(value); setButtonDesc(value)
}) })
.catch(() => { .catch(() => {
setButtonDesc("Failed to invoke Rust command 'on_button_clicked'"); setButtonDesc("Failed to invoke Rust command 'on_button_clicked'")
}); })
}; }
const shortcutHandler = useCallback(() => { const shortcutHandler = useCallback(() => {
console.log("Ctrl+P was pressed!"); console.log("Ctrl+P was pressed!")
}, []); }, [])
useGlobalShortcut("CommandOrControl+P", shortcutHandler); useGlobalShortcut("CommandOrControl+P", shortcutHandler)
return ( return (
<div className="flex flex-col"> <div className="flex flex-col">
@@ -54,5 +54,5 @@ export default function Page() {
</div> </div>
</main> </main>
</div> </div>
); )
} }

View File

@@ -1,17 +1,20 @@
import { FolderFocusOne } from "@icon-park/react"; import { FolderFocusOne } from "@icon-park/react"
import { Card, CardHeader, CardIcon, CardBody } from "../window/Card"; import { Card, CardBody, CardHeader, CardIcon } from "../window/Card"
interface RoundedButtonProps { interface RoundedButtonProps {
children?: React.ReactNode; children?: React.ReactNode
} }
const RoundedButton = ({ children }: RoundedButtonProps) => { const RoundedButton = ({ children }: RoundedButtonProps) => {
return ( return (
<button className="flex items-center justify-center px-3 py-1 transition rounded-full min-w-fit active:scale-95 hover:bg-black/10 text-zinc-700 bg-black/5"> <button
type="button"
className="flex items-center justify-center px-3 py-1 transition rounded-full min-w-fit active:scale-95 hover:bg-black/10 text-zinc-700 bg-black/5"
>
{children} {children}
</button> </button>
); )
}; }
const CommonDir = () => { const CommonDir = () => {
return ( return (
@@ -33,7 +36,7 @@ const CommonDir = () => {
</div> </div>
</CardBody> </CardBody>
</Card> </Card>
); )
}; }
export default CommonDir; export default CommonDir

View File

@@ -1,6 +1,6 @@
import { TakeOff } from "@icon-park/react"; import { TakeOff } from "@icon-park/react"
import { Card, CardHeader, CardIcon, CardBody } from "../window/Card";
import { invoke } from "@tauri-apps/api/core" import { invoke } from "@tauri-apps/api/core"
import { Card, CardBody, CardHeader, CardIcon } from "../window/Card"
const FastLaunch = () => { const FastLaunch = () => {
return ( return (
@@ -13,6 +13,7 @@ const FastLaunch = () => {
<CardBody> <CardBody>
<div className="flex gap-2"> <div className="flex gap-2">
<button <button
type="button"
onClick={() => onClick={() =>
invoke("launch_game", { invoke("launch_game", {
// steamPath: steam.dir + "/steam.exe", // steamPath: steam.dir + "/steam.exe",
@@ -25,6 +26,7 @@ const FastLaunch = () => {
</button> </button>
<button <button
type="button"
onClick={() => onClick={() =>
invoke("launch_game", { invoke("launch_game", {
// steamPath: steam.dir + "/steam.exe", // steamPath: steam.dir + "/steam.exe",
@@ -40,6 +42,6 @@ const FastLaunch = () => {
</CardBody> </CardBody>
</Card> </Card>
) )
}; }
export default FastLaunch; export default FastLaunch

View File

@@ -1,6 +1,6 @@
import { Power } from "@icon-park/react"; import { Power } from "@icon-park/react"
import { Card, CardHeader, CardIcon, CardBody } from "../window/Card"; import { invoke } from "@tauri-apps/api/core"
import { invoke } from "@tauri-apps/api/core"; import { Card, CardBody, CardHeader, CardIcon } from "../window/Card"
const ForceQuit = () => { const ForceQuit = () => {
return ( return (
@@ -12,12 +12,24 @@ const ForceQuit = () => {
</CardHeader> </CardHeader>
<CardBody> <CardBody>
<div className="flex gap-2"> <div className="flex gap-2">
<button onClick={() => invoke("kill_steam")} className="px-5 font-medium py-1.5 transition bg-blue-200 rounded-full">Steam</button> <button
<button onClick={() => invoke("kill_game")} className="px-5 font-medium py-1.5 transition bg-orange-200 rounded-full">CS2</button> type="button"
onClick={() => invoke("kill_steam")}
className="px-5 font-medium py-1.5 transition bg-blue-200 rounded-full"
>
Steam
</button>
<button
type="button"
onClick={() => invoke("kill_game")}
className="px-5 font-medium py-1.5 transition bg-orange-200 rounded-full"
>
CS2
</button>
</div> </div>
</CardBody> </CardBody>
</Card> </Card>
); )
}; }
export default ForceQuit; export default ForceQuit

View File

@@ -1,10 +1,11 @@
import { Plus, SettingConfig, Switch } from "@icon-park/react"; import useToolStore from "@/store/tool"
import { Card, CardHeader, CardIcon, CardTool, CardBody } from "../window/Card"; import { Plus, SettingConfig, Switch } from "@icon-park/react"
import { ToolButton } from "../window/ToolButton"; import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import useToolStore from "@/store/tool"; import { ToolButton } from "../window/ToolButton"
const LaunchOption = () => { const LaunchOption = () => {
const { launchOptions, setLaunchOption, launchIndex, setLaunchIndex } = useToolStore() const { launchOptions, setLaunchOption, launchIndex, setLaunchIndex } =
useToolStore()
return ( return (
<Card> <Card>
@@ -35,7 +36,7 @@ const LaunchOption = () => {
/> />
</CardBody> </CardBody>
</Card> </Card>
); )
}; }
export default LaunchOption; export default LaunchOption

View File

@@ -1,16 +1,16 @@
import { Refresh, VolumeNotice } from "@icon-park/react";
import { import {
Card,
CardBody,
CardHeader, CardHeader,
CardIcon, CardIcon,
CardTool, CardTool,
CardBody, } from "@/components/window/Card"
Card, import useAppStore from "@/store/app"
} from "@/components/window/Card"; import { Refresh, VolumeNotice } from "@icon-park/react"
import { ToolButton } from "../window/ToolButton"; import { ToolButton } from "../window/ToolButton"
import useAppStore from "@/store/app";
const Notice = () => { const Notice = () => {
const app = useAppStore(); const app = useAppStore()
return ( return (
<Card> <Card>
<CardHeader> <CardHeader>
@@ -24,9 +24,11 @@ const Notice = () => {
</ToolButton> </ToolButton>
</CardTool> </CardTool>
</CardHeader> </CardHeader>
<CardBody>{app.notice || "不会真的有人要更新CSGO工具箱吧不会吧不会吧 xswl"}</CardBody> <CardBody>
{app.notice || "不会真的有人要更新CSGO工具箱吧不会吧不会吧 xswl"}
</CardBody>
</Card> </Card>
) )
}; }
export default Notice; export default Notice

View File

@@ -1,7 +1,7 @@
import { BatteryCharge, Refresh } from "@icon-park/react"; import { BatteryCharge, Refresh } from "@icon-park/react"
import { Card, CardHeader, CardIcon, CardTool, CardBody } from "../window/Card"; import { invoke } from "@tauri-apps/api/core"
import { ToolButton } from "../window/ToolButton"; import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { invoke } from "@tauri-apps/api/core"; import { ToolButton } from "../window/ToolButton"
const PowerPlan = () => { const PowerPlan = () => {
return ( return (
@@ -19,13 +19,31 @@ const PowerPlan = () => {
</CardHeader> </CardHeader>
<CardBody> <CardBody>
<div className="flex p-0.5 bg-black/5 gap-2 rounded-full"> <div className="flex p-0.5 bg-black/5 gap-2 rounded-full">
<button onClick={() => invoke("set_power_plan", {index: 1})} className="flex-1 px-2 py-1 transition rounded-full bg-black/5"></button> <button
<button onClick={() => invoke("set_power_plan", {index: 2})} className="flex-1 px-2 py-1 transition rounded-full"></button> type="button"
<button onClick={() => invoke("set_power_plan", {index: 3})} className="flex-1 px-2 py-1 transition rounded-full"></button> onClick={() => invoke("set_power_plan", { index: 1 })}
className="flex-1 px-2 py-1 transition rounded-full bg-black/5"
>
</button>
<button
type="button"
onClick={() => invoke("set_power_plan", { index: 2 })}
className="flex-1 px-2 py-1 transition rounded-full"
>
</button>
<button
type="button"
onClick={() => invoke("set_power_plan", { index: 3 })}
className="flex-1 px-2 py-1 transition rounded-full"
>
</button>
</div> </div>
</CardBody> </CardBody>
</Card> </Card>
); )
}; }
export default PowerPlan; export default PowerPlan

View File

@@ -1,6 +1,6 @@
import { FolderConversion, FolderPlus } from "@icon-park/react"; import { FolderConversion, FolderPlus } from "@icon-park/react"
import { Card, CardHeader, CardIcon, CardTool, CardBody } from "../window/Card"; import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { ToolButton } from "../window/ToolButton"; import { ToolButton } from "../window/ToolButton"
const SmartTransfer = () => { const SmartTransfer = () => {
return ( return (
@@ -22,7 +22,7 @@ const SmartTransfer = () => {
</div> </div>
</CardBody> </CardBody>
</Card> </Card>
); )
}; }
export default SmartTransfer; export default SmartTransfer

View File

@@ -1,5 +1,5 @@
import { ReactNode } from "react"
import clsx from "clsx" import clsx from "clsx"
import type { ReactNode } from "react"
interface CardProps { interface CardProps {
children?: ReactNode children?: ReactNode
@@ -20,23 +20,41 @@ const Card = ({ children }: CardProps) => {
} }
const CardHeader = ({ children }: CardProps) => { const CardHeader = ({ children }: CardProps) => {
return <div className="flex items-center gap-1.5 tracking-wide">{children}</div> return (
<div className="flex items-center gap-1.5 tracking-wide">{children}</div>
)
} }
const CardIcon = ({ children, type, className, ...rest }: CardProps) => { const CardIcon = ({ children, type, className, ...rest }: CardProps) => {
return ( return (
<div className={clsx("flex gap-1.5 items-center font-semibold", type === "menu" && "transition cursor-pointer hover:bg-black/5 px-2 py-1 rounded-md active:scale-95", className)} {...rest}> <div
className={clsx(
"flex gap-1.5 items-center font-semibold",
type === "menu" &&
"transition cursor-pointer hover:bg-black/5 px-2 py-1 rounded-md active:scale-95",
className,
)}
{...rest}
>
{children} {children}
</div> </div>
) )
} }
const CardTool = ({ children }: CardProps) => { const CardTool = ({ children }: CardProps) => {
return <div className="flex items-center justify-end flex-grow gap-2">{children}</div> return (
<div className="flex items-center justify-end flex-grow gap-2">
{children}
</div>
)
} }
const CardBody = ({ children }: CardProps) => { const CardBody = ({ children }: CardProps) => {
return <div className="w-full h-full text-sm tracking-wide text-zinc-800">{children}</div> return (
<div className="w-full h-full text-sm tracking-wide text-zinc-800">
{children}
</div>
)
} }
export { Card, CardHeader, CardIcon, CardTool, CardBody } export { Card, CardHeader, CardIcon, CardTool, CardBody }

View File

@@ -8,7 +8,7 @@ const Header = () => {
使CS工具箱 114 使CS工具箱 114
</p> </p>
</div> </div>
); )
}; }
export default Header; export default Header

View File

@@ -1,9 +1,9 @@
"use client" "use client"
import { RocketOne, Minus, Close, Square } from "@icon-park/react" import { Close, Minus, RocketOne, Square } from "@icon-park/react"
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { getCurrentWindow } from "@tauri-apps/api/window" import { getCurrentWindow } from "@tauri-apps/api/window"
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
import { useRouter, usePathname } from "next/navigation" import { usePathname, useRouter } from "next/navigation"
const Nav = () => { const Nav = () => {
const close = async () => { const close = async () => {
@@ -35,10 +35,16 @@ const Nav = () => {
const pathname = usePathname() const pathname = usePathname()
return ( return (
<nav className="absolute top-0 right-0 flex flex-row h-16 gap-0.5 p-4" data-tauri-drag-region> <nav
className="absolute top-0 right-0 flex flex-row h-16 gap-0.5 p-4"
data-tauri-drag-region
>
<button <button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={() => pathname !== "/prepare" ? router.push("/prepare") : router.back()} onClick={() =>
pathname !== "/prepare" ? router.push("/prepare") : router.back()
}
> >
<RocketOne size={16} /> <RocketOne size={16} />
</button> </button>
@@ -46,18 +52,21 @@ const Nav = () => {
{/* { platform() === "windows" && ( */} {/* { platform() === "windows" && ( */}
<> <>
<button <button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={minimize} onClick={minimize}
> >
<Minus size={16} /> <Minus size={16} />
</button> </button>
<button <button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={toggleMaximize} onClick={toggleMaximize}
> >
<Square size={16} /> <Square size={16} />
</button> </button>
<button <button
type="button"
className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition rounded hover:bg-zinc-200/80 active:scale-95"
onClick={close} onClick={close}
> >

View File

@@ -1,8 +1,15 @@
"use client" "use client"
import { ReactNode } from "react" import {
Home,
MonitorOne,
Movie,
Setting,
Terminal,
Toolkit,
} from "@icon-park/react"
import clsx from "clsx" import clsx from "clsx"
import { Home, MonitorOne, Movie, Setting, Terminal, Toolkit } from "@icon-park/react" import { usePathname, useRouter } from "next/navigation"
import { useRouter, usePathname } from "next/navigation" import type { ReactNode } from "react"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
import useAppStore from "@/store/app" import useAppStore from "@/store/app"
@@ -24,11 +31,12 @@ const SideButton = ({
return ( return (
<button <button
onClick={() => router.push(route || "/")} type="button"
onKeyUp={() => router.push(route || "/")}
className={clsx( className={clsx(
className, className,
"p-2.5 hover:bg-black/5 rounded-lg transition relative", "p-2.5 hover:bg-black/5 rounded-lg transition relative",
path.startsWith(route) && "bg-black/5" path.startsWith(route) && "bg-black/5",
)} )}
{...rest} {...rest}
> >
@@ -36,7 +44,7 @@ const SideButton = ({
<div <div
className={clsx( className={clsx(
path.startsWith(route) && "opacity-100", path.startsWith(route) && "opacity-100",
"transition-opacity duration-300 opacity-0 h-3.5 w-0.5 absolute left-0.5 bg-purple-500 rounded-full top-1/2 -translate-y-1/2" "transition-opacity duration-300 opacity-0 h-3.5 w-0.5 absolute left-0.5 bg-purple-500 rounded-full top-1/2 -translate-y-1/2",
)} )}
/> />
</button> </button>
@@ -49,10 +57,10 @@ const Avatar = () => {
return ( return (
<div <div
onClick={() => router.push("/users")} onKeyUp={() => router.push("/users")}
className={clsx( className={clsx(
"w-12 h-12 bg-gray-700 rounded-full shadow-2xl cursor-pointer transition active:scale-95 shadow-purple-800", "w-12 h-12 bg-gray-700 rounded-full shadow-2xl cursor-pointer transition active:scale-95 shadow-purple-800",
path.startsWith("/users") && "shadow-sm" path.startsWith("/users") && "shadow-sm",
)} )}
> >
<img src="favicon.ico" alt="avatar" draggable={false} /> <img src="favicon.ico" alt="avatar" draggable={false} />
@@ -66,7 +74,7 @@ const SideBar = () => {
return ( return (
<div <div
className={clsx( className={clsx(
"absolute left-0 flex flex-col h-full select-none w-20 py-7" "absolute left-0 flex flex-col h-full select-none w-20 py-7",
// platform() === "windows" ? "w-20" : "w-[4.25rem]" // platform() === "windows" ? "w-20" : "w-[4.25rem]"
)} )}
data-tauri-drag-region data-tauri-drag-region
@@ -99,9 +107,12 @@ const SideBar = () => {
</SideButton> </SideButton>
</section> </section>
<div className="mx-auto text-sm text-center text-zinc-500" data-tauri-drag-region> <div
className="mx-auto text-sm text-center text-zinc-500"
data-tauri-drag-region
>
<p></p> <p></p>
<p onClick={() => setVersion("x.y.z")}>{version}</p> <p onKeyUp={() => setVersion("x.y.z")}>{version}</p>
</div> </div>
</div> </div>
) )

View File

@@ -1,8 +1,17 @@
import { ReactNode } from "react"; import type { ReactNode } from "react"
interface ToolButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { interface ToolButtonProps
children?: ReactNode; extends React.ButtonHTMLAttributes<HTMLButtonElement> {
children?: ReactNode
} }
export const ToolButton = ({ children, ...rest }: ToolButtonProps) => { export const ToolButton = ({ children, ...rest }: ToolButtonProps) => {
return <button className="flex gap-0.5 active:scale-95 items-center min-w-7 justify-center px-2 py-1.5 bg-black/5 transition hover:bg-black/10 rounded-md text-sm leading-none" {...rest}>{children}</button>; return (
}; <button
type="button"
className="flex gap-0.5 active:scale-95 items-center min-w-7 justify-center px-2 py-1.5 bg-black/5 transition hover:bg-black/10 rounded-md text-sm leading-none"
{...rest}
>
{children}
</button>
)
}

View File

@@ -1,6 +1,6 @@
import { create } from 'zustand' import { tauriStore } from "@/utils/persist"
import { tauriStore } from '@/utils/persist' import { create } from "zustand"
import { createJSONStorage, persist } from 'zustand/middleware' import { createJSONStorage, persist } from "zustand/middleware"
interface AppState { interface AppState {
version: string version: string
@@ -23,23 +23,25 @@ const { /* store, */ storage } = tauriStore(STORE_NAME)
const useAppStore = create<AppState & AppAction>()( const useAppStore = create<AppState & AppAction>()(
persist( persist(
(set/* , get */) => ({ (set /* , get */) => ({
version: "0.0.1", version: "0.0.1",
hasUpdate: false, hasUpdate: false,
inited: false, inited: false,
notice: "Man! What can I say?", notice: "Man! What can I say?",
useMirror: true, useMirror: true,
setVersion: (version: string) => set(() => ({ version: version })), setVersion: (version: string) => set(() => ({ version: version })),
setHasUpdate: (hasUpdate: boolean) => set(() => ({ hasUpdate: hasUpdate })), setHasUpdate: (hasUpdate: boolean) =>
set(() => ({ hasUpdate: hasUpdate })),
setInited: (inited: boolean) => set(() => ({ inited: inited })), setInited: (inited: boolean) => set(() => ({ inited: inited })),
setNotice: (notice: string) => set(() => ({ notice: notice })), setNotice: (notice: string) => set(() => ({ notice: notice })),
setUseMirror: (useMirror: boolean) => set(() => ({ useMirror: useMirror })) setUseMirror: (useMirror: boolean) =>
set(() => ({ useMirror: useMirror })),
}), }),
{ {
name: STORE_NAME, // name of item in the storage (must be unique) name: STORE_NAME, // name of item in the storage (must be unique)
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
}, },
) ),
) )
export default useAppStore export default useAppStore

View File

@@ -1,7 +1,7 @@
import { SteamUser } from '@/types/steam' import type { SteamUser } from "@/types/steam"
import { tauriStore } from '@/utils/persist' import { tauriStore } from "@/utils/persist"
import { create } from 'zustand' import { create } from "zustand"
import { persist, createJSONStorage } from 'zustand/middleware' import { createJSONStorage, persist } from "zustand/middleware"
const mock_user: SteamUser = { const mock_user: SteamUser = {
steamID64: "76561198052315353", steamID64: "76561198052315353",
@@ -14,20 +14,20 @@ const mock_user: SteamUser = {
} }
interface SteamState { interface SteamState {
dir: string, dir: string
csDir: string, csDir: string
users: SteamUser[], users: SteamUser[]
isDirValid: boolean, isDirValid: boolean
isCsDirValid: boolean, isCsDirValid: boolean
} }
interface SteamAction { interface SteamAction {
setDir: (dir: string) => void, setDir: (dir: string) => void
setCsDir: (dir: string) => void, setCsDir: (dir: string) => void
setUsers: (users: SteamUser[]) => void, setUsers: (users: SteamUser[]) => void
setIsDirValid: (valid: boolean) => void, setIsDirValid: (valid: boolean) => void
setIsCsDirValid: (valid: boolean) => void, setIsCsDirValid: (valid: boolean) => void
currentUser: () => SteamUser, currentUser: () => SteamUser
} }
const STORE_NAME = "steam" const STORE_NAME = "steam"
@@ -53,8 +53,8 @@ const useSteamStore = create<SteamState & SteamAction>()(
{ {
name: STORE_NAME, // name of item in the storage (must be unique) name: STORE_NAME, // name of item in the storage (must be unique)
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
} },
) ),
) )
export default useSteamStore export default useSteamStore

View File

@@ -1,6 +1,6 @@
import { tauriStore } from '@/utils/persist' import { tauriStore } from "@/utils/persist"
import { create } from 'zustand' import { create } from "zustand"
import { createJSONStorage, persist } from 'zustand/middleware' import { createJSONStorage, persist } from "zustand/middleware"
interface ToolState { interface ToolState {
launchOptions: string[] launchOptions: string[]
@@ -20,20 +20,32 @@ const { /* store, */ storage } = tauriStore(STORE_NAME)
const useToolStore = create<ToolState & ToolAction>()( const useToolStore = create<ToolState & ToolAction>()(
persist( persist(
(set/* , get */) => ({ (set /* , get */) => ({
launchOptions: ["-high -refresh 120 -novid -nojoy -tickrate 128 +cl_cmdrate 128 +cl_updaterate 128 +exec auto.cfg +test", "", ""], launchOptions: [
"-high -refresh 120 -novid -nojoy -tickrate 128 +cl_cmdrate 128 +cl_updaterate 128 +exec auto.cfg +test",
"",
"",
],
launchIndex: 0, launchIndex: 0,
powerPlan: 0, powerPlan: 0,
setLaunchOption: (option: string, index: number) => set((state) => ({ launchOptions: [...state.launchOptions.slice(0, index), option, ...state.launchOptions.slice(index + 1)] })), setLaunchOption: (option: string, index: number) =>
setLaunchOptions: (options: string[]) => set(() => ({ launchOptions: options })), set((state) => ({
launchOptions: [
...state.launchOptions.slice(0, index),
option,
...state.launchOptions.slice(index + 1),
],
})),
setLaunchOptions: (options: string[]) =>
set(() => ({ launchOptions: options })),
setLaunchIndex: (index: number) => set(() => ({ launchIndex: index })), setLaunchIndex: (index: number) => set(() => ({ launchIndex: index })),
setPowerPlan: (index: number) => set(() => ({ powerPlan: index })) setPowerPlan: (index: number) => set(() => ({ powerPlan: index })),
}), }),
{ {
name: STORE_NAME, // name of item in the storage (must be unique) name: STORE_NAME, // name of item in the storage (must be unique)
storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used storage: createJSONStorage(() => storage), // (optional) by default the 'localStorage' is used
} },
) ),
) )
export default useToolStore export default useToolStore

View File

@@ -1,4 +1,4 @@
import { AdvancedListItem } from "@/types/common" import type { AdvancedListItem } from "@/types/common"
export interface File { export interface File {
dir: string dir: string

View File

@@ -1,4 +1,4 @@
import { Owner } from "@/types/cfg" import type { Owner } from "@/types/cfg"
export interface XBase { export interface XBase {
name: string name: string

View File

@@ -1,4 +1,4 @@
import { AdvancedListItem } from "@/types/common" import type { AdvancedListItem } from "@/types/common"
export interface SteamUser extends AdvancedListItem { export interface SteamUser extends AdvancedListItem {
steamID64: string steamID64: string

View File

@@ -1,20 +1,18 @@
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { StateStorage } from 'zustand/middleware'
import { Store } from "@tauri-apps/plugin-store" import { Store } from "@tauri-apps/plugin-store"
import { throttle } from 'throttle-debounce'; import { throttle } from "throttle-debounce"
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import type { StateStorage } from "zustand/middleware"
// import { useThrottleFn } from '@reactuses/core'; // import { useThrottleFn } from '@reactuses/core';
// 节流设置 // 节流设置
export const THROTTLE_TIME = 300 export const THROTTLE_TIME = 300
export const THROTTLE_TIME_STORE = 5000 export const THROTTLE_TIME_STORE = 5000
export const THROTTLE_LEADING = true export const THROTTLE_LEADING = true
export const THROTTLE_TRAILING = true export const THROTTLE_TRAILING = true
// 自定义Store覆盖get, set等方法以适应tauri+zustand // 自定义Store覆盖get, set等方法以适应tauri+zustand
export function tauriStore(name: string) { export async function tauriStore(name: string) {
const store = new Store(`${name || "store"}.settings.json`) const store = await Store.load(`${name || "store"}.settings.json`)
// 自动保存 // 自动保存
const autoSave = throttle( const autoSave = throttle(
@@ -24,8 +22,8 @@ export function tauriStore(name: string) {
}, },
{ {
noTrailing: !THROTTLE_TRAILING, noTrailing: !THROTTLE_TRAILING,
noLeading: !THROTTLE_LEADING noLeading: !THROTTLE_LEADING,
} },
) )
const doSet = throttle( const doSet = throttle(
@@ -35,8 +33,8 @@ export function tauriStore(name: string) {
}, },
{ {
noTrailing: !THROTTLE_TRAILING, noTrailing: !THROTTLE_TRAILING,
noLeading: !THROTTLE_LEADING noLeading: !THROTTLE_LEADING,
} },
) )
const set = (key: string, value: unknown) => { const set = (key: string, value: unknown) => {