Skip to content

Commit 27f1c0b

Browse files
authored
fix(utils): improve the mobile detection (#65)
1 parent 8413abb commit 27f1c0b

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ web-sys = { version = "0.3.77", features = [
1717
'Document',
1818
'Element',
1919
'HtmlElement',
20+
'Navigator',
2021
'Node',
2122
'Window',
2223
'Screen',

src/utils.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ pub fn open_url(url: &str, new_tab: bool) -> Result<(), Error> {
3030

3131
/// Returns `true` if the screen is a mobile device.
3232
pub fn is_mobile() -> bool {
33-
// TODO: Improve this...
34-
get_raw_screen_size().0 < 550
33+
let user_agent = web_sys::window().and_then(|w| w.navigator().user_agent().ok());
34+
user_agent.is_some_and(|agent| {
35+
let agent = agent.to_lowercase();
36+
agent.contains("mobile") || agent.contains("tablet")
37+
})
3538
}
3639

3740
/// Returns the number of characters that can fit in the window (viewport of the browser or terminal).

0 commit comments

Comments
 (0)