11import { createContext , useContext , useState , useEffect , type ReactNode } from "react" ;
22import { invoke } from "@tauri-apps/api/core" ;
33import { message } from "@tauri-apps/plugin-dialog" ;
4- import { set_eq_all , set_pitch as audio_set_pitch , set_crossfade as audio_set_cf , EQ_FREQS } from "@/lib" ;
4+ import { set_eq_all , set_pitch as audio_set_pitch , set_crossfade as audio_set_cf , set_spatial as audio_set_spatial , EQ_FREQS } from "@/lib" ;
55
66export type EqPreset = { name : string ; gains : number [ ] } ;
77
@@ -82,6 +82,8 @@ type SettingsState = {
8282 set_amll_word_sync : ( v : boolean ) => void ;
8383 crossfade : number ;
8484 set_crossfade : ( v : number ) => void ;
85+ spatial_audio : boolean ;
86+ set_spatial_audio : ( v : boolean ) => void ;
8587 custom_presets : EqPreset [ ] ;
8688 save_preset : ( name : string , gains : number [ ] ) => void ;
8789 delete_preset : ( name : string ) => void ;
@@ -121,6 +123,7 @@ export function SettingsProv({ children }: { children: ReactNode }) {
121123 const s = localStorage . getItem ( "crossfade" ) ;
122124 return s ? Math . max ( 0 , Math . min ( 12 , parseFloat ( s ) || 0 ) ) : 0 ;
123125 } ) ;
126+ const [ spatial_audio , _set_spatial ] = useState ( ( ) => localStorage . getItem ( "spatial_audio" ) === "1" ) ;
124127 const [ custom_presets , _set_custom_presets ] = useState < EqPreset [ ] > ( load_custom_presets ) ;
125128
126129 useEffect ( ( ) => {
@@ -140,6 +143,10 @@ export function SettingsProv({ children }: { children: ReactNode }) {
140143 audio_set_cf ( crossfade ) ;
141144 } , [ crossfade ] ) ;
142145
146+ useEffect ( ( ) => {
147+ audio_set_spatial ( spatial_audio ) ;
148+ } , [ spatial_audio ] ) ;
149+
143150 useEffect ( ( ) => {
144151 if ( ! tray_enabled ) {
145152 invoke ( "tray_set" , { enabled : false } ) . catch ( e => console . error ( "tray_set off:" , e ) ) ;
@@ -167,6 +174,7 @@ export function SettingsProv({ children }: { children: ReactNode }) {
167174 const set_exp_volume = ( v : boolean ) => persist_bool ( "exp_volume" , v , _set_exp_vol ) ;
168175 const set_amll_lyrics = ( v : boolean ) => persist_bool ( "amll_lyrics" , v , _set_amll ) ;
169176 const set_amll_word_sync = ( v : boolean ) => persist_bool ( "amll_word_sync" , v , _set_amll_ws ) ;
177+ const set_spatial_audio = ( v : boolean ) => persist_bool ( "spatial_audio" , v , _set_spatial ) ;
170178
171179 function set_eq_bands ( gains : number [ ] ) {
172180 localStorage . setItem ( "eq_bands" , JSON . stringify ( gains ) ) ;
@@ -243,7 +251,7 @@ export function SettingsProv({ children }: { children: ReactNode }) {
243251 }
244252
245253 return (
246- < Ctx . Provider value = { { immersive_bg, set_immersive_bg, eq_bands, set_eq_bands, eq_enabled, set_eq_enabled, discord_rpc, set_discord_rpc, rpc_opts, set_rpc_opts, tray_enabled, set_tray_enabled, sp_client_id, set_sp_client_id, sp_tokens, sp_token, sp_connect, sp_disconnect, sp_loading, pitch, set_pitch, exp_volume, set_exp_volume, amll_lyrics, set_amll_lyrics, amll_word_sync, set_amll_word_sync, crossfade, set_crossfade, custom_presets, save_preset, delete_preset } } >
254+ < Ctx . Provider value = { { immersive_bg, set_immersive_bg, eq_bands, set_eq_bands, eq_enabled, set_eq_enabled, discord_rpc, set_discord_rpc, rpc_opts, set_rpc_opts, tray_enabled, set_tray_enabled, sp_client_id, set_sp_client_id, sp_tokens, sp_token, sp_connect, sp_disconnect, sp_loading, pitch, set_pitch, exp_volume, set_exp_volume, amll_lyrics, set_amll_lyrics, amll_word_sync, set_amll_word_sync, crossfade, set_crossfade, spatial_audio , set_spatial_audio , custom_presets, save_preset, delete_preset } } >
247255 { children }
248256 </ Ctx . Provider >
249257 ) ;
0 commit comments