diff --git a/gui/src/imp/native_audio.rs b/gui/src/imp/native_audio.rs index 5b5b3c5..ed3eb43 100644 --- a/gui/src/imp/native_audio.rs +++ b/gui/src/imp/native_audio.rs @@ -81,7 +81,6 @@ impl super::AudioSystemInterface for NativeAudioSystem { type AudioPlayer = NativeAudioPlayer; async fn new() -> Result { - // TODO let host = cpal::default_host(); let name = host.id(); let processors = AudioProcessorSender::default(); diff --git a/gui/src/imp/stub.rs b/gui/src/imp/stub.rs index c4f2917..d03cd5e 100644 --- a/gui/src/imp/stub.rs +++ b/gui/src/imp/stub.rs @@ -1,3 +1,5 @@ +/// Stub implementation of the platform interface, so that we can +/// `cargo check` without any --feature flags. use crate::effects::AudioProcessor; use color_eyre::eyre::Error; use dioxus::hooks::UnboundedReceiver; @@ -10,11 +12,11 @@ impl super::PlatformInterface for StubPlatform { type AudioSystem = StubAudioSystem; fn init_logging() { - todo!() + panic!("stubbed platform") } fn request_permissions() { - todo!() + panic!("stubbed platform") } fn network_connect( @@ -23,37 +25,37 @@ impl super::PlatformInterface for StubPlatform { _event_rx: &mut UnboundedReceiver, _gui_config: &ClientConfig, ) -> impl Future> { - async { todo!() } + async { panic!("stubbed platform") } } fn get_status( _client: &reqwest::Client, ) -> impl Future> { - async { todo!() } + async { panic!("stubbed platform") } } fn load_config() -> impl Future> { - async { todo!() } + async { panic!("stubbed platform") } } fn load_username() -> Option { - todo!() + panic!("stubbed platform") } fn load_server_url() -> Option { - todo!() + panic!("stubbed platform") } fn set_default_username(_username: &str) -> Option<()> { - todo!() + panic!("stubbed platform") } fn set_default_server(_server: &str) -> Option<()> { - todo!() + panic!("stubbed platform") } fn sleep(_duration: std::time::Duration) -> impl Future { - async { todo!() } + async { panic!("stubbed platform") } } } @@ -63,22 +65,22 @@ impl super::AudioSystemInterface for StubAudioSystem { type AudioPlayer = StubAudioPlayer; async fn new() -> Result { - todo!() + panic!("stubbed platform") } fn set_processor(&self, _processor: AudioProcessor) { - todo!() + panic!("stubbed platform") } fn start_recording( &mut self, _each: impl FnMut(Vec, bool) + Send + 'static, ) -> Result<(), Error> { - todo!() + panic!("stubbed platform") } fn create_player(&mut self) -> Result { - todo!() + panic!("stubbed platform") } } @@ -86,7 +88,7 @@ pub struct StubAudioPlayer; impl super::AudioPlayerInterface for StubAudioPlayer { fn play_opus(&mut self, _payload: &[u8]) { - todo!() + panic!("stubbed platform") } } @@ -99,7 +101,7 @@ impl SpawnHandle { where F: Future + 'static, { - todo!() + panic!("stubbed platform") } #[allow(unused)] @@ -113,5 +115,5 @@ pub fn spawn(_future: F) where F: Future + 'static, { - todo!() + panic!("stubbed platform") } diff --git a/gui/src/imp/web.rs b/gui/src/imp/web.rs index 92a1a18..1a55ec4 100644 --- a/gui/src/imp/web.rs +++ b/gui/src/imp/web.rs @@ -3,7 +3,6 @@ use crate::effects::{AudioProcessor, AudioProcessorSender, TransmitState}; use color_eyre::eyre::{bail, eyre, Error}; use crossbeam::atomic::AtomicCell; use dioxus::prelude::*; -use futures::{AsyncRead, AsyncWrite}; use gloo_timers::future::TimeoutFuture; use js_sys::Float32Array; use mumble_protocol::control::ClientControlCodec; @@ -65,7 +64,25 @@ impl super::PlatformInterface for WebPlatform { type AudioSystem = WebAudioSystem; fn init_logging() { - init_logging(); + // copied from tracing_web example usage + + use tracing_subscriber::fmt::format::Pretty; + use tracing_subscriber::prelude::*; + use tracing_web::{performance_layer, MakeWebConsoleWriter}; + + let fmt_layer = tracing_subscriber::fmt::layer() + .with_ansi(false) // Only partially supported across browsers + .without_time() // std::time is not available in browsers + .with_writer(MakeWebConsoleWriter::new()) // write events to the console + .with_filter(LevelFilter::DEBUG); + let perf_layer = performance_layer().with_details_from_fields(Pretty::default()); + + tracing_subscriber::registry() + .with(fmt_layer) + .with(perf_layer) + .init(); + + info!("logging initiated"); } fn request_permissions() { @@ -73,23 +90,43 @@ impl super::PlatformInterface for WebPlatform { } async fn load_config() -> color_eyre::Result { - load_config().await + let config_url = match option_env!("MUMBLE_WEB2_GUI_CONFIG_URL") { + Some(url) => Url::parse(url)?, + None => absolute_url("config")?, + }; + info!("loading config from {}", config_url); + + let config = reqwest::get(config_url) + .await? + .json::() + .await?; + + Ok(config) } fn load_username() -> Option { - load_username() + web_sys::window() + .unwrap() + .local_storage() + .ok()?? + .get_item("username") + .ok()? } fn load_server_url() -> Option { - load_server_url() + None } fn set_default_username(username: &str) -> Option<()> { - set_default_username(username) + web_sys::window()? + .local_storage() + .ok()?? + .set_item("username", username) + .ok() } - fn set_default_server(server: &str) -> Option<()> { - set_default_server(server) + fn set_default_server(_server: &str) -> Option<()> { + None } async fn network_connect( @@ -102,7 +139,12 @@ impl super::PlatformInterface for WebPlatform { } async fn get_status(client: &reqwest::Client) -> color_eyre::Result { - get_status(client).await + Ok(client + .get(absolute_url("status")?) + .send() + .await? + .json::() + .await?) } async fn sleep(duration: Duration) { @@ -476,79 +518,8 @@ pub async fn network_connect( crate::network_loop(username, event_rx, reader, writer).await } -pub fn set_default_username(username: &str) -> Option<()> { - web_sys::window()? - .local_storage() - .ok()?? - .set_item("username", username) - .ok() -} - -pub fn set_default_server(username: &str) -> Option<()> { - None -} - -pub fn load_username() -> Option { - web_sys::window() - .unwrap() - .local_storage() - .ok()?? - .get_item("username") - .ok()? -} - -pub fn load_server_url() -> Option { - None -} - pub fn absolute_url(path: &str) -> Result { let window: web_sys::Window = web_sys::window().expect("no global `window` exists"); let location = window.location(); Ok(Url::parse(&location.href().ey()?)?.join(path)?) } - -pub async fn load_config() -> color_eyre::Result { - let config_url = match option_env!("MUMBLE_WEB2_GUI_CONFIG_URL") { - Some(url) => Url::parse(url)?, - None => absolute_url("config")?, - }; - info!("loading config from {}", config_url); - - let config = reqwest::get(config_url) - .await? - .json::() - .await?; - - Ok(config) -} - -pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result { - Ok(client - .get(absolute_url("status")?) - .send() - .await? - .json::() - .await?) -} - -pub fn init_logging() { - // copied from tracing_web example usage - - use tracing_subscriber::fmt::format::Pretty; - use tracing_subscriber::prelude::*; - use tracing_web::{performance_layer, MakeWebConsoleWriter}; - - let fmt_layer = tracing_subscriber::fmt::layer() - .with_ansi(false) // Only partially supported across browsers - .without_time() // std::time is not available in browsers - .with_writer(MakeWebConsoleWriter::new()) // write events to the console - .with_filter(LevelFilter::DEBUG); - let perf_layer = performance_layer().with_details_from_fields(Pretty::default()); - - tracing_subscriber::registry() - .with(fmt_layer) - .with(perf_layer) - .init(); - - info!("logging initiated"); -}