Put model state into an Arc (#28)
Build Mumble Web 2 / macos_build (push) Successful in 1m14s
Build Mumble Web 2 / linux_build (push) Successful in 1m27s
Build Mumble Web 2 / windows_build (push) Successful in 2m56s
Build Mumble Web 2 / android_build (push) Successful in 4m39s

Previously the model state was in a `static STATE` to make it accessible to all the various subsystems. This moves it into an Arc and plumbs the reference around via function arguments. That allows us to do non-static initialization, eg based on user config. I also moved some things into dioxus context.

Co-authored-by: Sam Sartor <me@samsartor.com>
Co-committed-by: Sam Sartor <me@samsartor.com>
This commit was merged in pull request #28.
This commit is contained in:
2026-03-30 00:56:36 +00:00
committed by Sam Sartor
parent 7337b3e49b
commit f0ce15000e
9 changed files with 115 additions and 70 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
use crate::app::Command;
use crate::app::{Command, SharedState};
use color_eyre::eyre::{bail, Error};
use dioxus::hooks::UnboundedReceiver;
use mumble_protocol::control::ClientControlCodec;
@@ -74,6 +74,7 @@ pub async fn network_connect(
username: String,
event_rx: &mut UnboundedReceiver<Command>,
overrides: &ProxyOverrides,
state: SharedState,
) -> Result<(), Error> {
info!("connecting");
@@ -102,7 +103,7 @@ pub async fn network_connect(
let reader = asynchronous_codec::FramedRead::new(read_server.compat(), read_codec);
let writer = asynchronous_codec::FramedWrite::new(write_server.compat_write(), write_codec);
crate::network_loop(username, event_rx, reader, writer).await
crate::network_loop(username, state, event_rx, reader, writer).await
}
pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
+3 -4
View File
@@ -1,9 +1,7 @@
use crate::app::Command;
use crate::app::{Command, SharedState};
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use etcetera::{choose_app_strategy, AppStrategy, AppStrategyArgs};
use mumble_web2_common::{ProxyOverrides, ServerStatus};
use std::collections::HashMap;
use std::time::Duration;
/// Desktop platform implementation using Tokio and native audio.
@@ -30,8 +28,9 @@ impl super::PlatformInterface for DesktopPlatform {
username: String,
event_rx: &mut UnboundedReceiver<Command>,
overrides: &ProxyOverrides,
state: SharedState,
) -> Result<(), Error> {
super::connect::network_connect(address, username, event_rx, overrides).await
super::connect::network_connect(address, username, event_rx, overrides, state).await
}
async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
+3 -2
View File
@@ -1,4 +1,4 @@
use crate::app::Command;
use crate::app::{Command, SharedState};
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use mumble_web2_common::{ProxyOverrides, ServerStatus};
@@ -24,8 +24,9 @@ impl super::PlatformInterface for MobilePlatform {
username: String,
event_rx: &mut UnboundedReceiver<Command>,
overrides: &ProxyOverrides,
state: SharedState,
) -> Result<(), Error> {
super::connect::network_connect(address, username, event_rx, overrides).await
super::connect::network_connect(address, username, event_rx, overrides, state).await
}
async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
+4 -2
View File
@@ -4,7 +4,8 @@
//! The traits make the platform boundary explicit and provide compile-time verification.
#![allow(async_fn_in_trait)]
use crate::{app::Command, effects::AudioProcessor};
use crate::app::{Command, SharedState};
use crate::effects::AudioProcessor;
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use mumble_web2_common::{ProxyOverrides, ServerStatus};
@@ -51,7 +52,7 @@ pub trait AudioPlayerInterface {
fn play_opus(&mut self, payload: &[u8]);
}
pub trait ConfigSystemInterface: Sized {
pub trait ConfigSystemInterface: Sized + Clone {
fn new() -> Result<Self, Error>;
fn config_get<T>(&self, key: &str) -> Option<T>
@@ -82,6 +83,7 @@ pub trait PlatformInterface {
username: String,
event_rx: &mut UnboundedReceiver<Command>,
proxy_overrides: &ProxyOverrides,
state: SharedState,
) -> impl Future<Output = Result<(), Error>>;
/// Get server status (user count, version, etc.).
+1 -5
View File
@@ -1,10 +1,6 @@
use crate::app::Command;
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use mumble_web2_common::ServerStatus;
use std::collections::HashMap;
use std::time::Duration;
use tracing::{error, info, warn};
use tracing::info;
#[derive(Clone, PartialEq)]
pub struct NativeConfigSystem {
+3 -1
View File
@@ -1,6 +1,6 @@
/// Stub implementation of the platform interface, so that we can
/// `cargo check` without any --feature flags.
use crate::effects::AudioProcessor;
use crate::{app::SharedState, effects::AudioProcessor};
use color_eyre::eyre::Error;
use dioxus::hooks::UnboundedReceiver;
use mumble_web2_common::{ProxyOverrides, ServerStatus};
@@ -25,6 +25,7 @@ impl super::PlatformInterface for StubPlatform {
_username: String,
_event_rx: &mut UnboundedReceiver<crate::app::Command>,
_overrides: &ProxyOverrides,
_state: SharedState,
) -> impl Future<Output = Result<(), Error>> {
async { panic!("stubbed platform") }
}
@@ -77,6 +78,7 @@ impl super::AudioPlayerInterface for StubAudioPlayer {
}
}
#[derive(Clone)]
pub struct StubConfigSystem;
impl super::ConfigSystemInterface for StubConfigSystem {
+5 -3
View File
@@ -1,4 +1,4 @@
use crate::app::Command;
use crate::app::{Command, SharedState};
use crate::effects::{AudioProcessor, AudioProcessorSender, TransmitState};
use color_eyre::eyre::{bail, eyre, Error};
use crossbeam::atomic::AtomicCell;
@@ -111,8 +111,9 @@ impl super::PlatformInterface for WebPlatform {
username: String,
event_rx: &mut UnboundedReceiver<Command>,
overrides: &ProxyOverrides,
state: SharedState,
) -> Result<(), Error> {
network_connect(address, username, event_rx, overrides).await
network_connect(address, username, event_rx, overrides, state).await
}
async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
@@ -434,6 +435,7 @@ pub async fn network_connect(
username: String,
event_rx: &mut UnboundedReceiver<Command>,
overrides: &ProxyOverrides,
state: SharedState,
) -> Result<(), Error> {
info!("connecting");
@@ -492,7 +494,7 @@ pub async fn network_connect(
let writer =
asynchronous_codec::FramedWrite::new(wasm_stream_writable.into_async_write(), write_codec);
crate::network_loop(username, event_rx, reader, writer).await
crate::network_loop(username, state, event_rx, reader, writer).await
}
pub fn absolute_url(path: &str) -> Result<Url, Error> {