xpenatan / gdx-teavm

Run Libgdx in a webbrowser with teavm
Apache License 2.0
107 stars 16 forks source link

How to distinguish between mobile and desktop browser? #96

Closed Quillraven closed 1 year ago

Quillraven commented 1 year ago

Hi,

I have a question: how do you distinguish between mobile and desktop browser?

I saw a code snippet like:

val userAgent = Window.Navigator.getUserAgent() ?: ""
if(userAgent.contains("Mobile") || userAgent.contains("Android")) {
  // mobile browser
}

but this does not seem to work because of missing GWTBridge class at runtime. Also, it is GWT stuff and I am not sure if this is the correct approach for TeaVM.

In LibGDX itself I only see an ApplicationType which always return WebGL for TeaVM backend. I think you cannot distinguish between mobile and desktop browser with that.

How would you solve that?

xpenatan commented 1 year ago

Hi. sorry for long delay. Very busy with work.

TeaWebAgent and TeaAgentInfo class check OS and browser. Maybe adding mobile and android will work. https://github.com/xpenatan/gdx-teavm/blob/master/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/agent/TeaWebAgent.java

It just set as a system property in TeaApplication.init(). I guess this part of code needs improvements.