gled-ui 2.32.1

gled's egui interface, shared by the desktop app and the browser
Documentation
//! What the interface can do only on some platforms.

/// Opens the interface again in a new browser tab, which is a new window
/// connected to the same engine.
#[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:?}"),
    }
}

/// Sets the title of the browser tab.
#[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);
    }
}

/// Whether the page fills the screen.
#[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()
}

/// Shows the page on the whole screen, or leaves that. Browsers only allow
/// it in answer to a click or key, which is when egui handles them on the web.
#[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:?}");
    }
}