Device switching

This commit is contained in:
2026-08-28 01:32:59 +02:00
parent de236a247f
commit cbe0019d7c
2 changed files with 32 additions and 2 deletions
+29 -2
View File
@@ -4,6 +4,8 @@ use std::fs;
use std::sync::Mutex; use std::sync::Mutex;
use tauri::{AppHandle, Manager, State}; use tauri::{AppHandle, Manager, State};
use crate::commands::audio::VoiceState;
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Config { pub struct Config {
@@ -42,8 +44,33 @@ fn config_file_path(app: &AppHandle) -> Result<std::path::PathBuf, String> {
} }
#[tauri::command] #[tauri::command]
pub fn update_config(state: State<ConfigState>, config: Config) -> Result<(), String> { pub fn update_config(
*state.0.lock().unwrap() = config; state: State<ConfigState>,
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(()) Ok(())
} }
+3
View File
@@ -8,6 +8,7 @@ import axios from "axios";
import { Account, AccountsFile, getAccounts } from "@/lib/accounts"; import { Account, AccountsFile, getAccounts } from "@/lib/accounts";
import { Page } from "@/components/page/PageView"; import { Page } from "@/components/page/PageView";
import { ClientMethod } from "./protocol"; import { ClientMethod } from "./protocol";
import { Config, getConfig } from "@/lib/config";
ed.hashes.sha512 = sha512; ed.hashes.sha512 = sha512;
@@ -31,6 +32,7 @@ export default class Enclave<P = Page> {
public isSettingsOpen: boolean; public isSettingsOpen: boolean;
public forceRender: () => void; public forceRender: () => void;
public page?: P; public page?: P;
public config?: Config;
public constructor() { public constructor() {
this.serverList = {}; this.serverList = {};
@@ -41,6 +43,7 @@ export default class Enclave<P = Page> {
public async init() { public async init() {
this.serverList = await getServerList(); this.serverList = await getServerList();
this.accounts = await getAccounts(); this.accounts = await getAccounts();
this.config = await getConfig();
} }
public getAccount(): Account | null { public getAccount(): Account | null {