start implementing keycard onboarding flow
This commit is contained in:
parent
03c0a85aee
commit
7d8be3fc40
|
@ -1,5 +1,5 @@
|
|||
import NimQml, chronicles, std/wrapnils
|
||||
import status/status
|
||||
import status/[signals, status, keycard]
|
||||
import view
|
||||
|
||||
type KeycardController* = ref object
|
||||
|
@ -20,5 +20,25 @@ proc delete*(self: KeycardController) =
|
|||
proc reset*(self: KeycardController) =
|
||||
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) =
|
||||
discard
|
||||
discard """
|
||||
self.status.events.on(SignalType.KeycardConnected.event) do(e:Args):
|
||||
getCardState()
|
||||
self.view.cardConnected()
|
||||
"""
|
|
@ -1,13 +1,26 @@
|
|||
import NimQml, chronicles
|
||||
import status/status
|
||||
import status/keycard
|
||||
import status/[status, keycard]
|
||||
import status/types/keycard as keycardtypes
|
||||
|
||||
logScope:
|
||||
topics = "keycard-model"
|
||||
|
||||
type
|
||||
CardState* {.pure.} = enum
|
||||
Disconnected = 0
|
||||
NotKeycard = 1
|
||||
PreInit = 2
|
||||
Unpaired = 3
|
||||
Paired = 4
|
||||
Frozen = 5
|
||||
Blocked = 6
|
||||
Authenticated = 7
|
||||
|
||||
QtObject:
|
||||
type KeycardView* = ref object of QObject
|
||||
status*: Status
|
||||
cardState*: CardState
|
||||
appInfo*: KeycardApplicationInfo
|
||||
|
||||
proc setup(self: KeycardView) =
|
||||
self.QObject.setup
|
||||
|
@ -24,13 +37,15 @@ QtObject:
|
|||
|
||||
proc cardDisconnected*(self: KeycardView) {.signal.}
|
||||
|
||||
proc simulateDisconnected*(self: KeycardView) {.slot.} =
|
||||
self.cardDisconnected()
|
||||
proc cardStateChanged*(self: KeycardView, cardState: int) {.signal.}
|
||||
|
||||
proc simulateConnected*(self: KeycardView) {.slot.} =
|
||||
self.cardConnected()
|
||||
proc startConnection*(self: KeycardView) {.slot.} =
|
||||
discard self.status.keycard.start()
|
||||
|
||||
proc testConnection*(self: KeycardView) {.slot.} =
|
||||
info "Connecting Keycard ", msg = self.status.keycard.start()
|
||||
info "Selecting Keycard", msg = self.status.keycard.select().instanceUID
|
||||
info "Disconnecting Keycard ", msg = self.status.keycard.stop()
|
||||
proc stopConnection*(self: KeycardView) {.slot.} =
|
||||
self.cardState = Disconnected
|
||||
discard self.status.keycard.stop()
|
||||
|
||||
proc `cardState=`*(self: KeycardView, cardState: CardState) =
|
||||
self.cardState = cardState
|
||||
self.cardStateChanged(int(cardState))
|
|
@ -10,16 +10,8 @@ Item {
|
|||
id: keycardView
|
||||
anchors.fill: parent
|
||||
Component.onCompleted: {
|
||||
keycardModel.testConnection()
|
||||
createPinModal.open()
|
||||
}
|
||||
|
||||
Timer {
|
||||
interval: 2000; running: true; repeat: true
|
||||
onTriggered: {
|
||||
connected? keycardModel.simulateDisconnected() : keycardModel.simulateConnected()
|
||||
connected = !connected
|
||||
}
|
||||
insertCard.open()
|
||||
keycardModel.startConnection()
|
||||
}
|
||||
|
||||
CreatePINModal {
|
||||
|
|
Loading…
Reference in New Issue