From 44ceb6730dbf522be849328d26e0be964d44bbbe Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Mon, 27 Dec 2021 12:04:10 +0100 Subject: [PATCH] refactor(@desktop/settings-devices): device settings added --- src/app/boot/app_controller.nim | 8 +- .../core/signals/remote_signals/messages.nim | 9 +- src/app/modules/main/module.nim | 6 +- .../main/profile_section/about/module.nim | 2 + .../profile_section/devices/controller.nim | 62 ++++++++++++ .../devices/controller_interface.nim | 32 ++++++ .../profile_section/devices/io_interface.nim | 11 +++ .../main/profile_section/devices/item.nim | 31 ++++++ .../main/profile_section/devices/model.nim | 94 ++++++++++++++++++ .../main/profile_section/devices/module.nim | 91 +++++++++++++++++ .../module_access_interface.nim | 13 +++ .../module_base_interface.nim | 5 + .../module_controller_delegate_interface.nim | 2 + .../module_view_delegate_interface.nim | 17 ++++ .../main/profile_section/devices/view.nim | 56 +++++++++++ .../main/profile_section/io_interface.nim | 6 ++ .../modules/main/profile_section/module.nim | 20 +++- src/app/modules/main/profile_section/view.nim | 8 +- src/app_service/service/about/service.nim | 4 +- .../service/devices/dto/device.nim | 39 ++++++++ src/app_service/service/devices/service.nim | 99 +++++++++++++++++++ .../service/settings/dto/settings.nim | 3 + src/app_service/service/settings/service.nim | 9 ++ .../service/settings/service_interface.nim | 6 ++ ui/app/AppLayouts/Profile/ProfileLayout.qml | 2 +- .../Profile/stores/DevicesStore.qml | 29 ++++++ .../AppLayouts/Profile/stores/RootStore.qml | 28 +----- .../AppLayouts/Profile/views/DevicesView.qml | 25 ++--- 28 files changed, 668 insertions(+), 49 deletions(-) create mode 100644 src/app/modules/main/profile_section/devices/controller.nim create mode 100644 src/app/modules/main/profile_section/devices/controller_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/io_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/item.nim create mode 100644 src/app/modules/main/profile_section/devices/model.nim create mode 100644 src/app/modules/main/profile_section/devices/module.nim create mode 100644 src/app/modules/main/profile_section/devices/private_interfaces/module_access_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/private_interfaces/module_base_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/private_interfaces/module_controller_delegate_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/private_interfaces/module_view_delegate_interface.nim create mode 100644 src/app/modules/main/profile_section/devices/view.nim create mode 100644 src/app_service/service/devices/dto/device.nim create mode 100644 src/app_service/service/devices/service.nim create mode 100644 ui/app/AppLayouts/Profile/stores/DevicesStore.qml diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 2a485429db..d9018b2092 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -28,6 +28,7 @@ import ../../app_service/service/node_configuration/service as node_configuratio import ../../app_service/service/network/service as network_service import ../../app_service/service/activity_center/service as activity_center_service import ../../app_service/service/saved_address/service as saved_address_service +import ../../app_service/service/devices/service as devices_service import ../modules/startup/module as startup_module import ../modules/main/module as main_module @@ -96,6 +97,7 @@ type privacyService: privacy_service.Service nodeConfigurationService: node_configuration_service.Service savedAddressService: saved_address_service.Service + devicesService: devices_service.Service # Modules startupModule: startup_module.AccessInterface @@ -171,6 +173,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.privacyService = privacy_service.newService() result.providerService = provider_service.newService(result.dappPermissionsService, result.settingsService) result.savedAddressService = saved_address_service.newService(statusFoundation.status.events) + result.devicesService = devices_service.newService(statusFoundation.status.events, result.settingsService) # Modules result.startupModule = startup_module.newModule[AppController]( @@ -204,7 +207,8 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController = result.stickersService, result.activityCenterService, result.savedAddressService, - result.nodeConfigurationService + result.nodeConfigurationService, + result.devicesService ) # Do connections @@ -242,6 +246,7 @@ proc delete*(self: AppController) = self.settingsService.delete self.stickersService.delete self.savedAddressService.delete + self.devicesService.delete proc startupDidLoad*(self: AppController) = singletonInstance.engine.setRootContextProperty("localAppSettings", self.localAppSettingsVariant) @@ -282,6 +287,7 @@ proc load(self: AppController) = self.activityCenterService.init() self.savedAddressService.init() self.aboutService.init() + self.devicesService.init() let pubKey = self.settingsService.getPublicKey() singletonInstance.localAccountSensitiveSettings.setFileName(pubKey) diff --git a/src/app/core/signals/remote_signals/messages.nim b/src/app/core/signals/remote_signals/messages.nim index 5e16f58b60..f6a76aedda 100644 --- a/src/app/core/signals/remote_signals/messages.nim +++ b/src/app/core/signals/remote_signals/messages.nim @@ -3,7 +3,7 @@ import json import base # Step by step we should remove all these types from `status-lib` -import status/types/[installation, activity_center_notification, removed_message] +import status/types/[activity_center_notification, removed_message] import status/types/community as old_community import ../../../../app_service/service/message/dto/[message, pinned_message, reaction] @@ -11,13 +11,14 @@ import ../../../../app_service/service/chat/dto/[chat] import ../../../../app_service/service/community/dto/[community] import ../../../../app_service/service/activity_center/dto/[notification] import ../../../../app_service/service/contacts/dto/[contacts, status_update] +import ../../../../app_service/service/devices/dto/[device] type MessageSignal* = ref object of Signal messages*: seq[MessageDto] pinnedMessages*: seq[PinnedMessageDto] chats*: seq[ChatDto] contacts*: seq[ContactsDto] - installations*: seq[Installation] + devices*: seq[DeviceDto] emojiReactions*: seq[ReactionDto] communities*: seq[CommunityDto] membershipRequests*: seq[old_community.CommunityMembershipRequest] @@ -50,8 +51,8 @@ proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal = signal.statusUpdates.add(statusUpdate) if event["event"]{"installations"} != nil: - for jsonInstallation in event["event"]["installations"]: - signal.installations.add(jsonInstallation.toInstallation) + for jsonDevice in event["event"]["installations"]: + signal.devices.add(jsonDevice.toDeviceDto()) if event["event"]{"emojiReactions"} != nil: for jsonReaction in event["event"]["emojiReactions"]: diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 9e9ee66dfe..7767b933e4 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -37,6 +37,7 @@ import ../../../app_service/service/stickers/service as stickers_service import ../../../app_service/service/activity_center/service as activity_center_service import ../../../app_service/service/saved_address/service as saved_address_service import ../../../app_service/service/node_configuration/service_interface as node_configuration_service +import ../../../app_service/service/devices/service as devices_service import eventemitter @@ -84,7 +85,8 @@ proc newModule*[T]( stickersService: stickers_service.Service, activityCenterService: activity_center_service.Service, savedAddressService: saved_address_service.ServiceInterface, - nodeConfigurationService: node_configuration_service.ServiceInterface + nodeConfigurationService: node_configuration_service.ServiceInterface, + devicesService: devices_service.Service ): Module[T] = result = Module[T]() result.delegate = delegate @@ -116,7 +118,7 @@ proc newModule*[T]( dappPermissionsService, providerService) result.profileSectionModule = profile_section_module.newModule(result, events, accountsService, settingsService, profileService, contactsService, aboutService, languageService, mnemonicService, privacyService, - nodeConfigurationService) + nodeConfigurationService, devicesService) result.stickersModule = stickers_module.newModule(result, events, stickersService) result.activityCenterModule = activity_center_module.newModule(result, events, activityCenterService, contactsService) result.communitiesModule = communities_module.newModule(result, events, communityService) diff --git a/src/app/modules/main/profile_section/about/module.nim b/src/app/modules/main/profile_section/about/module.nim index 006e7a2f2c..2b24f5fe5a 100644 --- a/src/app/modules/main/profile_section/about/module.nim +++ b/src/app/modules/main/profile_section/about/module.nim @@ -33,6 +33,8 @@ proc newModule*( method delete*(self: Module) = self.view.delete + self.viewVariant.delete + self.controller.delete method load*(self: Module) = self.view.load() diff --git a/src/app/modules/main/profile_section/devices/controller.nim b/src/app/modules/main/profile_section/devices/controller.nim new file mode 100644 index 0000000000..90414d3f06 --- /dev/null +++ b/src/app/modules/main/profile_section/devices/controller.nim @@ -0,0 +1,62 @@ +import Tables, chronicles +import controller_interface +import io_interface + +import ../../../../../app_service/service/settings/service_interface as settings_service +import ../../../../../app_service/service/devices/service as devices_service + +import eventemitter + +export controller_interface + +logScope: + topics = "profile-section-devices-module-controller" + +type + Controller* = ref object of controller_interface.AccessInterface + delegate: io_interface.AccessInterface + events: EventEmitter + settingsService: settings_service.ServiceInterface + devicesService: devices_service.Service + +proc newController*(delegate: io_interface.AccessInterface, + events: EventEmitter, + settingsService: settings_service.ServiceInterface, + devicesService: devices_service.Service): Controller = + result = Controller() + result.delegate = delegate + result.events = events + result.settingsService = settingsService + result.devicesService = devicesService + +method delete*(self: Controller) = + discard + +method init*(self: Controller) = + self.events.on(SIGNAL_UPDATE_DEVICE) do(e: Args): + var args = UpdateDeviceArgs(e) + self.delegate.updateOrAddDevice(args.deviceId, args.name, args.enabled) + +method getMyInstallationId*(self: Controller): string = + return self.settingsService.getInstallationId() + +method getAllDevices*(self: Controller): seq[DeviceDto] = + return self.devicesService.getAllDevices() + +method isDeviceSetup*(self: Controller): bool = + return self.devicesService.isDeviceSetup() + +method setDeviceName*(self: Controller, name: string) = + self.devicesService.setDeviceName(name) + +method syncAllDevices*(self: Controller) = + self.devicesService.syncAllDevices() + +method advertise*(self: Controller) = + self.devicesService.advertise() + +method enableDevice*(self: Controller, deviceId: string, enable: bool) = + if enable: + self.devicesService.enable(deviceId) + else: + self.devicesService.disable(deviceId) \ No newline at end of file diff --git a/src/app/modules/main/profile_section/devices/controller_interface.nim b/src/app/modules/main/profile_section/devices/controller_interface.nim new file mode 100644 index 0000000000..5082eb1da2 --- /dev/null +++ b/src/app/modules/main/profile_section/devices/controller_interface.nim @@ -0,0 +1,32 @@ +import ../../../../../app_service/service/devices/dto/device + +type + AccessInterface* {.pure inheritable.} = ref object of RootObj + ## Abstract class for any input/interaction with this module. + +method delete*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method init*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method getMyInstallationId*(self: AccessInterface): string {.base.} = + raise newException(ValueError, "No implementation available") + +method getAllDevices*(self: AccessInterface): seq[DeviceDto] {.base.} = + raise newException(ValueError, "No implementation available") + +method isDeviceSetup*(self: AccessInterface): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method setDeviceName*(self: AccessInterface, name: string) {.base.} = + raise newException(ValueError, "No implementation available") + +method syncAllDevices*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method advertise*(self: AccessInterface) {.base.} = + raise newException(ValueError, "No implementation available") + +method enableDevice*(self: AccessInterface, deviceId: string, enable: bool) {.base.} = + raise newException(ValueError, "No implementation available") \ No newline at end of file diff --git a/src/app/modules/main/profile_section/devices/io_interface.nim b/src/app/modules/main/profile_section/devices/io_interface.nim new file mode 100644 index 0000000000..71a5bfbb5b --- /dev/null +++ b/src/app/modules/main/profile_section/devices/io_interface.nim @@ -0,0 +1,11 @@ +# Defines how parent module accesses this module +include ./private_interfaces/module_base_interface +include ./private_interfaces/module_access_interface + +# Defines how this module view communicates with this module +include ./private_interfaces/module_view_delegate_interface + +# Defines how this controller communicates with this module +include ./private_interfaces/module_controller_delegate_interface + +# Defines how submodules of this module communicate with this module diff --git a/src/app/modules/main/profile_section/devices/item.nim b/src/app/modules/main/profile_section/devices/item.nim new file mode 100644 index 0000000000..6eae9f7aec --- /dev/null +++ b/src/app/modules/main/profile_section/devices/item.nim @@ -0,0 +1,31 @@ +type + Item* = ref object + installationId: string + name: string + enabled: bool + isCurrentDevice: bool + +proc initItem*(installationId, name: string, enabled, isCurrentDevice: bool): Item = + result = Item() + result.installationId = installationId + result.name = name + result.enabled = enabled + result.isCurrentDevice = isCurrentDevice + +proc installationId*(self: Item): string = + self.installationId + +proc name*(self: Item): string = + self.name + +proc `name=`*(self: Item, value: string) = + self.name = value + +proc enabled*(self: Item): bool = + self.enabled + +proc `enabled=`*(self: Item, value: bool) = + self.enabled = value + +proc isCurrentDevice*(self: Item): bool = + self.isCurrentDevice \ No newline at end of file diff --git a/src/app/modules/main/profile_section/devices/model.nim b/src/app/modules/main/profile_section/devices/model.nim new file mode 100644 index 0000000000..f447f3d1a4 --- /dev/null +++ b/src/app/modules/main/profile_section/devices/model.nim @@ -0,0 +1,94 @@ +import NimQml, Tables +import item + +type + ModelRole {.pure.} = enum + Name = UserRole + 1, + InstallationId + IsCurrentDevice + Enabled + +QtObject: + type Model* = ref object of QAbstractListModel + items*: seq[Item] + + proc setup(self: Model) = + self.QAbstractListModel.setup + + proc delete(self: Model) = + self.items = @[] + self.QAbstractListModel.delete + + proc newModel*(): Model = + new(result, delete) + result.setup + + method rowCount(self: Model, index: QModelIndex = nil): int = + return self.items.len + + method roleNames(self: Model): Table[int, string] = + { + ModelRole.Name.int:"name", + ModelRole.InstallationId.int:"installationId", + ModelRole.IsCurrentDevice.int:"isCurrentDevice", + ModelRole.Enabled.int:"enabled" + }.toTable + + method data(self: Model, index: QModelIndex, role: int): QVariant = + if not index.isValid: + return + if index.row < 0 or index.row >= self.items.len: + return + let item = self.items[index.row] + let enumRole = role.ModelRole + + case enumRole: + of ModelRole.Name: + result = newQVariant(item.name) + of ModelRole.InstallationId: + result = newQVariant(item.installationId) + of ModelRole.IsCurrentDevice: + result = newQVariant(item.isCurrentDevice) + of ModelRole.Enabled: + result = newQVariant(item.enabled) + + proc addItems*(self: Model, items: seq[Item]) = + if(items.len == 0): + return + + let parentModelIndex = newQModelIndex() + defer: parentModelIndex.delete + + let first = self.items.len + let last = first + items.len - 1 + self.beginInsertRows(parentModelIndex, first, last) + self.items.add(items) + self.endInsertRows() + + proc addItem*(self: Model, item: Item) = + let parentModelIndex = newQModelIndex() + defer: parentModelIndex.delete + + self.beginInsertRows(parentModelIndex, self.items.len, self.items.len) + self.items.add(item) + self.endInsertRows() + + proc findIndexByInstallationId(self: Model, installationId: string): int = + for i in 0.. 0): + for d in receivedData.devices: + let data = UpdateDeviceArgs( + deviceId: d.id, + name: d.metadata.name, + enabled: d.enabled) + self.events.emit(SIGNAL_UPDATE_DEVICE, data) + + proc init*(self: Service) = + self.doConnect() + + proc getAllDevices*(self: Service): seq[DeviceDto] = + try: + let response = status_installations.getOurInstallations() + return map(response.result.getElems(), proc(x: JsonNode): DeviceDto = x.toDeviceDto()) + except Exception as e: + let errDesription = e.msg + error "error: ", errDesription + + proc isNewDevice(self: Service, device: DeviceDto): bool = + let allDevices = self.getAllDevices() + for d in allDevices: + if(d.id == device.id): + return false + return true + + proc setDeviceName*(self: Service, name: string) = + let installationId = self.settingsService.getInstallationId() + # Once we get more info from `status-go` we may emit success/failed signal from here. + discard status_installations.setInstallationMetadata(installationId, name, hostOs) + + proc isDeviceSetup*(self: Service): bool = + let allDevices = self.getAllDevices() + let installationId = self.settingsService.getInstallationId() + for d in allDevices: + if d.id == installationId: + return not d.metadata.isEmpty() + return false + + proc syncAllDevices*(self: Service) = + let preferredName = self.settingsService.getPreferredName() + let photoPath = "" # From the old code: TODO change this to identicon when status-go is updated + # Once we get more info from `status-go` we may emit success/failed signal from here. + discard status_installations.syncDevices(preferredName, "") + + proc advertise*(self: Service) = + # Once we get more info from `status-go` we may emit success/failed signal from here. + discard status_installations.sendPairInstallation() + + proc enable*(self: Service, deviceId: string) = + # Once we get more info from `status-go` we may emit success/failed signal from here. + discard status_installations.enableInstallation(deviceId) + + proc disable*(self: Service, deviceId: string) = + # Once we get more info from `status-go` we may emit success/failed signal from here. + discard status_installations.disableInstallation(deviceId) \ No newline at end of file diff --git a/src/app_service/service/settings/dto/settings.nim b/src/app_service/service/settings/dto/settings.nim index 5a0707bed4..3f660d1f5b 100644 --- a/src/app_service/service/settings/dto/settings.nim +++ b/src/app_service/service/settings/dto/settings.nim @@ -11,6 +11,7 @@ const KEY_NETWORKS_ALL_NETWORKS* = "networks/networks" const KEY_DAPPS_ADDRESS* = "dapps-address" const KEY_EIP1581_ADDRESS* = "eip1581-address" const KEY_INSTALLATION_ID* = "installation-id" +const KEY_PREFERRED_NAME* = "preferred-name" const KEY_KEY_UID* = "key-uid" const KEY_LATEST_DERIVED_PATH* = "latest-derived-path" const KEY_LINK_PREVIEW_REQUEST_ENABLED* = "link-preview-request-enabled" @@ -75,6 +76,7 @@ type dappsAddress*: string eip1581Address*: string installationId*: string + preferredName*: string keyUid*: string latestDerivedPath*: int linkPreviewRequestEnabled*: bool @@ -171,6 +173,7 @@ proc toSettingsDto*(jsonObj: JsonNode): SettingsDto = discard jsonObj.getProp(KEY_DAPPS_ADDRESS, result.dappsAddress) discard jsonObj.getProp(KEY_EIP1581_ADDRESS, result.eip1581Address) discard jsonObj.getProp(KEY_INSTALLATION_ID, result.installationId) + discard jsonObj.getProp(KEY_PREFERRED_NAME, result.preferredName) discard jsonObj.getProp(KEY_KEY_UID, result.keyUid) discard jsonObj.getProp(KEY_LATEST_DERIVED_PATH, result.latestDerivedPath) discard jsonObj.getProp(KEY_LINK_PREVIEW_REQUEST_ENABLED, result.linkPreviewRequestEnabled) diff --git a/src/app_service/service/settings/service.nim b/src/app_service/service/settings/service.nim index cb7861a345..7ad4b41696 100644 --- a/src/app_service/service/settings/service.nim +++ b/src/app_service/service/settings/service.nim @@ -98,6 +98,15 @@ method saveInstallationId*(self: Service, value: string): bool = method getInstallationId*(self: Service): string = return self.settings.installationId +method savePreferredName*(self: Service, value: string): bool = + if(self.saveSetting(KEY_PREFERRED_NAME, value)): + self.settings.preferredName = value + return true + return false + +method getPreferredName*(self: Service): string = + return self.settings.preferredName + method saveKeyUid*(self: Service, value: string): bool = if(self.saveSetting(KEY_KEY_UID, value)): self.settings.keyUid = value diff --git a/src/app_service/service/settings/service_interface.nim b/src/app_service/service/settings/service_interface.nim index 049596b795..793dd7d63f 100644 --- a/src/app_service/service/settings/service_interface.nim +++ b/src/app_service/service/settings/service_interface.nim @@ -59,6 +59,12 @@ method saveInstallationId*(self: ServiceInterface, value: string): bool {.base.} method getInstallationId*(self: ServiceInterface): string {.base.} = raise newException(ValueError, "No implementation available") +method savePreferredName*(self: ServiceInterface, value: string): bool {.base.} = + raise newException(ValueError, "No implementation available") + +method getPreferredName*(self: ServiceInterface): string {.base.} = + raise newException(ValueError, "No implementation available") + method saveKeyUid*(self: ServiceInterface, value: string): bool {.base.} = raise newException(ValueError, "No implementation available") diff --git a/ui/app/AppLayouts/Profile/ProfileLayout.qml b/ui/app/AppLayouts/Profile/ProfileLayout.qml index 3a3d487f9b..92f69964e3 100644 --- a/ui/app/AppLayouts/Profile/ProfileLayout.qml +++ b/ui/app/AppLayouts/Profile/ProfileLayout.qml @@ -93,7 +93,7 @@ StatusAppTwoPanelLayout { } DevicesView { - store: profileView.store + devicesStore: profileView.store.devicesStore } BrowserView { diff --git a/ui/app/AppLayouts/Profile/stores/DevicesStore.qml b/ui/app/AppLayouts/Profile/stores/DevicesStore.qml new file mode 100644 index 0000000000..8b4a0214f9 --- /dev/null +++ b/ui/app/AppLayouts/Profile/stores/DevicesStore.qml @@ -0,0 +1,29 @@ +import QtQuick 2.13 +import utils 1.0 + +QtObject { + id: root + + property var devicesModule + + property var devicesModel: devicesModule.model + + // Module Properties + property bool isDeviceSetup: devicesModule.isDeviceSetup + + function setName(name) { + return root.devicesModule.setName(name) + } + + function syncAll() { + root.devicesModule.syncAll() + } + + function advertise() { + root.devicesModule.advertise() + } + + function enableDevice(installationId, enable) { + root.devicesModule.enableDevice(installationId, enable) + } +} diff --git a/ui/app/AppLayouts/Profile/stores/RootStore.qml b/ui/app/AppLayouts/Profile/stores/RootStore.qml index 76d9200077..5812d34217 100644 --- a/ui/app/AppLayouts/Profile/stores/RootStore.qml +++ b/ui/app/AppLayouts/Profile/stores/RootStore.qml @@ -11,10 +11,15 @@ QtObject { property var mnemonicModuleInst: mnemonicModule property var profileModuleInst: profileSectionModule + property AdvancedStore advancedStore: AdvancedStore { advancedModule: profileModuleInst.advancedModule } + property DevicesStore devicesStore: DevicesStore { + devicesModule: profileModuleInst.devicesModule + } + // Not Refactored Yet // property var chatsModelInst: chatsModel // Not Refactored Yet @@ -37,7 +42,6 @@ QtObject { // Not Refactored Yet // property var mutedChatsContacts: profileModelInst.mutedChats.contacts // property var mutedChats: profileModelInst.mutedChats.chats -// property var devicesList: profileModelInst.devices.list // Not Refactored Yet property string ensRegisterAddress: "" //utilsModelInst.ensRegisterAddress @@ -55,8 +59,6 @@ QtObject { property bool profileHasIdentityImage: profile.hasIdentityImage // Not Refactored Yet // property bool automaticMailserverSelection: profileModelInst.mailservers.automaticSelection - // Not Refactored Yet - property bool devicesSetup: false //profileModelInst.devices.isSetup property bool mnemonicBackedUp: mnemonicModuleInst.isBackedUp property bool messagesFromContactsOnly: profile.messagesFromContactsOnly @@ -364,26 +366,6 @@ QtObject { // return profileModelInst.ens.setPubKey(username, address, gasLimit, gasPrice, password) } - function setDeviceName(name) { - // Not Refactored Yet -// profileModelInst.devices.setName(name) - } - - function advertiseDevice() { - // Not Refactored Yet -// profileModelInst.devices.advertise() - } - - function enableDeviceInstallation(id, pairedSwitch) { - // Not Refactored Yet -// profileModelInst.devices.enableInstallation(id, pairedSwitch) - } - - function syncAllDevices() { - // Not Refactored Yet -// profileModelInst.devices.syncAll() - } - function readTextFile(path) { return globalUtils.readTextFile(path) } diff --git a/ui/app/AppLayouts/Profile/views/DevicesView.qml b/ui/app/AppLayouts/Profile/views/DevicesView.qml index ebeae54f7d..961e72b44c 100644 --- a/ui/app/AppLayouts/Profile/views/DevicesView.qml +++ b/ui/app/AppLayouts/Profile/views/DevicesView.qml @@ -15,7 +15,8 @@ import shared.controls 1.0 Item { id: root - property var store + property var devicesStore + property bool isSyncing: false width: 200 @@ -32,7 +33,7 @@ Item { anchors.topMargin: 24 anchors.right: parent.right anchors.rightMargin: Style.current.padding - visible: !root.store.devicesSetup + visible: !root.devicesStore.isDeviceSetup height: visible ? childrenRect.height : 0 StatusBaseText { @@ -59,7 +60,7 @@ Item { //% "Continue" text: qsTrId("continue") enabled: deviceNameTxt.text !== "" - onClicked : root.store.setDeviceName(deviceNameTxt.text.trim()) + onClicked : root.devicesStore.setName(deviceNameTxt.text.trim()) } } @@ -71,7 +72,7 @@ Item { anchors.topMargin: Style.current.padding anchors.right: parent.right anchors.rightMargin: Style.current.padding - visible: root.store.devicesSetup + visible: root.devicesStore.isDeviceSetup height: visible ? childrenRect.height : 0 Rectangle { @@ -122,7 +123,7 @@ Item { MouseArea { cursorShape: Qt.PointingHandCursor anchors.fill: parent - onClicked: root.store.advertiseDevice() + onClicked: root.devicesStore.advertise() } } @@ -153,7 +154,7 @@ Item { anchors.bottomMargin: Style.current.padding anchors.right: root.right anchors.rightMargin: Style.current.padding - visible: root.store.devicesSetup + visible: root.devicesStore.isDeviceSetup StatusBaseText { id: deviceListLbl @@ -193,7 +194,7 @@ Item { //% "No info" let labelText = `${model.name || qsTrId("pairing-no-info")} ` + //% "you" - `(${model.isUserDevice ? qsTrId("you") + ", ": ""}${deviceId})`; + `(${model.isCurrentDevice ? qsTrId("you") + ", ": ""}${deviceId})`; return labelText; } elide: Text.ElideRight @@ -204,15 +205,15 @@ Item { } StatusSwitch { id: devicePairedSwitch - visible: !model.isUserDevice - checked: model.isEnabled + visible: !model.isCurrentDevice + checked: model.enabled anchors.left: deviceItemLbl.right anchors.leftMargin: Style.current.padding anchors.top: deviceItemLbl.top - onClicked: root.store.enableDeviceInstallation(model.installationId, devicePairedSwitch) + onClicked: root.devicesStore.enableDevice(model.installationId, devicePairedSwitch) } } - model: root.store.devicesList + model: root.devicesStore.devicesModel } } @@ -229,7 +230,7 @@ Item { enabled: !isSyncing onClicked : { isSyncing = true; - root.store.syncAllDevices() + root.devicesStore.syncAll() // Currently we don't know how long it takes, so we just disable for 10s, to avoid spamming timer.setTimeout(function(){ isSyncing = false