[feat] tray powerplan items and seperators
This commit is contained in:
@@ -9,6 +9,7 @@ import { useDebounce } from "ahooks"
|
||||
import { useEffect } from "react"
|
||||
import "./globals.css"
|
||||
import Providers from "./providers"
|
||||
import { PowerPlans } from "@/components/cstb/PowerPlan"
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const steam = useSteamStore()
|
||||
@@ -35,6 +36,15 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
||||
await invoke("kill_game")
|
||||
addToast({ title: "已关闭CS2" })
|
||||
})
|
||||
|
||||
void listen<number>("tray://set_powerplan", async (event) => {
|
||||
if (typeof(event.payload) === "number" && event.payload <= 0 && event.payload > 4) return
|
||||
await invoke("set_powerplan", { plan: event.payload })
|
||||
const current = await invoke<number>("get_powerplan")
|
||||
tool.setPowerPlan(current)
|
||||
|
||||
addToast({ title: `电源计划已切换 → ${PowerPlans[current].title}` })
|
||||
})
|
||||
})
|
||||
|
||||
// 检测steam路径和游戏路径是否有效
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Key } from "@react-types/shared"
|
||||
import { useToolStore } from "@/store/tool"
|
||||
import { useEffect } from "react"
|
||||
|
||||
const PowerPlans = [
|
||||
export const PowerPlans = [
|
||||
{
|
||||
id: "0",
|
||||
title: "其他",
|
||||
|
||||
@@ -55,7 +55,7 @@ const Avatar = () => {
|
||||
<img
|
||||
src={
|
||||
steam.currentUser()?.avatar
|
||||
? `data:image/png;base64,${steam.currentUser()?.avatar || ''}`
|
||||
? `data:image/png;base64,${steam.currentUser()?.avatar || ""}`
|
||||
: "/logo_square.png"
|
||||
}
|
||||
alt="avatar"
|
||||
@@ -72,9 +72,10 @@ const Avatar = () => {
|
||||
const SideBar = () => {
|
||||
const app = useAppStore()
|
||||
|
||||
void getVersion().then((Value) => {
|
||||
app.setVersion(Value)
|
||||
})
|
||||
if (typeof window !== "undefined")
|
||||
void getVersion().then((Value) => {
|
||||
app.setVersion(Value)
|
||||
})
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -37,7 +37,7 @@ export const useAppStore = () => {
|
||||
}
|
||||
|
||||
const launchStore = new LazyStore('cstb.json', { autoSave: true });
|
||||
void launchStore.save()
|
||||
if (typeof window !== 'undefined') void launchStore.save()
|
||||
|
||||
const setVersion = (version: string) => {
|
||||
appStore.state.version = version
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { store } from "@tauri-store/valtio"
|
||||
import { useSnapshot } from "valtio"
|
||||
import { DEFAULT_STORE_CONFIG } from "./config"
|
||||
import { emit } from "@tauri-apps/api/event"
|
||||
import { send } from "process"
|
||||
|
||||
interface LaunchOption {
|
||||
option: string
|
||||
@@ -50,6 +52,13 @@ export const useToolStore = () => {
|
||||
void toolStore.start
|
||||
const state = useSnapshot(toolStore.state)
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
setTimeout(() => {
|
||||
sendCurrentLaunchOptionToTray(state.launchIndex)
|
||||
sendPowerPlanToTray(state.powerPlan)
|
||||
}, 500)
|
||||
}
|
||||
|
||||
return {
|
||||
state,
|
||||
store: toolStore,
|
||||
@@ -77,10 +86,18 @@ const setLaunchOptions = (options: LaunchOption[]) => {
|
||||
|
||||
const setLaunchIndex = (index: number) => {
|
||||
toolStore.state.launchIndex = index
|
||||
sendCurrentLaunchOptionToTray(index)
|
||||
}
|
||||
|
||||
const sendCurrentLaunchOptionToTray = (index: number) => {
|
||||
emit("tray://get_current_launch_option", toolStore.state.launchOptions[index].name || index + 1)
|
||||
}
|
||||
const setPowerPlan = (plan: number) => {
|
||||
toolStore.state.powerPlan = plan
|
||||
sendPowerPlanToTray(plan)
|
||||
}
|
||||
const sendPowerPlanToTray = (plan: number) => {
|
||||
emit("tray://get_powerplan", plan)
|
||||
}
|
||||
|
||||
const setVideoSetting = (setting: VideoSetting) => {
|
||||
|
||||
Reference in New Issue
Block a user