From cbe0019d7c437e0453c2ac922a38db230238c816 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Fri, 28 Aug 2026 01:32:59 +0200 Subject: [PATCH] Device switching --- src-tauri/src/commands/config.rs | 31 +++++++++++++++++++++++++++++-- src/app/app.ts | 3 +++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index cc7cc22..79c23bd 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -4,6 +4,8 @@ use std::fs; use std::sync::Mutex; use tauri::{AppHandle, Manager, State}; +use crate::commands::audio::VoiceState; + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Config { @@ -42,8 +44,33 @@ fn config_file_path(app: &AppHandle) -> Result { } #[tauri::command] -pub fn update_config(state: State, config: Config) -> Result<(), String> { - *state.0.lock().unwrap() = config; +pub fn update_config( + state: State, + voice_state: State<'_, VoiceState>, + mut config: Config, +) -> Result<(), String> { + let mut state_lock = state.0.lock().unwrap(); + + std::mem::swap(&mut *state_lock, &mut config); + + let Some(sesh) = &mut *voice_state.inner.session.lock().unwrap() else { + return Ok(()); + }; + + if state_lock.input_device_name != config.input_device_name { + sesh.update_input_device( + state_lock.input_device_name.clone(), + voice_state.inner.clone(), + )?; + } + + if state_lock.output_device_name != config.output_device_name { + sesh.update_output_device( + state_lock.output_device_name.clone(), + voice_state.inner.clone(), + )?; + } + Ok(()) } diff --git a/src/app/app.ts b/src/app/app.ts index 55efdec..58924f1 100644 --- a/src/app/app.ts +++ b/src/app/app.ts @@ -8,6 +8,7 @@ import axios from "axios"; import { Account, AccountsFile, getAccounts } from "@/lib/accounts"; import { Page } from "@/components/page/PageView"; import { ClientMethod } from "./protocol"; +import { Config, getConfig } from "@/lib/config"; ed.hashes.sha512 = sha512; @@ -31,6 +32,7 @@ export default class Enclave

{ public isSettingsOpen: boolean; public forceRender: () => void; public page?: P; + public config?: Config; public constructor() { this.serverList = {}; @@ -41,6 +43,7 @@ export default class Enclave

{ public async init() { this.serverList = await getServerList(); this.accounts = await getAccounts(); + this.config = await getConfig(); } public getAccount(): Account | null {