implement pairing storage
This commit is contained in:
parent
899c342414
commit
5cf58a78e5
|
@ -1,6 +1,6 @@
|
|||
import NimQml, chronicles, std/wrapnils
|
||||
import status/[signals, status, keycard]
|
||||
import view
|
||||
import view, pairing
|
||||
|
||||
logScope:
|
||||
topics = "keycard-model"
|
||||
|
@ -24,6 +24,12 @@ proc reset*(self: KeycardController) =
|
|||
discard
|
||||
|
||||
proc attemptOpenSecureChannel(self: KeycardController) : bool =
|
||||
let pairing = self.view.pairings.getPairing(self.view.appInfo.instanceUID)
|
||||
|
||||
if pairing == "":
|
||||
return false
|
||||
|
||||
# actually open secure channel
|
||||
return false
|
||||
|
||||
proc getCardState(self: KeycardController) =
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
import json, os, std/wrapnils
|
||||
|
||||
import ../../constants
|
||||
|
||||
let PAIRINGSTORE = joinPath(DATADIR, "keycard-pairings.json")
|
||||
|
||||
type KeycardPairingController* = ref object
|
||||
store: JsonNode
|
||||
|
||||
proc newPairingController*(): KeycardPairingController =
|
||||
result = KeycardPairingController()
|
||||
if fileExists(PAIRINGSTORE):
|
||||
result.store = parseJSON(readFile(PAIRINGSTORE))
|
||||
else:
|
||||
result.store = %*{}
|
||||
|
||||
proc save(self: KeycardPairingController) =
|
||||
writeFile(PAIRINGSTORE, $self.store)
|
||||
|
||||
proc addPairing*(self: KeycardPairingController, instanceUID: string, pairing: string) =
|
||||
self.store[instanceUID] = %* pairing
|
||||
self.save()
|
||||
|
||||
proc removePairing*(self: KeycardPairingController, instanceUID: string) =
|
||||
self.store.delete(instanceUID)
|
||||
self.save()
|
||||
|
||||
proc getPairing*(self: KeycardPairingController, instanceUID: string): string =
|
||||
let node = self.store{instanceUID}
|
||||
return ?.node.getStr()
|
|
@ -1,6 +1,7 @@
|
|||
import NimQml, chronicles
|
||||
import status/[status, keycard]
|
||||
import status/types/keycard as keycardtypes
|
||||
import pairing
|
||||
|
||||
logScope:
|
||||
topics = "keycard-model"
|
||||
|
@ -20,6 +21,7 @@ type
|
|||
QtObject:
|
||||
type KeycardView* = ref object of QObject
|
||||
status*: Status
|
||||
pairings*: KeycardPairingController
|
||||
cardState*: CardState
|
||||
appInfo*: KeycardApplicationInfo
|
||||
|
||||
|
@ -32,6 +34,7 @@ QtObject:
|
|||
proc newKeycardView*(status: Status): KeycardView =
|
||||
new(result, delete)
|
||||
result.status = status
|
||||
result.pairings = newPairingController()
|
||||
result.setup
|
||||
|
||||
proc cardConnected*(self: KeycardView) {.signal.}
|
||||
|
|
Loading…
Reference in New Issue