[chore] remove unusable files

This commit is contained in:
Purp1e
2025-03-12 22:20:06 +08:00
parent a78b63259a
commit 71858e5fec
21 changed files with 142 additions and 326 deletions

View File

@@ -1,28 +0,0 @@
version: 2
updates:
# Enable version updates for Node.js dependencies
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
allow:
- dependency-type: "all"
groups:
all:
patterns:
- "*"
ignore:
- dependency-name: "eslint"
versions: ">= 9"
# Enable version updates for rust
- package-ecosystem: "cargo"
directory: "/src-tauri"
schedule:
interval: "weekly"
allow:
- dependency-type: "all"
groups:
all:
patterns:
- "*"

View File

@@ -1,34 +0,0 @@
# Automatically squashes and merges Dependabot dependency upgrades if tests pass
name: Dependabot Auto-merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Fetch Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.3.3
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve Dependabot PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Auto-merge (squash) Dependabot PR
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,46 +0,0 @@
# Installs Node.js dependencies and pnpm, and checks formatting + linting
name: Lint Node.js
on:
push:
branches:
- main
pull_request:
paths-ignore:
- "src-tauri/**"
- "README.md"
jobs:
build:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Disable git core.autocrlf on Windows
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false
- name: Checkout repository code
uses: actions/checkout@v4
- name: Set up pnpm package manager
uses: pnpm/action-setup@v4
with:
version: latest
- name: Set up Node.js v22
uses: actions/setup-node@v3
with:
node-version: 22
cache: "pnpm"
- name: Install dependencies from lockfile
run: pnpm install --frozen-lockfile
- name: Run lint step
run: pnpm lint

View File

@@ -1,55 +0,0 @@
# Installs Rust and checks formatting + linting
name: Lint Rust
on:
push:
branches:
- main
pull_request:
paths-ignore:
- "src/**"
- "package.json"
- "package-lock.json"
- "yarn.lock"
- "pnpm-lock.yaml"
- "README.md"
jobs:
build:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Disable git core.autocrlf on Windows
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false
- name: Checkout repository code
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Install Linux dependencies
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt install libdbus-1-dev libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
- name: Create empty 'out' directory
run: mkdir out
- name: Run rustfmt check
run: cargo fmt --all -- --check
working-directory: src-tauri
- name: Run clippy check and deny warnings
run: cargo clippy --all-targets --all-features -- -D warnings
working-directory: src-tauri

View File

@@ -1,8 +1,8 @@
{ {
"$schema": "../node_modules/@tauri-apps/cli/schema.json", "$schema": "../node_modules/@tauri-apps/cli/schema.json",
"build": { "build": {
"beforeBuildCommand": "pnpm next-build", "beforeBuildCommand": "bun next-build",
"beforeDevCommand": "pnpm next-start", "beforeDevCommand": "bun next-start",
"frontendDist": "../out", "frontendDist": "../out",
"devUrl": "http://localhost:3000" "devUrl": "http://localhost:3000"
}, },

View File

@@ -1,10 +1,9 @@
"use client" "use client"
import { appStore } from "@/store/app" import { appStore } from "@/store/app"
import { useEffect } from "react"
import { useSnapshot } from "valtio" import { useSnapshot } from "valtio"
export default function Page() { export default function Page() {
appStore.start() void appStore.start()
const app = useSnapshot(appStore.state) const app = useSnapshot(appStore.state)
return ( return (

View File

@@ -7,6 +7,7 @@ import {
CardTool, CardTool,
} from "@/components/window/Card" } from "@/components/window/Card"
import { ToolButton } from "@/components/window/ToolButton" import { ToolButton } from "@/components/window/ToolButton"
import { cn } from "@heroui/react"
import { import {
AssemblyLine, AssemblyLine,
HardDisk, HardDisk,
@@ -14,7 +15,6 @@ import {
UploadOne, UploadOne,
Videocamera, Videocamera,
} from "@icon-park/react" } from "@icon-park/react"
import { cn } from "@heroui/react"
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"

View File

@@ -1,10 +1,9 @@
"use client" "use client"
import { currentUser, steamStore } from "@/store/steam" import { currentUser, steamStore } from "@/store/steam"
import { useEffect } from "react"
import { useSnapshot } from "valtio" import { useSnapshot } from "valtio"
export default function Page() { export default function Page() {
steamStore.start() void steamStore.start()
const steam = useSnapshot(steamStore.state) const steam = useSnapshot(steamStore.state)
return ( return (

View File

@@ -1,8 +1,8 @@
"use client" "use client"
import React from "react"
import { useRouter } from "next/navigation"
import { open } from "@tauri-apps/plugin-dialog" import { open } from "@tauri-apps/plugin-dialog"
import { useRouter } from "next/navigation"
import React from "react"
const Home = () => { const Home = () => {
const router = useRouter() const router = useRouter()
@@ -21,7 +21,9 @@ const Home = () => {
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>
<button <button
type="button" type="button"
onClick={() => router.push("/home")} onClick={() => router.push("/home")}
@@ -29,7 +31,11 @@ const Home = () => {
> >
</button> </button>
<button type="button" onClick={openFile} className="px-4 py-1 text-white bg-blue-500 rounded"> <button
type="button"
onClick={openFile}
className="px-4 py-1 text-white bg-blue-500 rounded"
>
</button> </button>
<p className="text-center bg-zinc-50">{file}</p> <p className="text-center bg-zinc-50">{file}</p>

View File

@@ -1,10 +1,9 @@
"use client" "use client"
import { steamStore, setDir, setCsDir, currentUser } from "@/store/steam" import { currentUser, setCsDir, setDir, steamStore } from "@/store/steam"
import { useEffect } from "react"
import { useSnapshot } from "valtio" import { useSnapshot } from "valtio"
export default function Page() { export default function Page() {
steamStore.start() void steamStore.start()
const steam = useSnapshot(steamStore.state) const steam = useSnapshot(steamStore.state)
return ( return (
<div <div

View File

@@ -1,12 +1,11 @@
import { toolStore, setLaunchOption, setLaunchIndex } from "@/store/tool" import { setLaunchIndex, setLaunchOption, toolStore } from "@/store/tool"
import { Plus, SettingConfig, Switch } from "@icon-park/react" import { Plus, SettingConfig, Switch } from "@icon-park/react"
import { useSnapshot } from "valtio"
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card" import { Card, CardBody, CardHeader, CardIcon, CardTool } from "../window/Card"
import { ToolButton } from "../window/ToolButton" import { ToolButton } from "../window/ToolButton"
import { useSnapshot } from "valtio"
import { use, useEffect, useState } from "react"
const LaunchOption = () => { const LaunchOption = () => {
toolStore.start() void toolStore.start()
const { launchOptions, launchIndex } = useSnapshot(toolStore.state) const { launchOptions, launchIndex } = useSnapshot(toolStore.state)
return ( return (
@@ -33,7 +32,9 @@ const LaunchOption = () => {
<textarea <textarea
placeholder="请输入启动选项" placeholder="请输入启动选项"
value={launchOptions[launchIndex] || ""} value={launchOptions[launchIndex] || ""}
onChange={(e) => launchIndex !== -1 && setLaunchOption(e.target.value, launchIndex)} onChange={(e) =>
launchIndex !== -1 && setLaunchOption(e.target.value, launchIndex)
}
className="w-full font-mono text-base bg-transparent outline-none resize-none min-h-20" className="w-full font-mono text-base bg-transparent outline-none resize-none min-h-20"
/> />
</CardBody> </CardBody>

View File

@@ -1,12 +1,17 @@
import { Card, CardBody, CardHeader, CardIcon, CardTool } from "@/components/window/Card" import {
Card,
CardBody,
CardHeader,
CardIcon,
CardTool,
} from "@/components/window/Card"
import { appStore } from "@/store/app" import { appStore } from "@/store/app"
import { Refresh, VolumeNotice } from "@icon-park/react" import { Refresh, VolumeNotice } from "@icon-park/react"
import { ToolButton } from "../window/ToolButton"
import { useSnapshot } from "valtio" import { useSnapshot } from "valtio"
import { useEffect } from "react" import { ToolButton } from "../window/ToolButton"
const Notice = () => { const Notice = () => {
appStore.start() void appStore.start()
const app = useSnapshot(appStore.state) const app = useSnapshot(appStore.state)
return ( return (
@@ -22,7 +27,9 @@ const Notice = () => {
</ToolButton> </ToolButton>
</CardTool> </CardTool>
</CardHeader> </CardHeader>
<CardBody>{app.notice || "不会真的有人要更新CSGO工具箱吧不会吧不会吧 xswl"}</CardBody> <CardBody>
{app.notice || "不会真的有人要更新CSGO工具箱吧不会吧不会吧 xswl"}
</CardBody>
</Card> </Card>
) )
} }

View File

@@ -2,10 +2,18 @@
import { resetAppStore } from "@/store/app" import { resetAppStore } from "@/store/app"
import { resetToolStore } from "@/store/tool" import { resetToolStore } from "@/store/tool"
import { addToast } from "@heroui/react" import { addToast } from "@heroui/react"
import { Close, Minus, Moon, Refresh, RefreshOne, RocketOne, Square, Sun, SunOne } from "@icon-park/react" import {
import { useTheme } from "next-themes" Close,
Minus,
Moon,
Refresh,
RocketOne,
Square,
SunOne,
} from "@icon-park/react"
import { getCurrentWindow } from "@tauri-apps/api/window" import { getCurrentWindow } from "@tauri-apps/api/window"
import { /* relaunch, */ exit, relaunch } from "@tauri-apps/plugin-process" import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { useTheme } from "next-themes"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
import { usePathname, useRouter } from "next/navigation" import { usePathname, useRouter } from "next/navigation"
@@ -41,7 +49,10 @@ 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" type="button"
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
@@ -50,7 +61,7 @@ const Nav = () => {
resetToolStore() resetToolStore()
addToast({ addToast({
title: "重置成功", title: "重置成功",
color: 'success' color: "success",
// description: "已重置所有设置", // description: "已重置所有设置",
}) })
}} }}
@@ -61,7 +72,9 @@ const Nav = () => {
<button <button
type="button" type="button"
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition duration-150 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>
@@ -69,7 +82,9 @@ const Nav = () => {
<button <button
type="button" type="button"
className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95" className="px-2 py-0 transition duration-150 rounded hover:bg-zinc-200/80 active:scale-95"
onClick={() => (theme === "light" ? setTheme("dark") : setTheme("light"))} onClick={() =>
theme === "light" ? setTheme("dark") : setTheme("light")
}
> >
{theme === "light" ? <SunOne size={16} /> : <Moon size={16} />} {theme === "light" ? <SunOne size={16} /> : <Moon size={16} />}
</button> </button>

View File

@@ -1,8 +1,15 @@
"use client" "use client"
import { Home, MonitorOne, Movie, Setting, Terminal, Toolkit } from "@icon-park/react"
import { Button, cn } from "@heroui/react" import { Button, cn } from "@heroui/react"
import {
Home,
MonitorOne,
Movie,
Setting,
Terminal,
Toolkit,
} from "@icon-park/react"
import { usePathname, useRouter } from "next/navigation" import { usePathname, useRouter } from "next/navigation"
import { useEffect, type ReactNode } from "react" import type { ReactNode } from "react"
// import { platform } from "@tauri-apps/plugin-os" // import { platform } from "@tauri-apps/plugin-os"
import { appStore, setVersion } from "@/store/app" import { appStore, setVersion } from "@/store/app"
@@ -30,7 +37,7 @@ const SideButton = ({
className={cn( className={cn(
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}
> >
@@ -38,7 +45,7 @@ const SideButton = ({
<div <div
className={cn( className={cn(
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>
@@ -54,7 +61,7 @@ const Avatar = () => {
onKeyUp={() => router.push("/users")} onKeyUp={() => router.push("/users")}
className={cn( className={cn(
"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} />
@@ -63,13 +70,13 @@ const Avatar = () => {
} }
const SideBar = () => { const SideBar = () => {
appStore.start() void appStore.start()
const { version } = useSnapshot(appStore.state) const { version } = useSnapshot(appStore.state)
return ( return (
<div <div
className={cn( className={cn(
"absolute left-0 flex flex-col h-full select-none w-20 pt-7 pb-5" "absolute left-0 flex flex-col h-full select-none w-20 pt-7 pb-5",
// platform() === "windows" ? "w-20" : "w-[4.25rem]" // platform() === "windows" ? "w-20" : "w-[4.25rem]"
)} )}
data-tauri-drag-region data-tauri-drag-region
@@ -102,7 +109,10 @@ 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>
<Button <Button
variant="light" variant="light"

View File

@@ -1,5 +1,5 @@
import { store } from 'tauri-plugin-valtio'; import { store } from "tauri-plugin-valtio"
import { DEFAULT_STORE_CONFIG } from '.'; import { DEFAULT_STORE_CONFIG } from "."
// Usage: // Usage:
// import {appStore} from "@/store/app" // import {appStore} from "@/store/app"
@@ -13,16 +13,26 @@ const defaultValue = {
hasUpdate: false, hasUpdate: false,
inited: false, inited: false,
notice: "", notice: "",
useMirror: true useMirror: true,
} }
export const appStore = store('app', { ...defaultValue }, DEFAULT_STORE_CONFIG); export const appStore = store("app", { ...defaultValue }, DEFAULT_STORE_CONFIG)
export const setVersion = (version: string) => { appStore.state.version = version } export const setVersion = (version: string) => {
export const setHasUpdate = (hasUpdate: boolean) => { appStore.state.hasUpdate = hasUpdate } appStore.state.version = version
export const setInited = (inited: boolean) => { appStore.state.inited = inited } }
export const setNotice = (notice: string) => { appStore.state.notice = notice } export const setHasUpdate = (hasUpdate: boolean) => {
export const setUseMirror = (useMirror: boolean) => { appStore.state.useMirror = useMirror } appStore.state.hasUpdate = hasUpdate
}
export const setInited = (inited: boolean) => {
appStore.state.inited = inited
}
export const setNotice = (notice: string) => {
appStore.state.notice = notice
}
export const setUseMirror = (useMirror: boolean) => {
appStore.state.useMirror = useMirror
}
export const resetAppStore = () => { export const resetAppStore = () => {
setVersion(defaultValue.version) setVersion(defaultValue.version)

View File

@@ -1,6 +1,6 @@
export const DEFAULT_STORE_CONFIG = { export const DEFAULT_STORE_CONFIG = {
saveOnChange: true, saveOnChange: true,
saveOnExit: true, saveOnExit: true,
saveStrategy: 'debounce' as const, saveStrategy: "debounce" as const,
saveInterval: 3000, saveInterval: 3000,
}; }

View File

@@ -1,28 +1,44 @@
import type { SteamUser } from "@/types/steam" import type { SteamUser } from "@/types/steam"
import { store } from 'tauri-plugin-valtio'; import { store } from "tauri-plugin-valtio"
import { DEFAULT_STORE_CONFIG } from '.'; import { DEFAULT_STORE_CONFIG } from "."
const defaultValue = { const defaultValue = {
dir: "C:\\Program Files (x86)\\Steam", dir: "C:\\Program Files (x86)\\Steam",
csDir: "", csDir: "",
users: [{ users: [
{
steamID64: "76561198052315353", steamID64: "76561198052315353",
steamID32: "STEAM_0:0:46157676", steamID32: "STEAM_0:0:46157676",
accountName: "wrr", accountName: "wrr",
personaName: "wrr", personaName: "wrr",
recent: 0, recent: 0,
avatar: "" avatar: "",
}] as SteamUser[], },
] as SteamUser[],
isDirValid: false, isDirValid: false,
isCsDirValid: false isCsDirValid: false,
} }
export const steamStore = store('steam', {...defaultValue}, DEFAULT_STORE_CONFIG); export const steamStore = store(
"steam",
{ ...defaultValue },
DEFAULT_STORE_CONFIG,
)
export const setDir = (dir: string) => { steamStore.state.dir = dir } export const setDir = (dir: string) => {
export const setCsDir = (dir: string) => { steamStore.state.csDir = dir } steamStore.state.dir = dir
export const setUsers = (users: SteamUser[]) => { steamStore.state.users = users } }
export const setIsDirValid = (valid: boolean) => { steamStore.state.isDirValid = valid } export const setCsDir = (dir: string) => {
export const setIsCsDirValid = (valid: boolean) => { steamStore.state.isCsDirValid = valid } steamStore.state.csDir = dir
}
export const setUsers = (users: SteamUser[]) => {
steamStore.state.users = users
}
export const setIsDirValid = (valid: boolean) => {
steamStore.state.isDirValid = valid
}
export const setIsCsDirValid = (valid: boolean) => {
steamStore.state.isCsDirValid = valid
}
export const currentUser = () => { export const currentUser = () => {
return steamStore.state.users[0] || defaultValue.users[0] return steamStore.state.users[0] || defaultValue.users[0]

View File

@@ -1,23 +1,27 @@
import { store } from 'tauri-plugin-valtio'; import { store } from "tauri-plugin-valtio"
import { DEFAULT_STORE_CONFIG } from '.'; import { DEFAULT_STORE_CONFIG } from "."
const defaultValue = { const defaultValue = {
launchOptions: [ launchOptions: [
"-novid -high -freq 144 -fullscreen", "-novid -high -freq 144 -fullscreen",
"-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder",
"-novid -high -freq 144 -fullscreen -allow_third_party_software" "-novid -high -freq 144 -fullscreen -allow_third_party_software",
] as string[], ] as string[],
launchIndex: 0, launchIndex: 0,
powerPlan: 0 powerPlan: 0,
} }
export const toolStore = store('tool', { ...defaultValue }, DEFAULT_STORE_CONFIG); export const toolStore = store(
"tool",
{ ...defaultValue },
DEFAULT_STORE_CONFIG,
)
export const setLaunchOption = (option: string, index: number) => { export const setLaunchOption = (option: string, index: number) => {
toolStore.state.launchOptions = [ toolStore.state.launchOptions = [
...toolStore.state.launchOptions.slice(0, index), ...toolStore.state.launchOptions.slice(0, index),
option, option,
...toolStore.state.launchOptions.slice(index + 1) ...toolStore.state.launchOptions.slice(index + 1),
] ]
} }

View File

@@ -1,51 +0,0 @@
import { Store } from "@tauri-apps/plugin-store"
import { throttle } from "throttle-debounce"
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import type { StateStorage } from "zustand/middleware"
// import { useThrottleFn } from '@reactuses/core';
// 节流设置
export const THROTTLE_TIME = 300
export const THROTTLE_TIME_STORE = 2000
export const THROTTLE_LEADING = true
export const THROTTLE_TRAILING = true
// 自定义Store覆盖get, set等方法以适应tauri+zustand
export async function tauriStore(name: string) {
const store = await Store.load(`${name || "store"}.settings.json`, {
autoSave: THROTTLE_TIME_STORE,
})
const doSet = throttle(
THROTTLE_TIME,
async (key: string, value: unknown) => await store.set(key, value),
{
noTrailing: !THROTTLE_TRAILING,
noLeading: !THROTTLE_LEADING,
},
)
const set = (key: string, value: unknown) => {
doSet(key, value)
}
const get = async (key: string) => await store.get(key)
// 自定义存储对象
const storage: StateStorage = {
setItem: async (name: string, value: string): Promise<void> => {
await store.set(name, value)
// console.log(name, 'has been set to', value)
},
getItem: async (name: string): Promise<string | null> => {
// console.log(name, 'has been get')
return (await store.get(name)) || null
},
removeItem: async (name: string): Promise<void> => {
// console.log(name, 'has been deleted')
await store.delete(name)
},
}
return { store, get, set, storage }
}

View File

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