#[cfg(target_arch = "wasm32")]
pub(crate) fn open_in_new_tab() {
let Some(window) = web_sys::window() else {
return;
};
let opened = window
.location()
.href()
.and_then(|href| window.open_with_url_and_target(&href, "_blank"));
match opened {
Ok(Some(_)) => {}
Ok(None) => gled_protocol::action::UiAction::Error(
"The browser blocked the new window, allow pop-ups for this page".to_owned(),
)
.enqueue(),
Err(err) => tracing::warn!("Could not open a new tab: {err:?}"),
}
}
#[cfg(target_arch = "wasm32")]
pub(crate) fn set_page_title(title: &str) {
if let Some(document) = web_sys::window().and_then(|window| window.document()) {
document.set_title(title);
}
}
#[cfg(target_arch = "wasm32")]
pub(crate) fn is_fullscreen() -> bool {
web_sys::window()
.and_then(|window| window.document())
.and_then(|document| document.fullscreen_element())
.is_some()
}
#[cfg(target_arch = "wasm32")]
pub(crate) fn set_fullscreen(fullscreen: bool) {
let Some(document) = web_sys::window().and_then(|window| window.document()) else {
return;
};
if !fullscreen {
document.exit_fullscreen();
} else if let Some(element) = document.document_element()
&& let Err(err) = element.request_fullscreen()
{
tracing::warn!("The browser refused fullscreen: {err:?}");
}
}