Skip to content

Commit

Permalink
Add safe fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Sep 5, 2024
1 parent c7f6f20 commit 9995c3b
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,27 @@ class FlutterWebAuth2Plugin(
* 4. Installed Browser
*/
private fun findTargetBrowserPackageName(options: Map<String, Any>): String? {
val chromePackage = "com.android.chrome"

@Suppress("UNCHECKED_CAST")
val customTabsPackageOrder = (options["customTabsPackageOrder"] as Iterable<String>?) ?: emptyList()
//check target browser
// Check target browser
var targetPackage = customTabsPackageOrder.firstOrNull { isSupportCustomTabs(it) }
if (targetPackage != null) {
return targetPackage
}

//check default browser
// Check default browser
val defaultBrowserSupported = CustomTabsClient.getPackageName(context!!, emptyList<String>()) != null
if (defaultBrowserSupported) {
return null;
}
//check installed browser
// Check installed browser
val allBrowsers = getInstalledBrowsers()
targetPackage = allBrowsers.firstOrNull { isSupportCustomTabs(it) }

if (targetPackage == null) {
targetPackage = chromePackage
// Safely fall back on Chrome just in case
val chromePackage = "com.android.chrome"
if (targetPackage == null && isSupportCustomTabs(chromePackage)) {
return chromePackage
}
return targetPackage
}
Expand All @@ -127,7 +127,7 @@ class FlutterWebAuth2Plugin(
return@compareBy -1
}

//FireFox default is not enable ,must enable in the browser settings.
// Firefox default is not enabled, must enable in the browser settings.
if (setOf("org.mozilla.firefox").contains(it)) {
return@compareBy 1
}
Expand Down

0 comments on commit 9995c3b

Please sign in to comment.