From 92474a56f7ebbc66eefcdd24690526a933a13135 Mon Sep 17 00:00:00 2001 From: Valk Dokk Date: Tue, 25 Feb 2025 11:38:59 +0700 Subject: [PATCH 1/4] update flutter api --- .fvmrc | 3 + .gitignore | 3 + .../flutter_web_auth/FlutterWebAuthPlugin.kt | 96 ++++++++----------- 3 files changed, 48 insertions(+), 54 deletions(-) create mode 100644 .fvmrc diff --git a/.fvmrc b/.fvmrc new file mode 100644 index 00000000..4cfa3d5f --- /dev/null +++ b/.fvmrc @@ -0,0 +1,3 @@ +{ + "flutter": "3.29.0" +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index ac5aa989..a920017b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ migrate_working_dir/ **/doc/api/ .dart_tool/ build/ + +# FVM Version Cache +.fvm/ \ No newline at end of file diff --git a/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt b/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt index b1c3d073..f0b0f943 100644 --- a/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt +++ b/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt @@ -3,72 +3,60 @@ package com.linusu.flutter_web_auth import android.content.Context import android.content.Intent import android.net.Uri - import androidx.browser.customtabs.CustomTabsIntent - import io.flutter.embedding.engine.plugins.FlutterPlugin -import io.flutter.plugin.common.BinaryMessenger import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import io.flutter.plugin.common.PluginRegistry.Registrar -class FlutterWebAuthPlugin(private var context: Context? = null, private var channel: MethodChannel? = null): MethodCallHandler, FlutterPlugin { - companion object { - val callbacks = mutableMapOf() +class FlutterWebAuthPlugin : MethodCallHandler, FlutterPlugin { + private var context: Context? = null + private lateinit var channel: MethodChannel - @JvmStatic - fun registerWith(registrar: Registrar) { - val plugin = FlutterWebAuthPlugin() - plugin.initInstance(registrar.messenger(), registrar.context()) + companion object { + val callbacks = mutableMapOf() } - } - - fun initInstance(messenger: BinaryMessenger, context: Context) { - this.context = context - channel = MethodChannel(messenger, "flutter_web_auth") - channel?.setMethodCallHandler(this) - } - - override public fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { - initInstance(binding.getBinaryMessenger(), binding.getApplicationContext()) - } - - override public fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { - context = null - channel = null - } - - override fun onMethodCall(call: MethodCall, resultCallback: Result) { - when (call.method) { - "authenticate" -> { - val url = Uri.parse(call.argument("url")) - val callbackUrlScheme = call.argument("callbackUrlScheme")!! - val preferEphemeral = call.argument("preferEphemeral")!! - - callbacks[callbackUrlScheme] = resultCallback - - val intent = CustomTabsIntent.Builder().build() - val keepAliveIntent = Intent(context, KeepAliveService::class.java) + override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) { + context = binding.applicationContext + channel = MethodChannel(binding.binaryMessenger, "flutter_web_auth") + channel.setMethodCallHandler(this) + } - intent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) - if (preferEphemeral) { - intent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) - } - intent.intent.putExtra("android.support.customtabs.extra.KEEP_ALIVE", keepAliveIntent) + override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { + channel.setMethodCallHandler(null) + context = null + } - intent.launchUrl(context!!, url) - } - "cleanUpDanglingCalls" -> { - callbacks.forEach{ (_, danglingResultCallback) -> - danglingResultCallback.error("CANCELED", "User canceled login", null) - } - callbacks.clear() - resultCallback.success(null) + override fun onMethodCall(call: MethodCall, resultCallback: Result) { + when (call.method) { + "authenticate" -> { + val url = Uri.parse(call.argument("url")) + val callbackUrlScheme = call.argument("callbackUrlScheme")!! + val preferEphemeral = call.argument("preferEphemeral") ?: false + + callbacks[callbackUrlScheme] = resultCallback + + val intent = CustomTabsIntent.Builder().build() + val keepAliveIntent = Intent(context, KeepAliveService::class.java) + + intent.intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK) + if (preferEphemeral) { + intent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) + } + intent.intent.putExtra("android.support.customtabs.extra.KEEP_ALIVE", keepAliveIntent) + + intent.launchUrl(context!!, url) + } + "cleanUpDanglingCalls" -> { + callbacks.forEach { (_, danglingResultCallback) -> + danglingResultCallback.error("CANCELED", "User canceled login", null) + } + callbacks.clear() + resultCallback.success(null) + } + else -> resultCallback.notImplemented() } - else -> resultCallback.notImplemented() } - } } From 20e70d6ca90fe1a2afa99fc26ec08aac248968b8 Mon Sep 17 00:00:00 2001 From: Valk Dokk Date: Tue, 25 Feb 2025 11:41:04 +0700 Subject: [PATCH 2/4] remove fvm --- .fvmrc | 3 --- .gitignore | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 .fvmrc diff --git a/.fvmrc b/.fvmrc deleted file mode 100644 index 4cfa3d5f..00000000 --- a/.fvmrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "flutter": "3.29.0" -} \ No newline at end of file diff --git a/.gitignore b/.gitignore index a920017b..ac5aa989 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,3 @@ migrate_working_dir/ **/doc/api/ .dart_tool/ build/ - -# FVM Version Cache -.fvm/ \ No newline at end of file From 12c1e250abbebdbe0092469e93f5cb2213bea566 Mon Sep 17 00:00:00 2001 From: Valk Dokk Date: Tue, 25 Feb 2025 11:47:57 +0700 Subject: [PATCH 3/4] bump version --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6a9925cc..ee0d0acd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_web_auth description: Flutter plugin for authenticating a user with a web service. -version: 0.6.0 +version: 0.7.0 homepage: https://github.com/LinusU/flutter_web_auth environment: From afcfe16b69b7479659498834bbc4370fc77036f5 Mon Sep 17 00:00:00 2001 From: Valk Dokk Date: Mon, 5 May 2025 08:23:33 +0700 Subject: [PATCH 4/4] set channel to null onDetachedFromEngine --- .../kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt b/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt index f0b0f943..0bdc1a93 100644 --- a/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt +++ b/android/src/main/kotlin/com/linusu/flutter_web_auth/FlutterWebAuthPlugin.kt @@ -26,6 +26,7 @@ class FlutterWebAuthPlugin : MethodCallHandler, FlutterPlugin { override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) { channel.setMethodCallHandler(null) + channel = null as MethodChannel context = null }