Refactor ProxyOverides to be optional
Build Mumble Web 2 / linux_build (push) Successful in 1m37s
Build Mumble Web 2 / windows_build (push) Successful in 2m26s

This commit is contained in:
2026-01-10 17:29:49 -07:00
parent eab8f1d6a7
commit 51f05593ac
5 changed files with 33 additions and 32 deletions
+2 -3
View File
@@ -2,9 +2,8 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
pub struct ProxyOverides {
pub proxy_url: Option<String>,
pub cert_hash: Option<Vec<u8>>,
pub any_server: bool,
pub proxy_url: String,
pub cert_hash: Vec<u8>,
}
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
+18 -12
View File
@@ -309,7 +309,7 @@ pub fn ChatView() -> Element {
}
#[component]
pub fn ControlView(config: Resource<ProxyOverides>) -> Element {
pub fn ControlView(config: Resource<Option<ProxyOverides>>) -> Element {
let net: Coroutine<Command> = use_coroutine_handle();
let status = &STATE.status;
let server = STATE.server.read();
@@ -331,7 +331,8 @@ pub fn ControlView(config: Resource<ProxyOverides>) -> Element {
let proxy_url = config
.read_unchecked()
.as_ref()
.and_then(|gui_config| gui_config.proxy_url.clone());
.and_then(|opt| opt.as_ref())
.map(|gui_config| gui_config.proxy_url.clone());
let connecting_color = "yellow";
let connected_color = "oklch(0.55 0.1184 141.35)";
@@ -508,7 +509,7 @@ pub fn ControlView(config: Resource<ProxyOverides>) -> Element {
}
#[component]
pub fn ServerView(config: Resource<ProxyOverides>) -> Element {
pub fn ServerView(config: Resource<Option<ProxyOverides>>) -> Element {
let net: Coroutine<Command> = use_coroutine_handle();
let server = STATE.server.read();
let Some(&UserState {
@@ -546,7 +547,7 @@ pub fn ServerView(config: Resource<ProxyOverides>) -> Element {
}
#[component]
pub fn LoginView(config: Resource<ProxyOverides>) -> Element {
pub fn LoginView(config: Resource<Option<ProxyOverides>>) -> Element {
let net: Coroutine<Command> = use_coroutine_handle();
let last_status = use_signal(|| None::<color_eyre::Result<ServerStatus>>);
@@ -564,7 +565,8 @@ pub fn LoginView(config: Resource<ProxyOverides>) -> Element {
addr.clone()
} else {
config()
.and_then(|c| c.proxy_url.clone())
.flatten()
.map(|c| c.proxy_url.clone())
.unwrap_or_default()
}
});
@@ -575,13 +577,13 @@ pub fn LoginView(config: Resource<ProxyOverides>) -> Element {
let do_connect = move |_| {
//let _ = set_default_username(&username.read());
let _ = imp::set_default_username(&username.read());
if config.read().as_ref().is_some_and(|cfg| cfg.any_server) {
if config.read().as_ref().is_some_and(|opt| opt.is_none()) {
imp::set_default_server(&address.read());
}
net.send(Connect {
address: address.read().clone(),
username: username.read().clone(),
config: config.read().clone().unwrap_or_default(),
config: config.read().clone().flatten().unwrap_or_default(),
})
};
let status = &STATE.status;
@@ -626,7 +628,7 @@ pub fn LoginView(config: Resource<ProxyOverides>) -> Element {
None => rsx!(),
}
}
if config.read().as_ref().is_some_and(|cfg| cfg.any_server) {
if config.read().as_ref().is_some_and(|opt| opt.is_none()) {
div {
label {
for: "address-entry",
@@ -725,7 +727,7 @@ pub fn app() -> Element {
let config = use_resource(|| async move {
match imp::load_proxy_overides().await {
Ok(config) => config,
Err(_) => ProxyOverides::default(),
Err(_) => None,
}
});
@@ -734,9 +736,13 @@ pub fn app() -> Element {
document::Link{ rel: "stylesheet", href: "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" }
document::Link{ rel: "stylesheet", href: STYLE }
match *STATE.status.read() {
Connected => rsx!(ServerView { config }),
_ => rsx!(LoginView { config }),
if config.read().is_none() {
div { class: "loading", "Loading..." }
} else {
match *STATE.status.read() {
Connected => rsx!(ServerView { config }),
_ => rsx!(LoginView { config }),
}
}
)
}
+2 -6
View File
@@ -366,12 +366,8 @@ pub fn load_server_url() -> Option<String> {
config.get("server").cloned()
}
pub async fn load_proxy_overides() -> color_eyre::Result<ProxyOverides> {
Ok(ProxyOverides {
proxy_url: None,
cert_hash: None,
any_server: true,
})
pub async fn load_proxy_overides() -> color_eyre::Result<Option<ProxyOverides>> {
Ok(None)
}
pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
+4 -4
View File
@@ -342,8 +342,8 @@ pub async fn network_connect(
)
.ey()?;
if let Some(server_hash) = &gui_config.cert_hash {
let hash = web_sys::js_sys::Uint8Array::from(server_hash.as_slice());
if !gui_config.cert_hash.is_empty() {
let hash = web_sys::js_sys::Uint8Array::from(gui_config.cert_hash.as_slice());
web_sys::js_sys::Reflect::set(&object, &"value".into(), &hash).ey()?;
}
@@ -422,7 +422,7 @@ pub fn absolute_url(path: &str) -> Result<Url, Error> {
Ok(Url::parse(&location.href().ey()?)?.join(path)?)
}
pub async fn load_proxy_overides() -> color_eyre::Result<ProxyOverides> {
pub async fn load_proxy_overides() -> color_eyre::Result<Option<ProxyOverides>> {
let config_url = match option_env!("MUMBLE_WEB2_GUI_CONFIG_URL") {
Some(url) => Url::parse(url)?,
None => absolute_url("config")?,
@@ -434,7 +434,7 @@ pub async fn load_proxy_overides() -> color_eyre::Result<ProxyOverides> {
.json::<ProxyOverides>()
.await?;
Ok(config)
Ok(Some(config))
}
pub async fn get_status(client: &reqwest::Client) -> color_eyre::Result<ServerStatus> {
+7 -7
View File
@@ -78,12 +78,12 @@ async fn main() -> Result<()> {
.map_err(|e| anyhow!("could not install crypto provider {e:?}"))?;
let mut client_config = ProxyOverides {
proxy_url: match &server_config.proxy_url {
Some(url) => Some(url.to_string()),
None => None,
},
cert_hash: None,
any_server: false,
proxy_url: server_config
.proxy_url
.as_ref()
.map(|url| url.to_string())
.unwrap_or_default(),
cert_hash: Vec::new(),
};
let (cert, key) = match (&server_config.cert_path, &server_config.key_path) {
@@ -102,7 +102,7 @@ async fn main() -> Result<()> {
let cert = cert_params.self_signed(&key_pair)?;
let hash = hmac_sha256::Hash::hash(cert.der().as_ref());
client_config.cert_hash = Some(hash.into());
client_config.cert_hash = hash.into();
(cert.pem().into(), key_pair.serialize_pem().into())
}