1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use crate::errors::{Error, NativeError};
use web_sys::Window;
pub fn get_window_size(window: &web_sys::Window) -> Result<(u32, u32), Error> {
let width = window
.inner_width()
.ok()
.and_then(|val| val.as_f64())
.ok_or(Error::Native(NativeError::WindowWidth))?;
let height = window
.inner_height()
.ok()
.and_then(|val| val.as_f64())
.ok_or(Error::Native(NativeError::WindowHeight))?;
Ok((width as u32, height as u32))
}
pub fn get_window() -> Result<Window, Error> {
web_sys::window().ok_or(Error::Native(NativeError::Window))
}