mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 09:54: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:flutter/material.dart';
|
||||||
import 'package:nostr_sdk/signer/nostr_signer.dart';
|
import 'package:nostr_sdk/signer/nostr_signer.dart';
|
||||||
import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart';
|
import 'package:nowser/component/auth_dialog/auth_app_connect_dialog.dart';
|
||||||
@@ -34,13 +36,9 @@ mixin PermissionCheckMixin {
|
|||||||
|
|
||||||
var app = appProvider.getApp(appType, code);
|
var app = appProvider.getApp(appType, code);
|
||||||
if (app == null) {
|
if (app == null) {
|
||||||
// app is null, app connect
|
|
||||||
var newApp = await getApp(appType, code);
|
|
||||||
if (context != null) {
|
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) {
|
if (app == null) {
|
||||||
@@ -111,6 +109,30 @@ mixin PermissionCheckMixin {
|
|||||||
return;
|
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,
|
void saveAuthLog(App app, int authType, int? eventKind, String? authDetail,
|
||||||
int authResult) {
|
int authResult) {
|
||||||
if (app.id != null) {
|
if (app.id != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user