Skip to content

fix(utils): try to improve mobile detection#65

Merged
orhun merged 1 commit intoratatui:mainfrom
dawedawe:improve_is_mobile
Apr 1, 2025
Merged

fix(utils): try to improve mobile detection#65
orhun merged 1 commit intoratatui:mainfrom
dawedawe:improve_is_mobile

Conversation

@dawedawe
Copy link
Copy Markdown
Contributor

Comes with its own set of drawbacks but maybe still a bit better than using the size 🤷

Copy link
Copy Markdown
Member

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, nice!

Some questions:

  • Did you run into an issue where the mobile isn't detected with the previous approach?
  • What kind of fallbacks does this have?

@dawedawe
Copy link
Copy Markdown
Contributor Author

Hey man, thanks for the review.

* Did you run into an issue where the mobile isn't detected with the previous approach?

If you use a mobile browser and just change the device orientation to landscape, the old approach would claim the device is not a mobile anymore. To me, the function is_mobile should really try to determine the device class and leave questions about the size to the size functions like get_raw_screen_size that the ratzilla programmer can then interpret according to their requirements.
In general, keeping the API a bit more orthogonal here seems good to me.

* What kind of fallbacks does this have?

The drawbacks of using the agent string are:

  • Users can set the user agent of their browser to any string
  • Browsers can change their user agent from one version to another

I think these drawbacks are acceptable, we just have to be aware of them.

@orhun orhun merged commit 27f1c0b into ratatui:main Apr 1, 2025
7 of 8 checks passed
@dawedawe dawedawe deleted the improve_is_mobile branch April 1, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants