feat: add toggle for switching status-go DEBUG log level

This commit is contained in:
Richard Ramos 2021-11-11 12:22:03 -04:00
parent c9a0488e89
commit 44e91df428
12 changed files with 103 additions and 4 deletions

View File

@ -43,3 +43,9 @@ method toggleTelemetry*[T](self: Controller[T]) =
method isTelemetryEnabled*[T](self: Controller[T]): bool =
return self.settingsService.isTelemetryEnabled()
method toggleDebug*[T](self: Controller[T]) =
self.settingsService.toggleDebug()
method isDebugEnabled*[T](self: Controller[T]): bool =
return self.settingsService.isDebugEnabled()

View File

@ -15,6 +15,12 @@ method toggleTelemetry*(self: AccessInterface) {.base.} =
method isTelemetryEnabled*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method toggleDebug*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isDebugEnabled*(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

@ -14,6 +14,9 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
method toggleTelemetry*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleDebug*(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

@ -86,6 +86,7 @@ method load*[T](self: Module[T]) =
self.aboutModule.load()
self.view.setIsTelemetryEnabled(self.controller.isTelemetryEnabled())
self.view.setIsDebugEnabled(self.controller.isDebugEnabled())
self.moduleLoaded = true
self.delegate.profileSectionDidLoad()
@ -98,3 +99,6 @@ method viewDidLoad*(self: Module) =
method toggleTelemetry*[T](self: Module[T]) =
self.controller.toggleTelemetry()
method toggleDebug*[T](self: Module[T]) =
self.controller.toggleDebug()

View File

@ -8,6 +8,7 @@ QtObject:
delegate: io_interface.AccessInterface
# TODO: move to the correct module once all have been merged
isTelemetryEnabled: bool
isDebugEnabled: bool
proc setup(self: View) =
self.QObject.setup
@ -35,4 +36,21 @@ QtObject:
proc toggleTelemetry*(self: View) {.slot.} =
self.delegate.toggleTelemetry()
self.setIsTelemetryEnabled(not self.isTelemetryEnabled)
self.setIsTelemetryEnabled(not self.isTelemetryEnabled)
proc isDebugEnabledChanged*(self: View) {.signal.}
proc setIsDebugEnabled*(self: View, isDebugEnabled: bool) =
self.isDebugEnabled = isDebugEnabled
self.isDebugEnabledChanged()
proc getIsDebugEnabled*(self: View): QVariant {.slot.} =
return newQVariant(self.isDebugEnabled)
QtProperty[QVariant] isDebugEnabled:
read = getIsDebugEnabled
notify = isDebugEnabledChanged
proc toggleDebug*(self: View) {.slot.} =
self.delegate.toggleDebug()
self.setIsDebugEnabled(not self.isDebugEnabled)

View File

@ -2,6 +2,7 @@ import # std libs
json, os
import utils
import chronicles
const GENERATED* = "generated"
const SEED* = "seed"
@ -122,7 +123,7 @@ var NODE_CONFIG* = %* {
#"ListenAddr": ":30304",
"LogEnabled": true,
"LogFile": "geth.log",
"LogLevel": "INFO",
"LogLevel": $LogLevel.INFO,
"MailserversConfig": {
"Enabled": true
},

View File

@ -189,7 +189,7 @@ proc prepareAccountSettingsJsonObject(self: Service, account: GeneratedAccountDt
"wallet-root-address": account.derivedAccounts.walletRoot.address,
"preview-privacy?": true,
"signing-phrase": generateSigningPhrase(3),
"log-level": "INFO",
"log-level": $LogLevel.INFO,
"latest-derived-path": 0,
"networks/networks": DEFAULT_NETWORKS,
"currency": "usd",

View File

@ -87,4 +87,17 @@ method toggleTelemetry*(self: Service) =
method isTelemetryEnabled*(self: Service): bool =
let telemetryServerUrl = status_go_settings.getSetting[string](Setting.TelemetryServerUrl)
return telemetryServerUrl != ""
return telemetryServerUrl != ""
method toggleDebug*(self: Service) =
var nodeConfig = status_go_settings.getNodeConfig()
if nodeConfig["LogLevel"].getStr() == $LogLevel.INFO:
nodeConfig["LogLevel"] = newJString($LogLevel.DEBUG)
else:
nodeConfig["LogLevel"] = newJString($LogLevel.INFO)
discard status_go_settings.saveSetting(Setting.NodeConfig, nodeConfig)
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported
method isDebugEnabled*(self: Service): bool =
let nodeConfig = status_go_settings.getNodeConfig()
return nodeConfig["LogLevel"].getStr() != $LogLevel.INFO

View File

@ -53,3 +53,9 @@ method toggleTelemetry*(self: ServiceInterface) {.base.} =
method isTelemetryEnabled*(self: ServiceInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")
method toggleDebug*(self: ServiceInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method isDebugEnabled*(self: ServiceInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -14,6 +14,8 @@ QtObject {
property var profileModelInst: profileModel
property var profileModuleInst: profileModule
property bool isDebugEnabled: profileSectionModule.isDebugEnabled
property var activeCommunity: chatsModelInst.communities.activeCommunity
function copyToClipboard(text) {

View File

@ -273,6 +273,17 @@ StatusPopupMenu {
enabled: isCurrentUser && !hideEmojiPicker && !emojiOnly && !isProfile && !isRightClickOnImage
}
StatusMenuItem {
id: copyMessageIdAction
text: qsTr("Copy Message Id")
icon.name: "chat"
enabled: store.isDebugEnabled
onTriggered: {
root.store.chatsModelInst.copyToClipboard(SelectedMessage.messageId)
close()
}
}
StatusMenuItem {
id: pinAction
text: {

View File

@ -416,6 +416,15 @@ ScrollView {
openPopup(enableTelemetryConfirmationDialogComponent, {light: false})
}
}
StatusSettingsLineButton {
text: qsTr("Debug")
isSwitch: true
switchChecked: root.store.profileModuleInst.isDebugEnabled
onClicked: {
openPopup(enableDebugComponent)
}
}
}
NetworksModal {
@ -444,6 +453,26 @@ ScrollView {
}
}
Component {
id: enableDebugComponent
ConfirmationDialog {
property bool mode: false
id: confirmDialog
showCancelButton: true
confirmationText: qsTr("Are you sure you want to %1 debug mode? The app will be restarted for this change to take effect.").arg(root.store.profileModuleInst.isDebugEnabled ?
qsTr("disable") :
qsTr("enable"))
onConfirmButtonClicked: {
root.store.profileModuleInst.toggleDebug()
close()
}
onCancelButtonClicked: {
close()
}
}
}
ConfirmationDialog {
id: confirmationPopup
property string settingsProp: ""