[fix] store persistence and switch dir to 'cstb'

This commit is contained in:
Purp1e
2025-03-20 01:46:54 +08:00
parent b90a08d0fe
commit c28cd23b5c
14 changed files with 136 additions and 81 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -32,6 +32,7 @@
"@tauri-apps/plugin-process": "2.0.0",
"@tauri-apps/plugin-shell": "2.0.1",
"@tauri-apps/plugin-store": "^2.2.0",
"@tauri-store/valtio": "^2.0.0",
"@types/throttle-debounce": "^5.0.2",
"framer-motion": "^12.5.0",
"jotai": "^2.12.2",

61
src-tauri/Cargo.lock generated
View File

@@ -463,6 +463,31 @@ dependencies = [
"piper",
]
[[package]]
name = "bon"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "625e90403736670c971aad50573b7db42e131970d60a14f215b61fdf24e0aa84"
dependencies = [
"bon-macros",
"rustversion",
]
[[package]]
name = "bon-macros"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa915c54d505ca9b9b7ac056df7797508c3b817e51609d0ed19949dd0925b872"
dependencies = [
"darling",
"ident_case",
"prettyplease",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.87",
]
[[package]]
name = "brotli"
version = "7.0.0"
@@ -3373,6 +3398,16 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "prettyplease"
version = "0.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033"
dependencies = [
"proc-macro2",
"syn 2.0.87",
]
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
@@ -3893,6 +3928,12 @@ dependencies = [
"untrusted",
]
[[package]]
name = "rustversion"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "ryu"
version = "1.0.18"
@@ -4876,9 +4917,9 @@ dependencies = [
[[package]]
name = "tauri-plugin-valtio"
version = "1.1.1"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b04f9e001956ca4d4ab9cb57cb4f0d8fb0949ba1a03a13591d2215653b988691"
checksum = "920125988ca715c48bf74091e2fb4da951fac392f445b1d96df67a3a72c28877"
dependencies = [
"serde",
"tauri",
@@ -4935,13 +4976,14 @@ dependencies = [
[[package]]
name = "tauri-store"
version = "0.8.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4e7c0776d9f8b54fd4788f4e471ce83b4c6cf62079799830a3735582a51fc4"
checksum = "d82e807a25b2fa63ef204d61c44092c4b6262bb534c766f13e1b2f68cd07e568"
dependencies = [
"dashmap",
"futures",
"itertools",
"semver",
"serde",
"serde_json",
"tauri",
@@ -4954,9 +4996,9 @@ dependencies = [
[[package]]
name = "tauri-store-macros"
version = "0.8.1"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fabed02238bc887f75887b315c6a14d9571ab463c1a188cc27ec2f7e917b06c3"
checksum = "dd0a53dbd50f92ca25e352530aa80026a6b221fa04453df0c2bf2b198d3c71fa"
dependencies = [
"proc-macro2",
"quote",
@@ -4965,11 +5007,14 @@ dependencies = [
[[package]]
name = "tauri-store-utils"
version = "0.2.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b983a259b22d622ce74b957140efa161bd75c6bfd47b7bf621c98dd05b1a2474"
checksum = "48256653b57a054a65c5d650c998cabd8956522ade275641095c9a49e7506b9d"
dependencies = [
"bon",
"futures",
"serde",
"serde_json",
"tauri",
"thiserror 2.0.3",
"tokio",

View File

@@ -9,6 +9,12 @@ default-run = "CS工具箱"
edition = "2021"
rust-version = "1.66"
[profile.release]
panic = "abort" # Strip expensive panic clean-up logic
codegen-units = 1 # Compile crates one after another so the compiler can optimize better
lto = true # Enables link to optimizations
opt-level = "s" # Optimize for binary size
strip = true # Remove debug symbols
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
@@ -29,7 +35,7 @@ tauri-plugin-clipboard-manager = "2.2.2"
tauri-plugin-shell = "2.2.0"
tauri-plugin-http = "2.4.2"
tauri-plugin-notification = "2.2.2"
tauri-plugin-valtio = "1.1.1"
tauri-plugin-valtio = "2.0.0"
tauri-plugin-store = "2.2.0"
tauri-plugin-system-info = "2.0.9"
tauri-plugin-theme = "2.1.3"

File diff suppressed because one or more lines are too long

View File

@@ -6014,6 +6014,11 @@
"type": "string",
"const": "valtio:allow-get-save-strategy"
},
{
"description": "Enables the get_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-get-store-collection-path"
},
{
"description": "Enables the get_store_ids command without any pre-configured scope.",
"type": "string",
@@ -6029,11 +6034,6 @@
"type": "string",
"const": "valtio:allow-get-store-state"
},
{
"description": "Enables the get_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-get-valtio-path"
},
{
"description": "Enables the load command without any pre-configured scope.",
"type": "string",
@@ -6084,16 +6084,16 @@
"type": "string",
"const": "valtio:allow-set-save-strategy"
},
{
"description": "Enables the set_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-store-collection-path"
},
{
"description": "Enables the set_store_options command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-store-options"
},
{
"description": "Enables the set_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-valtio-path"
},
{
"description": "Enables the unload command without any pre-configured scope.",
"type": "string",
@@ -6114,6 +6114,11 @@
"type": "string",
"const": "valtio:deny-get-save-strategy"
},
{
"description": "Denies the get_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-get-store-collection-path"
},
{
"description": "Denies the get_store_ids command without any pre-configured scope.",
"type": "string",
@@ -6129,11 +6134,6 @@
"type": "string",
"const": "valtio:deny-get-store-state"
},
{
"description": "Denies the get_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-get-valtio-path"
},
{
"description": "Denies the load command without any pre-configured scope.",
"type": "string",
@@ -6184,16 +6184,16 @@
"type": "string",
"const": "valtio:deny-set-save-strategy"
},
{
"description": "Denies the set_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-store-collection-path"
},
{
"description": "Denies the set_store_options command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-store-options"
},
{
"description": "Denies the set_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-valtio-path"
},
{
"description": "Denies the unload command without any pre-configured scope.",
"type": "string",

View File

@@ -6014,6 +6014,11 @@
"type": "string",
"const": "valtio:allow-get-save-strategy"
},
{
"description": "Enables the get_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-get-store-collection-path"
},
{
"description": "Enables the get_store_ids command without any pre-configured scope.",
"type": "string",
@@ -6029,11 +6034,6 @@
"type": "string",
"const": "valtio:allow-get-store-state"
},
{
"description": "Enables the get_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-get-valtio-path"
},
{
"description": "Enables the load command without any pre-configured scope.",
"type": "string",
@@ -6084,16 +6084,16 @@
"type": "string",
"const": "valtio:allow-set-save-strategy"
},
{
"description": "Enables the set_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-store-collection-path"
},
{
"description": "Enables the set_store_options command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-store-options"
},
{
"description": "Enables the set_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:allow-set-valtio-path"
},
{
"description": "Enables the unload command without any pre-configured scope.",
"type": "string",
@@ -6114,6 +6114,11 @@
"type": "string",
"const": "valtio:deny-get-save-strategy"
},
{
"description": "Denies the get_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-get-store-collection-path"
},
{
"description": "Denies the get_store_ids command without any pre-configured scope.",
"type": "string",
@@ -6129,11 +6134,6 @@
"type": "string",
"const": "valtio:deny-get-store-state"
},
{
"description": "Denies the get_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-get-valtio-path"
},
{
"description": "Denies the load command without any pre-configured scope.",
"type": "string",
@@ -6184,16 +6184,16 @@
"type": "string",
"const": "valtio:deny-set-save-strategy"
},
{
"description": "Denies the set_store_collection_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-store-collection-path"
},
{
"description": "Denies the set_store_options command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-store-options"
},
{
"description": "Denies the set_valtio_path command without any pre-configured scope.",
"type": "string",
"const": "valtio:deny-set-valtio-path"
},
{
"description": "Denies the unload command without any pre-configured scope.",
"type": "string",

View File

@@ -1,12 +1,14 @@
// "use client"
"use client"
import { steamStore } from "@/store/steam"
import { useEffect } from "react"
import "./globals.css"
import Providers from "./providers"
import { init } from "@/store"
export default function RootLayout({ children }: { children: React.ReactNode }) {
useEffect(() => {
void init()
})
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body>

View File

@@ -8,7 +8,7 @@ import { type Theme, getCurrentWindow } from "@tauri-apps/api/window"
import { /* relaunch, */ exit } from "@tauri-apps/plugin-process"
import { useTheme } from "next-themes"
import { usePathname, useRouter } from "next/navigation"
import { saveAllNow } from "tauri-plugin-valtio"
import { saveAllNow } from "@tauri-store/valtio"
const Nav = () => {
const app = useAppStore()

View File

@@ -1,6 +1,6 @@
import { store } from "tauri-plugin-valtio"
import { store } from "@tauri-store/valtio"
import { useSnapshot } from "valtio"
import { DEFAULT_STORE_CONFIG } from "."
import { DEFAULT_STORE_CONFIG } from "./config"
const defaultValue = {
version: "0.0.1",

6
src/store/config.ts Normal file
View File

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

View File

@@ -1,20 +1,15 @@
// @ts-ignore
// import path from "path"
// import { appConfigDir } from "@tauri-apps/api/path"
// import { setValtioPath } from "tauri-plugin-valtio"
import { appConfigDir } from "@tauri-apps/api/path"
import { setStoreCollectionPath } from "@tauri-store/valtio"
import { appStore } from "./app"
import { steamStore } from "./steam"
import { toolStore } from "./tool"
import path from "path"
// async function init() {
// const configDir = await appConfigDir()
// const distDir = path.join(configDir, "cstb")
// await setValtioPath(distDir)
// // console.log('init valtio', distDir);
// }
// void init()
export const DEFAULT_STORE_CONFIG = {
saveOnChange: true,
saveOnExit: true,
saveStrategy: "debounce" as const,
saveInterval: 2000,
export async function init() {
await appStore.start()
await toolStore.start()
await steamStore.start()
const appConfigDirPath = await appConfigDir()
console.log(appConfigDirPath)
await setStoreCollectionPath(path.resolve(appConfigDirPath, "cstb"))
}

View File

@@ -1,6 +1,6 @@
import type { SteamUser } from "@/types/steam"
import { store } from "tauri-plugin-valtio"
import { DEFAULT_STORE_CONFIG } from "."
import { store } from "@tauri-store/valtio"
import { DEFAULT_STORE_CONFIG } from "./config"
import { useSnapshot } from "valtio"
const defaultValue = {

View File

@@ -1,6 +1,6 @@
import { store } from "tauri-plugin-valtio"
import { store } from "@tauri-store/valtio"
import { useSnapshot } from "valtio"
import { DEFAULT_STORE_CONFIG } from "."
import { DEFAULT_STORE_CONFIG } from "./config"
const defaultValue = {