fix(Syncing): Fixed changing device name (#9921)
This commit is contained in:
parent
3b2a8f4253
commit
2d22f2f09a
|
@ -34,16 +34,20 @@ proc delete*(self: Controller) =
|
||||||
|
|
||||||
proc init*(self: Controller) =
|
proc init*(self: Controller) =
|
||||||
self.events.on(SIGNAL_DEVICES_LOADED) do(e: Args):
|
self.events.on(SIGNAL_DEVICES_LOADED) do(e: Args):
|
||||||
var args = DevicesArg(e)
|
let args = DevicesArg(e)
|
||||||
self.delegate.onDevicesLoaded(args.devices)
|
self.delegate.onDevicesLoaded(args.devices)
|
||||||
|
|
||||||
self.events.on(SIGNAL_ERROR_LOADING_DEVICES) do(e: Args):
|
self.events.on(SIGNAL_ERROR_LOADING_DEVICES) do(e: Args):
|
||||||
self.delegate.onDevicesLoadingErrored()
|
self.delegate.onDevicesLoadingErrored()
|
||||||
|
|
||||||
self.events.on(SIGNAL_UPDATE_DEVICE) do(e: Args):
|
self.events.on(SIGNAL_UPDATE_DEVICE) do(e: Args):
|
||||||
var args = UpdateInstallationArgs(e)
|
let args = UpdateInstallationArgs(e)
|
||||||
self.delegate.updateOrAddDevice(args.installation)
|
self.delegate.updateOrAddDevice(args.installation)
|
||||||
|
|
||||||
|
self.events.on(SIGNAL_INSTALLATION_NAME_UPDATED) do(e: Args):
|
||||||
|
let args = UpdateInstallationNameArgs(e)
|
||||||
|
self.delegate.updateInstallationName(args.installationId, args.name)
|
||||||
|
|
||||||
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
|
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
|
||||||
let args = SharedKeycarModuleArgs(e)
|
let args = SharedKeycarModuleArgs(e)
|
||||||
if args.uniqueIdentifier != UNIQUE_SYNCING_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER:
|
if args.uniqueIdentifier != UNIQUE_SYNCING_SECTION_ACCOUNTS_MODULE_AUTH_IDENTIFIER:
|
||||||
|
@ -51,11 +55,11 @@ proc init*(self: Controller) =
|
||||||
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)
|
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)
|
||||||
|
|
||||||
self.events.on(SIGNAL_LOCAL_PAIRING_EVENT) do(e: Args):
|
self.events.on(SIGNAL_LOCAL_PAIRING_EVENT) do(e: Args):
|
||||||
var args = LocalPairingEventArgs(e)
|
let args = LocalPairingEventArgs(e)
|
||||||
self.delegate.onLocalPairingEvent(args.eventType, args.action, args.error)
|
self.delegate.onLocalPairingEvent(args.eventType, args.action, args.error)
|
||||||
|
|
||||||
self.events.on(SIGNAL_LOCAL_PAIRING_STATUS_UPDATE) do(e: Args):
|
self.events.on(SIGNAL_LOCAL_PAIRING_STATUS_UPDATE) do(e: Args):
|
||||||
var args = LocalPairingStatus(e)
|
let args = LocalPairingStatus(e)
|
||||||
self.delegate.onLocalPairingStatusUpdate(args)
|
self.delegate.onLocalPairingStatusUpdate(args)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,8 +72,8 @@ proc asyncLoadDevices*(self: Controller) =
|
||||||
proc getAllDevices*(self: Controller): seq[InstallationDto] =
|
proc getAllDevices*(self: Controller): seq[InstallationDto] =
|
||||||
return self.devicesService.getAllDevices()
|
return self.devicesService.getAllDevices()
|
||||||
|
|
||||||
proc setDeviceName*(self: Controller, name: string) =
|
proc setInstallationName*(self: Controller, installationId: string, name: string) =
|
||||||
self.devicesService.setDeviceName(name)
|
self.devicesService.setInstallationName(installationId, name)
|
||||||
|
|
||||||
proc syncAllDevices*(self: Controller) =
|
proc syncAllDevices*(self: Controller) =
|
||||||
self.devicesService.syncAllDevices()
|
self.devicesService.syncAllDevices()
|
||||||
|
|
|
@ -20,6 +20,9 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||||
method updateOrAddDevice*(self: AccessInterface, installation: InstallationDto) {.base.} =
|
method updateOrAddDevice*(self: AccessInterface, installation: InstallationDto) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method updateInstallationName*(self: AccessInterface, installationId: string, name: string) {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method viewDidLoad*(self: AccessInterface) {.base.} =
|
method viewDidLoad*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
@ -35,7 +38,7 @@ method onDevicesLoadingErrored*(self: AccessInterface) {.base.} =
|
||||||
method loadDevices*(self: AccessInterface) {.base.} =
|
method loadDevices*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method setDeviceName*(self: AccessInterface, name: string) {.base.} =
|
method setInstallationName*(self: AccessInterface, installationId: string, name: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method syncAllDevices*(self: AccessInterface) {.base.} =
|
method syncAllDevices*(self: AccessInterface) {.base.} =
|
||||||
|
|
|
@ -109,10 +109,22 @@ QtObject:
|
||||||
if(i == -1):
|
if(i == -1):
|
||||||
return
|
return
|
||||||
|
|
||||||
let first = self.createIndex(i, 0, nil)
|
let index = self.createIndex(i, 0, nil)
|
||||||
let last = self.createIndex(i, 0, nil)
|
defer: index.delete
|
||||||
|
|
||||||
self.items[i].installation = installation
|
self.items[i].installation = installation
|
||||||
self.dataChanged(first, last, @[])
|
self.dataChanged(index, index, @[])
|
||||||
|
|
||||||
|
proc updateItemName*(self: Model, installationId: string, name: string) =
|
||||||
|
var i = self.findIndexByInstallationId(installationId)
|
||||||
|
if(i == -1):
|
||||||
|
return
|
||||||
|
|
||||||
|
let index = self.createIndex(i, 0, nil)
|
||||||
|
defer: index.delete
|
||||||
|
|
||||||
|
self.items[i].installation.metadata.name = name
|
||||||
|
self.dataChanged(index, index, @[ModelRole.Name.int])
|
||||||
|
|
||||||
proc getIsDeviceSetup*(self: Model, installationId: string): bool =
|
proc getIsDeviceSetup*(self: Model, installationId: string): bool =
|
||||||
return anyIt(self.items, it.installation.id == installationId and it.name != "")
|
return anyIt(self.items, it.installation.id == installationId and it.name != "")
|
||||||
|
|
|
@ -75,11 +75,8 @@ method viewDidLoad*(self: Module) =
|
||||||
method getModuleAsVariant*(self: Module): QVariant =
|
method getModuleAsVariant*(self: Module): QVariant =
|
||||||
return self.viewVariant
|
return self.viewVariant
|
||||||
|
|
||||||
method setDeviceName*(self: Module, name: string) =
|
method setInstallationName*(self: Module, installationId: string, name: string) =
|
||||||
self.controller.setDeviceName(name)
|
self.controller.setInstallationName(installationId, name)
|
||||||
# in future if we start getting more meaningful response form the `status-go` part, we may
|
|
||||||
# move this call to the `onDeviceNameSet` slot and confirm change on the qml side that way.
|
|
||||||
self.view.deviceSetupChanged()
|
|
||||||
|
|
||||||
method syncAllDevices*(self: Module) =
|
method syncAllDevices*(self: Module) =
|
||||||
self.controller.syncAllDevices()
|
self.controller.syncAllDevices()
|
||||||
|
@ -97,6 +94,8 @@ method updateOrAddDevice*(self: Module, installation: InstallationDto) =
|
||||||
let item = initItem(installation, self.isMyDevice(installation.id))
|
let item = initItem(installation, self.isMyDevice(installation.id))
|
||||||
self.view.model().addItem(item)
|
self.view.model().addItem(item)
|
||||||
|
|
||||||
|
method updateInstallationName*(self: Module, installationId: string, name: string) =
|
||||||
|
self.view.model().updateItemName(installationId, name)
|
||||||
|
|
||||||
method authenticateUser*(self: Module, keyUid: string) =
|
method authenticateUser*(self: Module, keyUid: string) =
|
||||||
self.controller.authenticateUser(keyUid)
|
self.controller.authenticateUser(keyUid)
|
||||||
|
|
|
@ -76,8 +76,8 @@ QtObject:
|
||||||
proc loadDevices*(self: View) {.slot.} =
|
proc loadDevices*(self: View) {.slot.} =
|
||||||
self.delegate.loadDevices()
|
self.delegate.loadDevices()
|
||||||
|
|
||||||
proc setName*(self: View, deviceName: string) {.slot.} =
|
proc setInstallationName*(self: View, installationId: string, name: string) {.slot.} =
|
||||||
self.delegate.setDeviceName(deviceName)
|
self.delegate.setInstallationName(installationId, name)
|
||||||
|
|
||||||
proc syncAll*(self: View) {.slot.} =
|
proc syncAll*(self: View) {.slot.} =
|
||||||
self.delegate.syncAllDevices()
|
self.delegate.syncAllDevices()
|
||||||
|
|
|
@ -16,7 +16,7 @@ type InstallationMetadata* = object
|
||||||
deviceType*: string
|
deviceType*: string
|
||||||
fcmToken*: string
|
fcmToken*: string
|
||||||
|
|
||||||
type InstallationDto* = object
|
type InstallationDto* = ref object
|
||||||
id*: string
|
id*: string
|
||||||
identity*: string
|
identity*: string
|
||||||
version*: int
|
version*: int
|
||||||
|
|
|
@ -33,6 +33,11 @@ type
|
||||||
UpdateInstallationArgs* = ref object of Args
|
UpdateInstallationArgs* = ref object of Args
|
||||||
installation*: InstallationDto
|
installation*: InstallationDto
|
||||||
|
|
||||||
|
type
|
||||||
|
UpdateInstallationNameArgs* = ref object of Args
|
||||||
|
installationId*: string
|
||||||
|
name*: string
|
||||||
|
|
||||||
type
|
type
|
||||||
DevicesArg* = ref object of Args
|
DevicesArg* = ref object of Args
|
||||||
devices*: seq[InstallationDto]
|
devices*: seq[InstallationDto]
|
||||||
|
@ -43,6 +48,7 @@ const SIGNAL_DEVICES_LOADED* = "devicesLoaded"
|
||||||
const SIGNAL_ERROR_LOADING_DEVICES* = "devicesErrorLoading"
|
const SIGNAL_ERROR_LOADING_DEVICES* = "devicesErrorLoading"
|
||||||
const SIGNAL_LOCAL_PAIRING_EVENT* = "localPairingEvent"
|
const SIGNAL_LOCAL_PAIRING_EVENT* = "localPairingEvent"
|
||||||
const SIGNAL_LOCAL_PAIRING_STATUS_UPDATE* = "localPairingStatusUpdate"
|
const SIGNAL_LOCAL_PAIRING_STATUS_UPDATE* = "localPairingStatusUpdate"
|
||||||
|
const SIGNAL_INSTALLATION_NAME_UPDATED* = "installationNameUpdated"
|
||||||
|
|
||||||
QtObject:
|
QtObject:
|
||||||
type Service* = ref object of QObject
|
type Service* = ref object of QObject
|
||||||
|
@ -105,8 +111,7 @@ QtObject:
|
||||||
let installations = map(rpcResponse.result.getElems(), proc(x: JsonNode): InstallationDto = x.toInstallationDto())
|
let installations = map(rpcResponse.result.getElems(), proc(x: JsonNode): InstallationDto = x.toInstallationDto())
|
||||||
self.events.emit(SIGNAL_DEVICES_LOADED, DevicesArg(devices: installations))
|
self.events.emit(SIGNAL_DEVICES_LOADED, DevicesArg(devices: installations))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
let errDesription = e.msg
|
error "error loading devices: ", desription = e.msg
|
||||||
error "error loading devices: ", errDesription
|
|
||||||
self.events.emit(SIGNAL_ERROR_LOADING_DEVICES, Args())
|
self.events.emit(SIGNAL_ERROR_LOADING_DEVICES, Args())
|
||||||
|
|
||||||
proc getAllDevices*(self: Service): seq[InstallationDto] =
|
proc getAllDevices*(self: Service): seq[InstallationDto] =
|
||||||
|
@ -114,13 +119,20 @@ QtObject:
|
||||||
let response = status_installations.getOurInstallations()
|
let response = status_installations.getOurInstallations()
|
||||||
return map(response.result.getElems(), proc(x: JsonNode): InstallationDto = x.toInstallationDto())
|
return map(response.result.getElems(), proc(x: JsonNode): InstallationDto = x.toInstallationDto())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
let errDesription = e.msg
|
error "error: ", desription = e.msg
|
||||||
error "error: ", errDesription
|
|
||||||
|
|
||||||
proc setDeviceName*(self: Service, name: string) =
|
proc setInstallationName*(self: Service, installationId: string, name: string) =
|
||||||
let installationId = self.settingsService.getInstallationId()
|
|
||||||
# Once we get more info from `status-go` we may emit success/failed signal from here.
|
# Once we get more info from `status-go` we may emit success/failed signal from here.
|
||||||
discard status_installations.setInstallationMetadata(installationId, name, hostOs)
|
try:
|
||||||
|
let response = status_installations.setInstallationName(installationId, name)
|
||||||
|
if response.error != nil:
|
||||||
|
let e = Json.decode($response.error, RpcError)
|
||||||
|
error "error: ", errorDescription = e.message
|
||||||
|
return
|
||||||
|
let data = UpdateInstallationNameArgs(installationId: installationId, name: name)
|
||||||
|
self.events.emit(SIGNAL_INSTALLATION_NAME_UPDATED, data)
|
||||||
|
except Exception as e:
|
||||||
|
error "error: ", desription = e.msg
|
||||||
|
|
||||||
proc syncAllDevices*(self: Service) =
|
proc syncAllDevices*(self: Service) =
|
||||||
let preferredName = self.settingsService.getPreferredName()
|
let preferredName = self.settingsService.getPreferredName()
|
||||||
|
|
|
@ -12,6 +12,11 @@ proc setInstallationMetadata*(installationId: string, deviceName: string, device
|
||||||
}]
|
}]
|
||||||
result = callPrivateRPC("setInstallationMetadata".prefix, payload)
|
result = callPrivateRPC("setInstallationMetadata".prefix, payload)
|
||||||
|
|
||||||
|
proc setInstallationName*(installationId: string, name: string):
|
||||||
|
RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
|
let payload = %* [installationId, name]
|
||||||
|
result = callPrivateRPC("setInstallationName".prefix, payload)
|
||||||
|
|
||||||
proc getOurInstallations*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
proc getOurInstallations*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||||
let payload = %* []
|
let payload = %* []
|
||||||
result = callPrivateRPC("getOurInstallations".prefix, payload)
|
result = callPrivateRPC("getOurInstallations".prefix, payload)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import QtQml.Models 2.14
|
||||||
import StatusQ.Core 0.1
|
import StatusQ.Core 0.1
|
||||||
import StatusQ.Core.Theme 0.1
|
import StatusQ.Core.Theme 0.1
|
||||||
import StatusQ.Controls 0.1
|
import StatusQ.Controls 0.1
|
||||||
|
import StatusQ.Controls.Validators 0.1
|
||||||
import StatusQ.Components 0.1
|
import StatusQ.Components 0.1
|
||||||
import StatusQ.Popups 0.1
|
import StatusQ.Popups 0.1
|
||||||
import StatusQ.Popups.Dialog 0.1
|
import StatusQ.Popups.Dialog 0.1
|
||||||
|
@ -30,6 +31,13 @@ StatusDialog {
|
||||||
QtObject {
|
QtObject {
|
||||||
id: d
|
id: d
|
||||||
property string deviceName: ""
|
property string deviceName: ""
|
||||||
|
|
||||||
|
function saveNewName() {
|
||||||
|
if (!nameInput.valid)
|
||||||
|
return
|
||||||
|
root.devicesStore.setInstallationName(root.deviceModel.installationId, nameInput.text.trim())
|
||||||
|
root.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onOpened: {
|
onOpened: {
|
||||||
|
@ -41,6 +49,18 @@ StatusDialog {
|
||||||
id: nameInput
|
id: nameInput
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
label: qsTr("Device name")
|
label: qsTr("Device name")
|
||||||
|
validators: [
|
||||||
|
StatusValidator {
|
||||||
|
errorMessage: qsTr("Device name can not be empty")
|
||||||
|
validate: (value) => {
|
||||||
|
return value.trim() !== ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
Keys.onReturnPressed: {
|
||||||
|
d.saveNewName()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,10 +68,9 @@ StatusDialog {
|
||||||
rightButtons: ObjectModel {
|
rightButtons: ObjectModel {
|
||||||
StatusButton {
|
StatusButton {
|
||||||
text: qsTr("Done")
|
text: qsTr("Done")
|
||||||
enabled: nameInput.text !== ""
|
enabled: nameInput.valid
|
||||||
onClicked : {
|
onClicked : {
|
||||||
root.devicesStore.setName(nameInput.text.trim())
|
d.saveNewName()
|
||||||
root.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ QtObject {
|
||||||
return root.devicesModule.loadDevices()
|
return root.devicesModule.loadDevices()
|
||||||
}
|
}
|
||||||
|
|
||||||
function setName(name) {
|
function setInstallationName(installationId, name) {
|
||||||
return root.devicesModule.setName(name)
|
return root.devicesModule.setInstallationName(installationId, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
function syncAll() {
|
function syncAll() {
|
||||||
|
|
Loading…
Reference in New Issue