mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 01:44:19 +01:00
fix remove app connect and website show connect dialog many times bug
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:nostr_sdk/signer/nostr_signer.dart';
|
||||
import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart';
|
||||
@@ -34,13 +36,9 @@ mixin PermissionCheckMixin {
|
||||
|
||||
var app = appProvider.getApp(appType, code);
|
||||
if (app == null) {
|
||||
// app is null, app connect
|
||||
var newApp = await getApp(appType, code);
|
||||
if (context != null) {
|
||||
await AuthAppConnectDialog.show(context, newApp);
|
||||
app = await connectToApp(appType, code, context);
|
||||
}
|
||||
// reload from provider
|
||||
app = appProvider.getApp(appType, code);
|
||||
}
|
||||
|
||||
if (app == null) {
|
||||
@@ -111,6 +109,30 @@ mixin PermissionCheckMixin {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Future<App?>> connectingAppFutureMap = {};
|
||||
|
||||
Future<App?> connectToApp(int appType, String code, BuildContext context) {
|
||||
var key = "$appType-$code";
|
||||
var f = connectingAppFutureMap[key];
|
||||
if (f != null) {
|
||||
return f;
|
||||
}
|
||||
|
||||
var complete = Completer<App?>();
|
||||
f = complete.future;
|
||||
connectingAppFutureMap[key] = f;
|
||||
|
||||
getApp(appType, code).then((newApp) => {
|
||||
AuthAppConnectDialog.show(context, newApp).then((value) {
|
||||
var app = appProvider.getApp(appType, code);
|
||||
complete.complete(app);
|
||||
connectingAppFutureMap.remove(key);
|
||||
})
|
||||
});
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
void saveAuthLog(App app, int authType, int? eventKind, String? authDetail,
|
||||
int authResult) {
|
||||
if (app.id != null) {
|
||||
|
||||
Reference in New Issue
Block a user