Skip to content

Commit

Permalink
fix(Pairing): Added installation info to pairing results (#10418)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-sirotin authored Apr 29, 2023
1 parent e1c9f2f commit abf58b0
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 54 deletions.
25 changes: 17 additions & 8 deletions src/app/core/signals/remote_signals/pairing.nim
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import json, tables
import base
import ../../../../app_service/service/accounts/dto/accounts

import ../../../../app_service/service/devices/dto/installation
import ../../../../app_service/service/devices/dto/local_pairing_event


type LocalPairingSignal* = ref object of Signal
eventType*: string
action*: int
eventType*: EventType
action*: Action
error*: string
account*: AccountDto
installation*: InstallationDto

proc fromEvent*(T: type LocalPairingSignal, event: JsonNode): LocalPairingSignal =
result = LocalPairingSignal()
let e = event["event"]
if e.contains("type"):
result.eventType = e["type"].getStr
result.eventType = e["type"].getStr().parse()
if e.contains("action"):
result.action = e["action"].getInt
result.action = e["action"].getInt().parse()
if e.contains("error"):
result.error = e["error"].getStr
if e.contains("data"):
result.account = e["data"].toAccountDto()
result.error = e["error"].getStr()
if not e.contains("data"):
return
case result.eventType:
of EventReceivedAccount:
result.account = e["data"].toAccountDto()
of EventReceivedInstallation:
result.installation = e["data"].toInstallationDto()
else:
discard
18 changes: 18 additions & 0 deletions src/app/modules/main/profile_section/devices/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ QtObject:
proc onLocalPairingEvent*(self: View, eventType: EventType, action: Action, error: string) =
self.localPairingEvent(ord(eventType), ord(action), error)

proc getLocalPairingInstallationId*(self: View): string {.slot.} =
return self.localPairingStatus.installation.id
QtProperty[string] localPairingInstallationId:
read = getLocalPairingInstallationId
notify = localPairingStatusChanged

proc getLocalPairingInstallationName*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.name
QtProperty[string] localPairingInstallationName:
read = getLocalPairingInstallationName
notify = localPairingStatusChanged

proc getLocalPairingInstallationDeviceType*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.deviceType
QtProperty[string] localPairingInstallationDeviceType:
read = getLocalPairingInstallationDeviceType
notify = localPairingStatusChanged

proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) =
self.localPairingStatus = status
self.localPairingStatusChanged()
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/startup/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -571,4 +571,4 @@ proc validateLocalPairingConnectionString*(self: Controller, connectionString: s
return self.devicesService.validateConnectionString(connectionString)

proc inputConnectionStringForBootstrapping*(self: Controller, connectionString: string): string =
return self.devicesService.inputConnectionStringForBootstrapping(connectionString)
return self.devicesService.inputConnectionStringForBootstrapping(connectionString)
20 changes: 19 additions & 1 deletion src/app/modules/startup/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,24 @@ QtObject:
read = getLocalPairingImage
notify = localPairingStatusChanged

proc getLocalPairingInstallationId*(self: View): string {.slot.} =
return self.localPairingStatus.installation.id
QtProperty[string] localPairingInstallationId:
read = getLocalPairingInstallationId
notify = localPairingStatusChanged

proc getLocalPairingInstallationName*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.name
QtProperty[string] localPairingInstallationName:
read = getLocalPairingInstallationName
notify = localPairingStatusChanged

proc getLocalPairingInstallationDeviceType*(self: View): string {.slot.} =
return self.localPairingStatus.installation.metadata.deviceType
QtProperty[string] localPairingInstallationDeviceType:
read = getLocalPairingInstallationDeviceType
notify = localPairingStatusChanged

proc onLocalPairingStatusUpdate*(self: View, status: LocalPairingStatus) =
self.localPairingStatus = status
self.localPairingStatusChanged()
Expand All @@ -357,4 +375,4 @@ QtObject:
return self.delegate.validateLocalPairingConnectionString(connectionString)

proc onReencryptionProcessStarted*(self: View) =
self.setAppState(AppState.AppEncryptionProcessState)
self.setAppState(AppState.AppEncryptionProcessState)
12 changes: 10 additions & 2 deletions src/app_service/service/devices/dto/local_pairing_event.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ../../../../app/core/eventemitter
import ../../accounts/dto/accounts
import installation

type
EventType* {.pure.} = enum
Expand All @@ -9,22 +10,25 @@ type
EventTransferError = 2,
EventTransferSuccess = 3,
EventReceivedAccount = 4,
EventProcessSuccess = 5,
EventProcessError = 6
EventReceivedInstallation = 5
EventProcessSuccess = 6,
EventProcessError = 7

type
Action* {.pure.} = enum
ActionUnknown = 0
ActionConnect = 1,
ActionPairingAccount = 2,
ActionSyncDevice = 3,
ActionPairingInstallation = 4,

type
LocalPairingEventArgs* = ref object of Args
eventType*: EventType
action*: Action
error*: string
account*: AccountDTO
installation*: InstallationDto

proc parse*(self: string): EventType =
case self:
Expand All @@ -42,6 +46,8 @@ proc parse*(self: string): EventType =
return EventProcessError
of "received-account":
return EventReceivedAccount
of "received-installation":
return EventReceivedInstallation
else:
return EventUnknown

Expand All @@ -53,5 +59,7 @@ proc parse*(self: int): Action =
return ActionPairingAccount
of 3:
return ActionSyncDevice
of 4:
return ActionPairingInstallation
else:
return ActionUnknown
56 changes: 35 additions & 21 deletions src/app_service/service/devices/dto/local_pairing_status.nim
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import ../../../../app/core/eventemitter
import ../../accounts/dto/accounts
import installation
import local_pairing_event

type
LocalPairingState* {.pure.} = enum
Idle = 0
WaitingForConnection
Transferring
Error
Finished

type
LocalPairingMode* {.pure.} = enum
Idle = 0
BootstrapingOtherDevice
BootstrapingThisDevice
Sender
Receiver

type
LocalPairingStatus* = ref object of Args
mode*: LocalPairingMode
state*: LocalPairingState
account*: AccountDTO
installation*: InstallationDto
error*: string

proc reset*(self: LocalPairingStatus) =
self.mode = LocalPairingMode.Idle
self.state = LocalPairingState.Idle
self.error = ""
self.installation = InstallationDto()

proc setup(self: LocalPairingStatus) =
self.reset()
Expand All @@ -38,29 +40,41 @@ proc newLocalPairingStatus*(): LocalPairingStatus =
new(result, delete)
result.setup()

proc update*(self: LocalPairingStatus, eventType: EventType, action: Action, account: AccountDTO, error: string) =
case eventType:
of EventConnectionSuccess:
self.state = LocalPairingState.WaitingForConnection
of EventTransferSuccess:
self.state = case self.mode:
of LocalPairingMode.BootstrapingOtherDevice:
LocalPairingState.Finished # For servers, `transfer` is last event
of LocalPairingMode.BootstrapingThisDevice:
LocalPairingState.Transferring # For clients, `process` is last event
else:
LocalPairingState.Idle
of EventProcessSuccess:
self.state = LocalPairingState.Finished
proc update*(self: LocalPairingStatus, data: LocalPairingEventArgs) =

self.error = data.error

# process any incoming data
case data.eventType:
of EventReceivedAccount:
self.account = data.account
of EventReceivedInstallation:
self.installation = data.installation
of EventConnectionError:
self.state = LocalPairingState.Error
of EventTransferError:
self.state = LocalPairingState.Error
of EventProcessError:
self.state = LocalPairingState.Error
of EventReceivedAccount:
self.account = account
else:
discard

self.error = error

if self.state == LocalPairingState.Error:
return

# Detect finished state
if (self.mode == LocalPairingMode.Sender and
data.eventType == EventProcessSuccess and
data.action == ActionPairingInstallation):
self.state = LocalPairingState.Finished

if (self.mode == LocalPairingMode.Receiver and
data.eventType == EventTransferSuccess and
data.action == ActionPairingInstallation):
self.state = LocalPairingState.Finished

if self.state == LocalPairingState.Finished:
return

self.state = LocalPairingState.Transferring

11 changes: 6 additions & 5 deletions src/app_service/service/devices/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ QtObject:

proc updateLocalPairingStatus(self: Service, data: LocalPairingEventArgs) =
self.events.emit(SIGNAL_LOCAL_PAIRING_EVENT, data)
self.localPairingStatus.update(data.eventType, data.action, data.account, data.error)
self.localPairingStatus.update(data)
self.events.emit(SIGNAL_LOCAL_PAIRING_STATUS_UPDATE, self.localPairingStatus)

proc doConnect(self: Service) =
Expand All @@ -90,9 +90,10 @@ QtObject:
self.events.on(SignalType.LocalPairing.event) do(e:Args):
let signalData = LocalPairingSignal(e)
let data = LocalPairingEventArgs(
eventType: signalData.eventType.parse(),
action: signalData.action.parse(),
eventType: signalData.eventType,
action: signalData.action,
account: signalData.account,
installation: signalData.installation,
error: signalData.error)
self.updateLocalPairingStatus(data)

Expand Down Expand Up @@ -187,7 +188,7 @@ QtObject:
"timeout": 5 * 60 * 1000,
}
}
self.localPairingStatus.mode = LocalPairingMode.BootstrapingOtherDevice
self.localPairingStatus.mode = LocalPairingMode.Sender
return status_go.getConnectionStringForBootstrappingAnotherDevice($configJSON)

proc inputConnectionStringForBootstrapping*(self: Service, connectionString: string): string =
Expand All @@ -203,7 +204,7 @@ QtObject:
},
"clientConfig": %* {}
}
self.localPairingStatus.mode = LocalPairingMode.BootstrapingThisDevice
self.localPairingStatus.mode = LocalPairingMode.Receiver

let arg = AsyncInputConnectionStringArg(
tptr: cast[ByteAddress](asyncInputConnectionStringTask),
Expand Down
3 changes: 2 additions & 1 deletion ui/StatusQ/src/StatusQ/Components/StatusListItem.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Rectangle {
property var inlineTagModel: []
property Component inlineTagDelegate
property bool loading: false
property bool loadingSubTitle: loading
property bool errorMode: false

property StatusAssetSettings asset: StatusAssetSettings {
Expand Down Expand Up @@ -291,7 +292,7 @@ Rectangle {
Theme.palette.baseColor1 : Theme.palette.directColor1
visible: !!root.subTitle
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
loading: root.loading
loading: root.loadingSubTitle
maximumLineCount: 3
elide: Text.ElideRight
}
Expand Down
3 changes: 3 additions & 0 deletions ui/app/AppLayouts/Onboarding/stores/StartupStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ QtObject {
readonly property string localPairingImage: startupModuleInst ? startupModuleInst.localPairingImage : ""
readonly property int localPairingColorId: startupModuleInst ? startupModuleInst.localPairingColorId : 0
readonly property string localPairingColorHash: startupModuleInst ? startupModuleInst.localPairingColorHash : ""
readonly property string localPairingInstallationId: startupModuleInst ? startupModuleInst.localPairingInstallationId : ""
readonly property string localPairingInstallationName: startupModuleInst ? startupModuleInst.localPairingInstallationName : ""
readonly property string localPairingInstallationDeviceType: startupModuleInst ? startupModuleInst.localPairingInstallationDeviceType : ""

function backAction() {
root.currentStartupState.backAction()
Expand Down
3 changes: 3 additions & 0 deletions ui/app/AppLayouts/Onboarding/views/SyncDeviceResult.qml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ Item {
userColorId: startupStore.localPairingColorId
userColorHash: startupStore.localPairingColorHash

installationId: startupStore.localPairingInstallationId
installationName: startupStore.localPairingInstallationName
installationDeviceType: startupStore.localPairingInstallationDeviceType
}

StatusButton {
Expand Down
6 changes: 4 additions & 2 deletions ui/app/AppLayouts/Profile/popups/SetupSyncingPopup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ StatusDialog {
target: root.devicesStore
function onLocalPairingStateChanged() {
switch (root.devicesStore.localPairingState) {
case Constants.LocalPairingState.WaitingForConnection:
break;
case Constants.LocalPairingState.Transferring:
d.localPairingStarted()
break
Expand Down Expand Up @@ -220,6 +218,10 @@ StatusDialog {

localPairingState: root.devicesStore.localPairingState
localPairingError: root.devicesStore.localPairingError

installationId: root.devicesStore.localPairingInstallationId
installationName: root.devicesStore.localPairingInstallationName
installationDeviceType: root.devicesStore.localPairingInstallationDeviceType
}

Views.ErrorMessage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ StatusDialog {

onOpened: {
nameInput.text = deviceModel.name
nameInput.forceActiveFocus()
}

contentItem: ColumnLayout {
Expand Down
3 changes: 3 additions & 0 deletions ui/app/AppLayouts/Profile/stores/DevicesStore.qml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ QtObject {

readonly property int localPairingState: devicesModule ? devicesModule.localPairingState : -1
readonly property string localPairingError: devicesModule ? devicesModule.localPairingError : ""
readonly property string localPairingInstallationId: devicesModule ? devicesModule.localPairingInstallationId : ""
readonly property string localPairingInstallationName: devicesModule ? devicesModule.localPairingInstallationName : ""
readonly property string localPairingInstallationDeviceType: devicesModule ? devicesModule.localPairingInstallationDeviceType : ""

function loadDevices() {
return root.devicesModule.loadDevices()
Expand Down
Loading

0 comments on commit abf58b0

Please sign in to comment.