From 9995c3b803fb289034cd274e27d6fd2c8e064afd Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Thu, 5 Sep 2024 10:04:35 +0200 Subject: [PATCH] Add safe fallback --- .../flutter_web_auth_2/FlutterWebAuth2Plugin.kt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/flutter_web_auth_2/android/src/main/kotlin/com/linusu/flutter_web_auth_2/FlutterWebAuth2Plugin.kt b/flutter_web_auth_2/android/src/main/kotlin/com/linusu/flutter_web_auth_2/FlutterWebAuth2Plugin.kt index 8687fc4..e8d62be 100644 --- a/flutter_web_auth_2/android/src/main/kotlin/com/linusu/flutter_web_auth_2/FlutterWebAuth2Plugin.kt +++ b/flutter_web_auth_2/android/src/main/kotlin/com/linusu/flutter_web_auth_2/FlutterWebAuth2Plugin.kt @@ -81,27 +81,27 @@ class FlutterWebAuth2Plugin( * 4. Installed Browser */ private fun findTargetBrowserPackageName(options: Map): String? { - val chromePackage = "com.android.chrome" - @Suppress("UNCHECKED_CAST") val customTabsPackageOrder = (options["customTabsPackageOrder"] as Iterable?) ?: 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()) != 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 } @@ -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 }