[fix] auto launch persist state
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { store } from "@tauri-store/valtio"
|
||||
import { useSnapshot } from "valtio"
|
||||
import { DEFAULT_STORE_CONFIG } from "./config"
|
||||
import { enable, isEnabled, disable } from "@tauri-apps/plugin-autostart"
|
||||
|
||||
const defaultValue = {
|
||||
version: "0.0.1",
|
||||
@@ -8,6 +9,7 @@ const defaultValue = {
|
||||
inited: false,
|
||||
notice: "",
|
||||
useMirror: true,
|
||||
autoStart: false,
|
||||
}
|
||||
|
||||
export const appStore = store("app", { ...defaultValue }, DEFAULT_STORE_CONFIG)
|
||||
@@ -24,6 +26,7 @@ export const useAppStore = () => {
|
||||
setInited,
|
||||
setNotice,
|
||||
setUseMirror,
|
||||
setAutoStart,
|
||||
resetAppStore,
|
||||
}
|
||||
}
|
||||
@@ -44,10 +47,20 @@ const setUseMirror = (useMirror: boolean) => {
|
||||
appStore.state.useMirror = useMirror
|
||||
}
|
||||
|
||||
const setAutoStart = (autoStart: boolean) => {
|
||||
if (autoStart) {
|
||||
void enable()
|
||||
} else {
|
||||
void disable()
|
||||
}
|
||||
appStore.state.autoStart = autoStart
|
||||
}
|
||||
|
||||
const resetAppStore = () => {
|
||||
setVersion(defaultValue.version)
|
||||
setHasUpdate(defaultValue.hasUpdate)
|
||||
setInited(defaultValue.inited)
|
||||
setNotice(defaultValue.notice)
|
||||
setUseMirror(defaultValue.useMirror)
|
||||
setAutoStart(defaultValue.autoStart)
|
||||
}
|
||||
Reference in New Issue
Block a user