mirror of
https://github.com/element-hq/element-android
synced 2024-11-27 11:59:12 +03:00
Parsing the full version of browsers for Web device type
This commit is contained in:
parent
a6289d19f4
commit
a5bcbf300b
2 changed files with 13 additions and 14 deletions
|
@ -75,6 +75,7 @@ class ParseDeviceUserAgentUseCase @Inject constructor() {
|
|||
|
||||
private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo {
|
||||
val browserSegments = userAgent.split(" ")
|
||||
// TODO parse the whole version of browser
|
||||
val (browserName, browserVersion) = when {
|
||||
isFirefox(browserSegments) -> {
|
||||
Pair("Firefox", getBrowserVersion(browserSegments, "Firefox"))
|
||||
|
@ -140,13 +141,11 @@ class ParseDeviceUserAgentUseCase @Inject constructor() {
|
|||
}
|
||||
|
||||
private fun getBrowserVersion(browserSegments: List<String>, browserName: String): String? {
|
||||
// Chrome/104.0.3497.100 -> 104
|
||||
// e.g Chrome/104.0.3497.100 -> 104.0.3497.100
|
||||
return browserSegments
|
||||
.find { it.startsWith(browserName) }
|
||||
?.split("/")
|
||||
?.getOrNull(1)
|
||||
?.split(".")
|
||||
?.firstOrNull()
|
||||
}
|
||||
|
||||
private fun isEdge(browserSegments: List<String>): Boolean {
|
||||
|
|
|
@ -62,8 +62,8 @@ private val A_USER_AGENT_LIST_FOR_DESKTOP = listOf(
|
|||
"Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36",
|
||||
)
|
||||
private val AN_EXPECTED_RESULT_LIST_FOR_DESKTOP = listOf(
|
||||
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Macintosh", "Electron", "20"),
|
||||
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows NT 10.0", "Electron", "20"),
|
||||
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Macintosh", "Electron", "20.1.1"),
|
||||
DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows NT 10.0", "Electron", "20.1.1"),
|
||||
)
|
||||
|
||||
private val A_USER_AGENT_LIST_FOR_WEB = listOf(
|
||||
|
@ -78,15 +78,15 @@ private val A_USER_AGENT_LIST_FOR_WEB = listOf(
|
|||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246",
|
||||
)
|
||||
private val AN_EXPECTED_RESULT_LIST_FOR_WEB = listOf(
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Chrome", "104"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Chrome", "104"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Firefox", "39"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Safari", "8"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "iPad", "Safari", "8"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "iPhone", "Safari", "8"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 6.0", "Firefox", "40"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Edge", "12"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Chrome", "104.0.5112.102"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Chrome", "104.0.5112.102"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Firefox", "39.0"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Safari", "8.0.3"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69.0.3497.100"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "iPad", "Safari", "8.0"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "iPhone", "Safari", "8.0"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 6.0", "Firefox", "40.0"),
|
||||
DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Edge", "12.246"),
|
||||
)
|
||||
|
||||
private val AN_UNKNOWN_USER_AGENT_LIST = listOf(
|
||||
|
|
Loading…
Reference in a new issue