250 lines
7.2 KiB
TypeScript
250 lines
7.2 KiB
TypeScript
import { store } from "@tauri-store/valtio"
|
|
import { useSnapshot } from "valtio"
|
|
import { DEFAULT_STORE_CONFIG } from "./config"
|
|
import { emit } from "@tauri-apps/api/event"
|
|
import { invoke } from "@tauri-apps/api/core"
|
|
import VideoSetting from "@/components/cstb/VideoSetting"
|
|
|
|
interface LaunchOption {
|
|
option: string
|
|
name: string
|
|
}
|
|
|
|
export interface VideoSetting {
|
|
version: string; // 版本
|
|
vendor_id: string; // 供应商ID
|
|
device_id: string; // 设备ID
|
|
cpu_level: string; // CPU等级
|
|
gpu_mem_level: string; // GPU内存等级
|
|
gpu_level: string; // GPU等级
|
|
knowndevice: string; // 已知设备
|
|
defaultres: string; // 默认分辨率宽度
|
|
defaultresheight: string; // 默认分辨率高度
|
|
refreshrate_numerator: string; // 刷新率分子
|
|
refreshrate_denominator: string; // 刷新率分母
|
|
fullscreen: string; // 全屏
|
|
coop_fullscreen: string; // 合作模式全屏
|
|
nowindowborder: string; // 无窗口边框
|
|
mat_vsync: string; // 垂直同步
|
|
fullscreen_min_on_focus_loss: string; // 失去焦点时最小化全屏
|
|
high_dpi: string; // 高DPI
|
|
auto_config: string; // 自动配置
|
|
shaderquality: string; // 光影质量
|
|
r_texturefilteringquality: string; // 纹理过滤质量
|
|
msaa_samples: string; // 多重采样抗锯齿样本数
|
|
r_csgo_cmaa_enable: string; // CMAA抗锯齿启用
|
|
videocfg_shadow_quality: string; // 阴影质量
|
|
videocfg_dynamic_shadows: string; // 动态阴影
|
|
videocfg_texture_detail: string; // 纹理细节
|
|
videocfg_particle_detail: string; // 粒子细节
|
|
videocfg_ao_detail: string; // 环境光遮蔽细节
|
|
videocfg_hdr_detail: string; // 高动态范围细节
|
|
videocfg_fsr_detail: string; // FSR细节
|
|
monitor_index: string; // 显示器索引
|
|
r_low_latency: string; // 低延迟
|
|
aspectratiomode: string; // 宽高比模式
|
|
}
|
|
|
|
// 视频设置预设模版
|
|
export const VideoSettingTemplate = {
|
|
veryhigh: {
|
|
shaderquality: "1",
|
|
r_texturefilteringquality: "3",
|
|
msaa_samples: "8",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "3",
|
|
videocfg_dynamic_shadows: "1",
|
|
videocfg_texture_detail: "2",
|
|
videocfg_particle_detail: "3",
|
|
videocfg_ao_detail: "3",
|
|
videocfg_hdr_detail: "-1",
|
|
videocfg_fsr_detail: "0",
|
|
},
|
|
high: {
|
|
shaderquality: "1",
|
|
r_texturefilteringquality: "3",
|
|
msaa_samples: "4",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "2",
|
|
videocfg_dynamic_shadows: "1",
|
|
videocfg_texture_detail: "2",
|
|
videocfg_particle_detail: "2",
|
|
videocfg_ao_detail: "2",
|
|
videocfg_hdr_detail: "-1",
|
|
videocfg_fsr_detail: "0",
|
|
},
|
|
middle: {
|
|
shaderquality: "0",
|
|
r_texturefilteringquality: "1",
|
|
msaa_samples: "2",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "1",
|
|
videocfg_dynamic_shadows: "1",
|
|
videocfg_texture_detail: "1",
|
|
videocfg_particle_detail: "1",
|
|
videocfg_ao_detail: "0",
|
|
videocfg_fsr_detail: "2",
|
|
},
|
|
low: {
|
|
shaderquality: "0",
|
|
r_texturefilteringquality: "0",
|
|
msaa_samples: "0",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "0",
|
|
videocfg_dynamic_shadows: "0",
|
|
videocfg_texture_detail: "0",
|
|
videocfg_particle_detail: "0",
|
|
videocfg_ao_detail: "0",
|
|
videocfg_hdr_detail: "3",
|
|
videocfg_fsr_detail: "3",
|
|
},
|
|
recommend: {
|
|
shaderquality: "0",
|
|
r_texturefilteringquality: "3",
|
|
msaa_samples: "2",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "0",
|
|
videocfg_dynamic_shadows: "1",
|
|
videocfg_texture_detail: "1",
|
|
videocfg_particle_detail: "0",
|
|
videocfg_ao_detail: "0",
|
|
videocfg_hdr_detail: "3",
|
|
videocfg_fsr_detail: "0",
|
|
},
|
|
}
|
|
|
|
|
|
const defaultValue = {
|
|
launchOptions: [
|
|
{ option: "-novid -high -freq 144 -fullscreen", name: "" },
|
|
{ option: "-novid -high -w 1920 -h 1080 -freq 144 -sw -noborder", name: "" },
|
|
{ option: "-novid -high -freq 144 -fullscreen -allow_third_party_software", name: "" },
|
|
] as LaunchOption[],
|
|
launchIndex: 0,
|
|
powerPlan: 0,
|
|
videoSetting: {
|
|
version: "15",
|
|
vendor_id: "0",
|
|
device_id: "0",
|
|
cpu_level: "3",
|
|
gpu_mem_level: "3",
|
|
gpu_level: "3",
|
|
knowndevice: "0",
|
|
defaultres: "1920",
|
|
defaultresheight: "1080",
|
|
refreshrate_numerator: "144",
|
|
refreshrate_denominator: "1",
|
|
fullscreen: "1",
|
|
coop_fullscreen: "0",
|
|
nowindowborder: "1",
|
|
mat_vsync: "0",
|
|
fullscreen_min_on_focus_loss: "1",
|
|
high_dpi: "0",
|
|
auto_config: "2",
|
|
shaderquality: "0",
|
|
r_texturefilteringquality: "3",
|
|
msaa_samples: "2",
|
|
r_csgo_cmaa_enable: "0",
|
|
videocfg_shadow_quality: "0",
|
|
videocfg_dynamic_shadows: "1",
|
|
videocfg_texture_detail: "1",
|
|
videocfg_particle_detail: "0",
|
|
videocfg_ao_detail: "0",
|
|
videocfg_hdr_detail: "3",
|
|
videocfg_fsr_detail: "0",
|
|
monitor_index: "0",
|
|
r_low_latency: "1",
|
|
aspectratiomode: "0",
|
|
} as VideoSetting,
|
|
}
|
|
|
|
export const toolStore = store(
|
|
"tool",
|
|
{ ...defaultValue },
|
|
DEFAULT_STORE_CONFIG,
|
|
)
|
|
|
|
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,
|
|
setLaunchOption,
|
|
setLaunchOptions,
|
|
setLaunchIndex,
|
|
setPowerPlan,
|
|
setVideoSetting,
|
|
getVideoConfig,
|
|
setVideoConfig,
|
|
addLaunchOption,
|
|
resetToolStore,
|
|
}
|
|
}
|
|
|
|
const setLaunchOption = (option: LaunchOption, index: number) => {
|
|
toolStore.state.launchOptions = [
|
|
...toolStore.state.launchOptions.slice(0, index),
|
|
option,
|
|
...toolStore.state.launchOptions.slice(index + 1),
|
|
]
|
|
}
|
|
|
|
const setLaunchOptions = (options: LaunchOption[]) => {
|
|
toolStore.state.launchOptions = options
|
|
}
|
|
|
|
const setLaunchIndex = (index: number) => {
|
|
toolStore.state.launchIndex = index
|
|
sendCurrentLaunchOptionToTray(index)
|
|
}
|
|
|
|
const sendCurrentLaunchOptionToTray = (index: number) => {
|
|
void 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) => {
|
|
void emit("tray://get_powerplan", plan)
|
|
}
|
|
|
|
const setVideoSetting = (setting: VideoSetting) => {
|
|
toolStore.state.videoSetting = setting
|
|
}
|
|
|
|
const getVideoConfig = async (steam_dir: string, steam_id32: number) => {
|
|
const video = await invoke<VideoSetting>("get_cs2_video_config", { steamDir: steam_dir, steamId32: steam_id32 })
|
|
// console.log(video)
|
|
setVideoSetting(video)
|
|
}
|
|
|
|
const setVideoConfig = async (steam_dir: string, steam_id32: number, video_config: VideoSetting) => {
|
|
console.log(video_config.videocfg_hdr_detail)
|
|
await invoke("set_cs2_video_config", { steamDir: steam_dir, steamId32: steam_id32, videoConfig: video_config })
|
|
}
|
|
|
|
const addLaunchOption = (option: LaunchOption) => {
|
|
// 限制最高10个
|
|
if (toolStore.state.launchOptions.length >= 10) {
|
|
return
|
|
}
|
|
toolStore.state.launchOptions = [...toolStore.state.launchOptions, option]
|
|
}
|
|
|
|
const resetToolStore = () => {
|
|
setLaunchOptions(defaultValue.launchOptions)
|
|
setLaunchIndex(defaultValue.launchIndex)
|
|
setPowerPlan(defaultValue.powerPlan)
|
|
setVideoSetting(defaultValue.videoSetting)
|
|
}
|