From 6d5931956c0e4b23415661c98cf908b9b0942d10 Mon Sep 17 00:00:00 2001 From: Adam Velebil Date: Fri, 10 Jun 2022 08:37:31 +0200 Subject: [PATCH] YADESK-699 correct data in acc dlg after rename --- .../com/yubico/authenticator/api/Pigeon.java | 15 +++++-- .../com/yubico/authenticator/DialogManager.kt | 23 ++++++++--- .../yubico/authenticator/oath/OathManager.kt | 12 ++++++ lib/android/api/impl.dart | 34 +++++++++++---- lib/android/views/tap_request_dialog.dart | 41 +++++++++++-------- pigeons/api.dart | 7 ++-- 6 files changed, 96 insertions(+), 36 deletions(-) diff --git a/android/app/src/main/java/com/yubico/authenticator/api/Pigeon.java b/android/app/src/main/java/com/yubico/authenticator/api/Pigeon.java index b718a4ed..737d7a9b 100644 --- a/android/app/src/main/java/com/yubico/authenticator/api/Pigeon.java +++ b/android/app/src/main/java/com/yubico/authenticator/api/Pigeon.java @@ -590,16 +590,23 @@ public class Pigeon { return FDialogApiCodec.INSTANCE; } - public void showDialogApi(@NonNull String dialogMessageArg, Reply callback) { + public void showDialog(@NonNull String dialogMessageArg, Reply callback) { BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.showDialogApi", getCodec()); + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.showDialog", getCodec()); channel.send(new ArrayList(Arrays.asList(dialogMessageArg)), channelReply -> { callback.reply(null); }); } - public void closeDialogApi(Reply callback) { + public void updateDialogState(@Nullable String titleArg, @Nullable String descriptionArg, @Nullable String iconArg, Reply callback) { BasicMessageChannel channel = - new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.closeDialogApi", getCodec()); + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.updateDialogState", getCodec()); + channel.send(new ArrayList(Arrays.asList(titleArg, descriptionArg, iconArg)), channelReply -> { + callback.reply(null); + }); + } + public void closeDialog(Reply callback) { + BasicMessageChannel channel = + new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.closeDialog", getCodec()); channel.send(null, channelReply -> { callback.reply(null); }); diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/DialogManager.kt b/android/app/src/main/kotlin/com/yubico/authenticator/DialogManager.kt index 95557450..a80a2c1e 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/DialogManager.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/DialogManager.kt @@ -3,9 +3,9 @@ package com.yubico.authenticator import com.yubico.authenticator.api.Pigeon.* import com.yubico.authenticator.logging.Log import io.flutter.plugin.common.BinaryMessenger -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch +import kotlinx.coroutines.* +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine typealias OnDialogClosed = () -> Unit typealias OnDialogCancelled = () -> Unit @@ -23,13 +23,26 @@ class DialogManager(messenger: BinaryMessenger, private var coroutineScope: Coro fun showDialog(message: String, cancelled: OnDialogCancelled?) = coroutineScope.launch(Dispatchers.Main) { - _fDialogApi.showDialogApi(message) { } + _fDialogApi.showDialog(message) { } }.also { onCancelled = cancelled } + suspend fun updateDialogState(title: String? = null, description: String? = null, icon: String? = null, delayMs: Long? = null) { + withContext(Dispatchers.Main) { + suspendCoroutine { continuation -> + _fDialogApi.updateDialogState(title, description, icon) { + continuation.resume(true) + } + } + if (delayMs != null) { + delay(delayMs) + } + } + } + fun closeDialog(onClosed: OnDialogClosed) { - _fDialogApi.closeDialogApi { + _fDialogApi.closeDialog { coroutineScope.launch(Dispatchers.Main) { onClosed() } diff --git a/android/app/src/main/kotlin/com/yubico/authenticator/oath/OathManager.kt b/android/app/src/main/kotlin/com/yubico/authenticator/oath/OathManager.kt index 65ccb058..9297835f 100644 --- a/android/app/src/main/kotlin/com/yubico/authenticator/oath/OathManager.kt +++ b/android/app/src/main/kotlin/com/yubico/authenticator/oath/OathManager.kt @@ -557,6 +557,12 @@ class OathManager( private fun returnSuccess(result: Result, data: T? = null) { coroutineScope.launch(Dispatchers.Main) { if (!_isUsbKey) { + dialogManager.updateDialogState( + title = "Action complete", + description = "Success", + icon = "check_circle", + delayMs = 500 + ) dialogManager.closeDialog { result.success(data) } @@ -571,6 +577,12 @@ class OathManager( private fun returnError(result: Result, error: Throwable) { coroutineScope.launch(Dispatchers.Main) { if (!_isUsbKey) { + dialogManager.updateDialogState( + title = "Action complete", + description = "Failure", + icon = "error", + delayMs = 500 + ) dialogManager.closeDialog { result.error(error) } diff --git a/lib/android/api/impl.dart b/lib/android/api/impl.dart index 2f90c170..afe93e00 100644 --- a/lib/android/api/impl.dart +++ b/lib/android/api/impl.dart @@ -428,34 +428,52 @@ class _FDialogApiCodec extends StandardMessageCodec { abstract class FDialogApi { static const MessageCodec codec = _FDialogApiCodec(); - Future showDialogApi(String dialogMessage); - Future closeDialogApi(); + Future showDialog(String dialogMessage); + void updateDialogState(String? title, String? description, String? icon); + void closeDialog(); static void setup(FDialogApi? api, {BinaryMessenger? binaryMessenger}) { { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FDialogApi.showDialogApi', codec, binaryMessenger: binaryMessenger); + 'dev.flutter.pigeon.FDialogApi.showDialog', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMessageHandler(null); } else { channel.setMessageHandler((Object? message) async { - assert(message != null, 'Argument for dev.flutter.pigeon.FDialogApi.showDialogApi was null.'); + assert(message != null, 'Argument for dev.flutter.pigeon.FDialogApi.showDialog was null.'); final List args = (message as List?)!; final String? arg_dialogMessage = (args[0] as String?); - assert(arg_dialogMessage != null, 'Argument for dev.flutter.pigeon.FDialogApi.showDialogApi was null, expected non-null String.'); - await api.showDialogApi(arg_dialogMessage!); + assert(arg_dialogMessage != null, 'Argument for dev.flutter.pigeon.FDialogApi.showDialog was null, expected non-null String.'); + await api.showDialog(arg_dialogMessage!); return; }); } } { final BasicMessageChannel channel = BasicMessageChannel( - 'dev.flutter.pigeon.FDialogApi.closeDialogApi', codec, binaryMessenger: binaryMessenger); + 'dev.flutter.pigeon.FDialogApi.updateDialogState', codec, binaryMessenger: binaryMessenger); + if (api == null) { + channel.setMessageHandler(null); + } else { + channel.setMessageHandler((Object? message) async { + assert(message != null, 'Argument for dev.flutter.pigeon.FDialogApi.updateDialogState was null.'); + final List args = (message as List?)!; + final String? arg_title = (args[0] as String?); + final String? arg_description = (args[1] as String?); + final String? arg_icon = (args[2] as String?); + api.updateDialogState(arg_title, arg_description, arg_icon); + return; + }); + } + } + { + final BasicMessageChannel channel = BasicMessageChannel( + 'dev.flutter.pigeon.FDialogApi.closeDialog', codec, binaryMessenger: binaryMessenger); if (api == null) { channel.setMessageHandler(null); } else { channel.setMessageHandler((Object? message) async { // ignore message - await api.closeDialogApi(); + api.closeDialog(); return; }); } diff --git a/lib/android/views/tap_request_dialog.dart b/lib/android/views/tap_request_dialog.dart index 97ed0009..b9a366c5 100755 --- a/lib/android/views/tap_request_dialog.dart +++ b/lib/android/views/tap_request_dialog.dart @@ -2,35 +2,44 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import '../../app/views/user_interaction.dart'; import '../../app/state.dart'; +import '../../app/views/user_interaction.dart'; import '../../widgets/custom_icons.dart'; import '../api/impl.dart'; class FDialogApiImpl extends FDialogApi { final WithContext _withContext; UserInteractionController? _controller; + FDialogApiImpl(this._withContext); @override - Future closeDialogApi() async { - if (_controller != null) { - _controller?.updateContent( - description: 'Success', - icon: const Icon( - Icons.check_circle, - size: 64, - ), - ); - Timer(const Duration(seconds: 1), () { - _controller?.close(); - _controller = null; - }); - } + void closeDialog() { + _controller?.close(); + _controller = null; } @override - Future showDialogApi(String dialogMessage) async { + Future updateDialogState( + String? title, String? description, String? icon) async { + final iconResource = icon == 'check_circle' + ? Icons.check_circle + : icon == 'error' + ? Icons.error + : null; + final dialogIcon = Icon( + iconResource, + size: 64, + ); + _controller?.updateContent( + title: title, + description: description, + icon: dialogIcon, + ); + } + + @override + Future showDialog(String dialogMessage) async { _controller = await _withContext((context) async => promptUserInteraction( context, title: 'Tap your key', diff --git a/pigeons/api.dart b/pigeons/api.dart index c21ef499..077d94c9 100644 --- a/pigeons/api.dart +++ b/pigeons/api.dart @@ -62,10 +62,11 @@ abstract class FManagementApi { @FlutterApi() abstract class FDialogApi { @async - void showDialogApi(String dialogMessage); + void showDialog(String dialogMessage); - @async - void closeDialogApi(); + void updateDialogState(String? title, String? description, String? icon); + + void closeDialog(); } @HostApi()