mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-22 00:12:09 +03:00
use correct context/section for AddToAny
This commit is contained in:
parent
90cd67ac65
commit
3432835450
@ -232,7 +232,31 @@ class OathManager(
|
|||||||
device.withConnection<SmartCardConnection, Unit> { connection ->
|
device.withConnection<SmartCardConnection, Unit> { connection ->
|
||||||
val session = getOathSession(connection)
|
val session = getOathSession(connection)
|
||||||
val previousId = oathViewModel.currentSession()?.deviceId
|
val previousId = oathViewModel.currentSession()?.deviceId
|
||||||
if (session.deviceId == previousId && device is NfcYubiKeyDevice) {
|
// only run pending action over NFC
|
||||||
|
// when the device is still the same
|
||||||
|
// or when there is no previous device, but we have a pending action
|
||||||
|
if (device is NfcYubiKeyDevice &&
|
||||||
|
((session.deviceId == previousId) ||
|
||||||
|
(previousId == null && pendingAction != null))
|
||||||
|
) {
|
||||||
|
// update session if it is null
|
||||||
|
if (previousId == null) {
|
||||||
|
oathViewModel.setSessionState(
|
||||||
|
Session(
|
||||||
|
session,
|
||||||
|
keyManager.isRemembered(session.deviceId)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!session.isLocked) {
|
||||||
|
try {
|
||||||
|
// only load the accounts without calculating the codes
|
||||||
|
oathViewModel.updateCredentials(getAccounts(session))
|
||||||
|
} catch (e: IOException) {
|
||||||
|
oathViewModel.updateCredentials(emptyMap())
|
||||||
|
} }
|
||||||
|
}
|
||||||
|
|
||||||
// Either run a pending action, or just refresh codes
|
// Either run a pending action, or just refresh codes
|
||||||
if (pendingAction != null) {
|
if (pendingAction != null) {
|
||||||
pendingAction?.let { action ->
|
pendingAction?.let { action ->
|
||||||
@ -686,6 +710,15 @@ class OathManager(
|
|||||||
return session
|
return session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getAccounts(session: YubiKitOathSession): Map<Credential, Code?> {
|
||||||
|
return session.credentials.map { credential ->
|
||||||
|
Pair(
|
||||||
|
Credential(credential, session.deviceId),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
}.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
private fun calculateOathCodes(session: YubiKitOathSession): Map<Credential, Code?> {
|
private fun calculateOathCodes(session: YubiKitOathSession): Map<Credential, Code?> {
|
||||||
val isUsbKey = deviceManager.isUsbKeyConnected()
|
val isUsbKey = deviceManager.isUsbKeyConnected()
|
||||||
var timestamp = System.currentTimeMillis()
|
var timestamp = System.currentTimeMillis()
|
||||||
|
@ -76,9 +76,6 @@ class _AndroidOathStateNotifier extends OathStateNotifier {
|
|||||||
@override
|
@override
|
||||||
Future<void> reset() async {
|
Future<void> reset() async {
|
||||||
try {
|
try {
|
||||||
// await ref
|
|
||||||
// .read(androidAppContextHandler)
|
|
||||||
// .switchAppContext(Application.accounts);
|
|
||||||
await oath.invoke('reset');
|
await oath.invoke('reset');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_log.debug('Calling reset failed with exception: $e');
|
_log.debug('Calling reset failed with exception: $e');
|
||||||
|
@ -109,6 +109,10 @@ class MainPage extends ConsumerWidget {
|
|||||||
label: Text(l10n.s_add_account),
|
label: Text(l10n.s_add_account),
|
||||||
icon: const Icon(Symbols.person_add_alt),
|
icon: const Icon(Symbols.person_add_alt),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
// make sure we execute the "Add account" in OATH section
|
||||||
|
ref
|
||||||
|
.read(currentSectionProvider.notifier)
|
||||||
|
.setCurrentSection(Section.accounts);
|
||||||
await addOathAccount(context, ref);
|
await addOathAccount(context, ref);
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user