use correct context/section for AddToAny

This commit is contained in:
Adam Velebil 2024-09-11 00:16:27 +02:00
parent 90cd67ac65
commit 3432835450
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
3 changed files with 38 additions and 4 deletions

View File

@ -232,7 +232,31 @@ class OathManager(
device.withConnection<SmartCardConnection, Unit> { connection ->
val session = getOathSession(connection)
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
if (pendingAction != null) {
pendingAction?.let { action ->
@ -686,6 +710,15 @@ class OathManager(
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?> {
val isUsbKey = deviceManager.isUsbKeyConnected()
var timestamp = System.currentTimeMillis()

View File

@ -76,9 +76,6 @@ class _AndroidOathStateNotifier extends OathStateNotifier {
@override
Future<void> reset() async {
try {
// await ref
// .read(androidAppContextHandler)
// .switchAppContext(Application.accounts);
await oath.invoke('reset');
} catch (e) {
_log.debug('Calling reset failed with exception: $e');

View File

@ -109,6 +109,10 @@ class MainPage extends ConsumerWidget {
label: Text(l10n.s_add_account),
icon: const Icon(Symbols.person_add_alt),
onPressed: () async {
// make sure we execute the "Add account" in OATH section
ref
.read(currentSectionProvider.notifier)
.setCurrentSection(Section.accounts);
await addOathAccount(context, ref);
})
],