use wasm_bindgen::JsValue;
use web_sys::{HtmlCanvasElement, Window};
pub(crate) fn follow(canvas: &HtmlCanvasElement) {
crate::thread_state::with(|state| *state.web.frame_canvas.borrow_mut() = Some(canvas.clone()));
}
pub(crate) fn window() -> Option<Window> {
crate::thread_state::with(|state| {
state
.web
.frame_canvas
.borrow()
.as_ref()
.and_then(|canvas| canvas.owner_document())
.and_then(|document| document.default_view())
})
.or_else(web_sys::window)
}
pub(crate) fn asked_of(current: &Window) -> bool {
crate::thread_state::with(|state| {
state
.web
.frame_asked_of
.borrow()
.as_ref()
.is_some_and(|asked| {
AsRef::<JsValue>::as_ref(asked) == AsRef::<JsValue>::as_ref(current)
&& !asked.closed().unwrap_or(true)
})
})
}
pub(crate) fn note_asked(window: &Window) {
crate::thread_state::with(|state| {
*state.web.frame_asked_of.borrow_mut() = Some(window.clone());
});
}