[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

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 = {