feat: allow to enable/disable telemetry

This commit is contained in:
Anthony Laibe 2021-11-04 15:41:25 +01:00 committed by Iuri Matias
parent 1315b0534d
commit f913dce44a
9 changed files with 93 additions and 4 deletions

View File

@ -37,3 +37,9 @@ method delete*[T](self: Controller[T]) =
method init*[T](self: Controller[T]) =
discard
method toggleTelemetry*[T](self: Controller[T]) =
self.settingsService.toggleTelemetry()
method isTelemetryEnabled*[T](self: Controller[T]): bool =
return self.settingsService.isTelemetryEnabled()

View File

@ -9,6 +9,12 @@ method delete*(self: AccessInterface) {.base.} =
method init*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleTelemetry*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isTelemetryEnabled*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.

View File

@ -11,6 +11,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method toggleTelemetry*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.

View File

@ -51,7 +51,7 @@ proc newModule*[T](delegate: T,
Module[T] =
result = Module[T]()
result.delegate = delegate
result.view = view.newView()
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController[Module[T]](result, accountsService, settingsService, profileService, languageService, mnemonicService, privacyService)
result.moduleLoaded = false
@ -85,6 +85,8 @@ method load*[T](self: Module[T]) =
self.privacyModule.load()
self.aboutModule.load()
self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled())
self.moduleLoaded = true
self.delegate.profileSectionDidLoad()
@ -93,3 +95,6 @@ method isLoaded*[T](self: Module[T]): bool =
method viewDidLoad*(self: Module) =
discard
method toggleTelemetry*[T](self: Module[T]) =
self.controller.toggleTelemetry()

View File

@ -1,8 +1,13 @@
import NimQml
import ./io_interface
QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
# TODO: move to the correct module once all have been merged
isTelemetryEnabled: bool
proc setup(self: View) =
self.QObject.setup
@ -10,6 +15,24 @@ QtObject:
proc delete*(self: View) =
self.QObject.delete
proc newView*(): View =
proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.delegate = delegate
result.setup()
proc isTelemetryEnabledChanged*(self: View) {.signal.}
proc setIsTelemetryEnabled*(self: View, isTelemetryEnabled: bool) =
self.isTelemetryEnabled = isTelemetryEnabled
self.isTelemetryEnabledChanged()
proc getIsTelemetryEnabled*(self: View): QVariant {.slot.} =
return newQVariant(self.isTelemetryEnabled)
QtProperty[QVariant] isTelemetryEnabled:
read = getIsTelemetryEnabled
notify = isTelemetryEnabledChanged
proc toggleTelemetry*(self: View) {.slot.} =
self.delegate.toggleTelemetry()
self.setIsTelemetryEnabled(not self.isTelemetryEnabled)

View File

@ -76,3 +76,15 @@ method getCurrentNetworkDetails*(self: Service): NetworkDetails =
for n in networks:
if n.id == currNetwork:
return n
method toggleTelemetry*(self: Service) =
let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl)
var newValue = ""
if telemetryServerUrl == "":
newValue = "https://telemetry.status.im"
discard status_go_settings.saveSetting(Setting.TelemetryServerUrl, newValue)
method isTelemetryEnabled*(self: Service): bool =
let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl)
return telemetryServerUrl != ""

View File

@ -47,3 +47,9 @@ method setDappsAddress*(self: ServiceInterface, address: string): bool {.base.}
method getCurrentNetworkDetails*(self: ServiceInterface): NetworkDetails {.base.} =
raise newException(ValueError, "No implementation available")
method toggleTelemetry*(self: ServiceInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isTelemetryEnabled*(self: ServiceInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -406,6 +406,16 @@ ScrollView {
localAccountSensitiveSettings.stickersEnsRopsten = !localAccountSensitiveSettings.stickersEnsRopsten
}
}
// TODO: replace with StatusQ component
StatusSettingsLineButton {
text: qsTr("Enable Telemetry")
isSwitch: true
switchChecked: root.store.profileModuleInst.isTelemetryEnabled
onClicked: {
openPopup(enableTelemetryConfirmationDialogComponent, {light: false})
}
}
}
NetworksModal {
@ -416,6 +426,24 @@ ScrollView {
id: fleetModal
}
Component {
id: enableTelemetryConfirmationDialogComponent
ConfirmationDialog {
property bool mode: false
id: confirmDialog
showCancelButton: true
confirmationText: qsTr("Are you sure you want to enable telemetry? This will reduce your privacy level while using Status. You need to restart the app for this change to take effect.")
onConfirmButtonClicked: {
root.store.profileModuleInst.toggleTelemetry()
close()
}
onCancelButtonClicked: {
close()
}
}
}
ConfirmationDialog {
id: confirmationPopup
property string settingsProp: ""

2
vendor/status-lib vendored

@ -1 +1 @@
Subproject commit 1aba03aed619b605a2f41eb02765d65756fff817
Subproject commit 5417274a3bb83645725bdc9dcad3e6d5af4b269c