start implementing keycard onboarding flow

This commit is contained in:
Michele Balistreri 2021-09-29 16:23:28 +03:00 committed by Iuri Matias
parent 03c0a85aee
commit 7d8be3fc40
3 changed files with 49 additions and 22 deletions

View File

@ -1,5 +1,5 @@
import NimQml, chronicles, std/wrapnils import NimQml, chronicles, std/wrapnils
import status/status import status/[signals, status, keycard]
import view import view
type KeycardController* = ref object type KeycardController* = ref object
@ -20,5 +20,25 @@ proc delete*(self: KeycardController) =
proc reset*(self: KeycardController) = proc reset*(self: KeycardController) =
discard discard
proc attemptOpenSecureChannel(self: KeycardController): bool =
return false
proc getCardState(self: KeycardController) =
let appInfo = self.status.keycard.select()
self.view.appInfo = appInfo
if not appInfo.installed:
self.view.cardState = NotKeycard
elif not appInfo.initialized:
self.view.cardState = PreInit
elif self.attemptOpenSecureChannel():
self.view.cardState = Paired
else:
self.view.cardState = Unpaired
proc init*(self: KeycardController) = proc init*(self: KeycardController) =
discard discard """
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
getCardState()
self.view.cardConnected()
"""

View File

@ -1,13 +1,26 @@
import NimQml, chronicles import NimQml, chronicles
import status/status import status/[status, keycard]
import status/keycard import status/types/keycard as keycardtypes
logScope: logScope:
topics = "keycard-model" topics = "keycard-model"
type
CardState* {.pure.} = enum
Disconnected = 0
NotKeycard = 1
PreInit = 2
Unpaired = 3
Paired = 4
Frozen = 5
Blocked = 6
Authenticated = 7
QtObject: QtObject:
type KeycardView* = ref object of QObject type KeycardView* = ref object of QObject
status*: Status status*: Status
cardState*: CardState
appInfo*: KeycardApplicationInfo
proc setup(self: KeycardView) = proc setup(self: KeycardView) =
self.QObject.setup self.QObject.setup
@ -24,13 +37,15 @@ QtObject:
proc cardDisconnected*(self: KeycardView) {.signal.} proc cardDisconnected*(self: KeycardView) {.signal.}
proc simulateDisconnected*(self: KeycardView) {.slot.} = proc cardStateChanged*(self: KeycardView, cardState: int) {.signal.}
self.cardDisconnected()
proc simulateConnected*(self: KeycardView) {.slot.} = proc startConnection*(self: KeycardView) {.slot.} =
self.cardConnected() discard self.status.keycard.start()
proc testConnection*(self: KeycardView) {.slot.} = proc stopConnection*(self: KeycardView) {.slot.} =
info "Connecting Keycard ", msg = self.status.keycard.start() self.cardState = Disconnected
info "Selecting Keycard", msg = self.status.keycard.select().instanceUID discard self.status.keycard.stop()
info "Disconnecting Keycard ", msg = self.status.keycard.stop()
proc `cardState=`*(self: KeycardView, cardState: CardState) =
self.cardState = cardState
self.cardStateChanged(int(cardState))

View File

@ -10,16 +10,8 @@ Item {
id: keycardView id: keycardView
anchors.fill: parent anchors.fill: parent
Component.onCompleted: { Component.onCompleted: {
keycardModel.testConnection() insertCard.open()
createPinModal.open() keycardModel.startConnection()
}
Timer {
interval: 2000; running: true; repeat: true
onTriggered: {
connected? keycardModel.simulateDisconnected() : keycardModel.simulateConnected()
connected = !connected
}
} }
CreatePINModal { CreatePINModal {