YADESK-699 correct data in acc dlg after rename

This commit is contained in:
Adam Velebil 2022-06-10 08:37:31 +02:00
parent 885e13626d
commit 6d5931956c
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
6 changed files with 96 additions and 36 deletions

View File

@ -590,16 +590,23 @@ public class Pigeon {
return FDialogApiCodec.INSTANCE;
}
public void showDialogApi(@NonNull String dialogMessageArg, Reply<Void> callback) {
public void showDialog(@NonNull String dialogMessageArg, Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.showDialogApi", getCodec());
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.showDialog", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(dialogMessageArg)), channelReply -> {
callback.reply(null);
});
}
public void closeDialogApi(Reply<Void> callback) {
public void updateDialogState(@Nullable String titleArg, @Nullable String descriptionArg, @Nullable String iconArg, Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.closeDialogApi", getCodec());
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.updateDialogState", getCodec());
channel.send(new ArrayList<Object>(Arrays.asList(titleArg, descriptionArg, iconArg)), channelReply -> {
callback.reply(null);
});
}
public void closeDialog(Reply<Void> callback) {
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(binaryMessenger, "dev.flutter.pigeon.FDialogApi.closeDialog", getCodec());
channel.send(null, channelReply -> {
callback.reply(null);
});

View File

@ -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<Boolean> { 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()
}

View File

@ -557,6 +557,12 @@ class OathManager(
private fun <T> returnSuccess(result: Result<T>, 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 <T> returnError(result: Result<T>, error: Throwable) {
coroutineScope.launch(Dispatchers.Main) {
if (!_isUsbKey) {
dialogManager.updateDialogState(
title = "Action complete",
description = "Failure",
icon = "error",
delayMs = 500
)
dialogManager.closeDialog {
result.error(error)
}

View File

@ -428,34 +428,52 @@ class _FDialogApiCodec extends StandardMessageCodec {
abstract class FDialogApi {
static const MessageCodec<Object?> codec = _FDialogApiCodec();
Future<void> showDialogApi(String dialogMessage);
Future<void> closeDialogApi();
Future<void> showDialog(String dialogMessage);
void updateDialogState(String? title, String? description, String? icon);
void closeDialog();
static void setup(FDialogApi? api, {BinaryMessenger? binaryMessenger}) {
{
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
'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<Object?> args = (message as List<Object?>?)!;
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<Object?> channel = BasicMessageChannel<Object?>(
'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<Object?> args = (message as List<Object?>?)!;
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<Object?> channel = BasicMessageChannel<Object?>(
'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;
});
}

View File

@ -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<void> 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<void> showDialogApi(String dialogMessage) async {
Future<void> 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<void> showDialog(String dialogMessage) async {
_controller = await _withContext((context) async => promptUserInteraction(
context,
title: 'Tap your key',

View File

@ -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()