mirror of
https://github.com/haorendashu/nowser.git
synced 2025-12-17 01:44:19 +01:00
android signer add get code by currentUser
This commit is contained in:
@@ -5,6 +5,7 @@ import 'dart:developer';
|
||||
import 'package:android_content_provider/android_content_provider.dart';
|
||||
import 'package:nostr_sdk/event.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19.dart';
|
||||
import 'package:nostr_sdk/nip19/nip19_tlv.dart';
|
||||
import 'package:nostr_sdk/signer/nostr_signer.dart';
|
||||
import 'package:nostr_sdk/utils/string_util.dart';
|
||||
import 'package:nostr_sdk/zap/private_zap.dart';
|
||||
@@ -60,6 +61,11 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
currentUser = projection[2];
|
||||
}
|
||||
}
|
||||
if (StringUtil.isNotBlank(currentUser)) {
|
||||
if (Nip19.isPubkey(currentUser!)) {
|
||||
currentUser = Nip19.decode(currentUser);
|
||||
}
|
||||
}
|
||||
|
||||
var authType = AuthType.GET_PUBLIC_KEY;
|
||||
if (authTypeStr == "GET_PUBLIC_KEY") {
|
||||
@@ -82,6 +88,15 @@ class AndroidSignerContentResolverProvider extends AndroidContentProvider
|
||||
|
||||
int appType = AppType.ANDROID_APP;
|
||||
var code = await getCallingPackage();
|
||||
if (StringUtil.isBlank(code)) {
|
||||
if (currentUser != null) {
|
||||
// code is null, but currentUser is not null, try to find currentUser depend on currentUser
|
||||
var app = appProvider.getAppByUser(appType, currentUser);
|
||||
if (app != null) {
|
||||
code = app.code;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtil.isBlank(code)) {
|
||||
print("get calling package fail!");
|
||||
return null;
|
||||
|
||||
@@ -135,6 +135,23 @@ class AppProvider extends ChangeNotifier {
|
||||
return _appMap[appId];
|
||||
}
|
||||
|
||||
// try to find app depend on pubkey.
|
||||
App? getAppByUser(int appType, String pubkey) {
|
||||
List<App> findedList = [];
|
||||
|
||||
for (var app in _list) {
|
||||
if (app.appType == appType && app.pubkey == pubkey) {
|
||||
findedList.add(app);
|
||||
}
|
||||
}
|
||||
|
||||
if (findedList.length == 1) {
|
||||
return findedList.first;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
App? getApp(int appType, String code) {
|
||||
for (var app in _list) {
|
||||
if (app.appType == appType && app.code == code) {
|
||||
|
||||
Reference in New Issue
Block a user