[feat] start hidden + hidden on close + basic tray function

This commit is contained in:
Purp1e
2025-03-26 03:00:18 +08:00
parent e0a84a0570
commit ee03bf0160
20 changed files with 266 additions and 40 deletions

View File

@@ -1,7 +1,8 @@
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"
import { enable, disable } from "@tauri-apps/plugin-autostart"
import { LazyStore } from '@tauri-apps/plugin-store';
const defaultValue = {
version: "0.0.1",
@@ -10,6 +11,8 @@ const defaultValue = {
notice: "",
useMirror: true,
autoStart: false,
startHidden: false,
hiddenOnClose: false,
}
export const appStore = store("app", { ...defaultValue }, DEFAULT_STORE_CONFIG)
@@ -27,10 +30,15 @@ export const useAppStore = () => {
setNotice,
setUseMirror,
setAutoStart,
setStartHidden,
setHiddenOnClose,
resetAppStore,
}
}
const launchStore = new LazyStore('cstb.json', { autoSave: true });
void launchStore.save()
const setVersion = (version: string) => {
appStore.state.version = version
}
@@ -56,6 +64,17 @@ const setAutoStart = (autoStart: boolean) => {
appStore.state.autoStart = autoStart
}
// 同步到 launchStore 使 start hidden 生效
const setStartHidden = async (startHidden: boolean) => {
appStore.state.startHidden = startHidden;
await launchStore.set('hidden', startHidden);
await launchStore.save();
}
const setHiddenOnClose = (hiddenOnClose: boolean) => {
appStore.state.hiddenOnClose = hiddenOnClose;
}
const resetAppStore = () => {
setVersion(defaultValue.version)
setHasUpdate(defaultValue.hasUpdate)
@@ -63,4 +82,6 @@ const resetAppStore = () => {
setNotice(defaultValue.notice)
setUseMirror(defaultValue.useMirror)
setAutoStart(defaultValue.autoStart)
void setStartHidden(defaultValue.startHidden)
setHiddenOnClose(defaultValue.hiddenOnClose)
}