forked from quasilyte/ebitengine-input
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internal_firefox_js.go
42 lines (37 loc) · 892 Bytes
/
internal_firefox_js.go
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
33
34
35
36
37
38
39
40
41
42
package input
import (
"strings"
"syscall/js"
)
func isFirefox() bool {
ua := js.Global().Get("navigator").Get("userAgent").String()
return strings.Contains(strings.ToLower(ua), "firefox")
}
func guessFirefoxGamepadModel(id int) gamepadModel {
gamepads := js.Global().Get("navigator").Call("getGamepads")
if gamepads.IsNull() || gamepads.Type() != js.TypeObject {
return gamepadUnknown
}
g := gamepads.Index(id)
if g.IsNull() {
return gamepadUnknown
}
gamepadID := strings.ToLower(g.Get("id").String())
for _, pattern := range firefoxKnownXinput {
if strings.Contains(gamepadID, pattern) {
return gamepadFirefoxXinput
}
}
return gamepadUnknown
}
var firefoxKnownXinput = []string{
// Generic keys.
"xinput",
"x-input",
"x_input",
"xbox",
"x-box",
"x_box",
// Specific models that do not contain any xinput keys in their name.
"logitech gamepad f310",
}