Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save only the settings that are changed #14930

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/app/modules/main/node_section/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ proc init*(self: Controller) =
proc sendRPCMessageRaw*(self: Controller, inputJSON: string): string =
return self.nodeService.sendRPCMessageRaw(inputJSON);

proc isV2LightMode*(self: Controller): bool =
return self.nodeConfigurationService.isV2LightMode()
proc isLightClient*(self: Controller): bool =
return self.nodeConfigurationService.isLightClient()

proc isFullNode*(self: Controller): bool =
return self.nodeConfigurationService.isFullNode()

proc setV2LightMode*(self: Controller, enabled: bool): bool =
return self.nodeConfigurationService.setV2LightMode(enabled)
proc setLightClient*(self: Controller, enabled: bool): bool =
return self.nodeConfigurationService.setLightClient(enabled)

proc getWakuVersion*(self: Controller): int =
return 2
4 changes: 2 additions & 2 deletions src/app/modules/main/node_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ method viewDidLoad*(self: AccessInterface) {.base.} =
method sendRPCMessageRaw*(self: AccessInterface, inputJSON: string): string {.base.} =
raise newException(ValueError, "No implementation available")

method setV2LightMode*(self: AccessInterface, enabled: bool) {.base.} =
method setLightClient*(self: AccessInterface, enabled: bool) {.base.} =
raise newException(ValueError, "No implementation available")

method isV2LightMode*(self: AccessInterface): bool {.base.} =
method isLightClient*(self: AccessInterface): bool {.base.} =
raise newException(ValueError, "No implementation available")

method isFullNode*(self: AccessInterface): bool {.base.} =
Expand Down
8 changes: 4 additions & 4 deletions src/app/modules/main/node_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ method viewDidLoad*(self: Module) =
method sendRPCMessageRaw*(self: Module, inputJSON: string): string =
return self.controller.sendRPCMessageRaw(inputJSON)

method setV2LightMode*(self: Module, enabled: bool) =
if(self.controller.setV2LightMode(enabled)):
method setLightClient*(self: Module, enabled: bool) =
if(self.controller.setLightClient(enabled)):
quit(QuitSuccess) # quits the app TODO: change this to logout instead when supported

method isV2LightMode*(self: Module): bool =
return self.controller.isV2LightMode()
method isLightClient*(self: Module): bool =
return self.controller.isLightClient()

method isFullNode*(self: Module): bool =
return self.controller.isFullNode()
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/node_section/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ QtObject:

proc log*(self: View, logContent: string) {.signal.}

proc getWakuV2LightClient(self: View): bool {.slot.} = self.delegate.isV2LightMode()
proc getWakuV2LightClient(self: View): bool {.slot.} = self.delegate.isLightClient()

QtProperty[bool] WakuV2LightClient:
read = getWakuV2LightClient
notify = initialized

proc setWakuV2LightClient*(self: View, enabled: bool) {.slot.} =
self.delegate.setV2LightMode(enabled)
self.delegate.setLightClient(enabled)
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ proc setMaxLogBackups*(self: Controller, value: int) =
self.delegate.onLogMaxBackupsChanged()

proc getWakuV2LightClientEnabled*(self: Controller): bool =
return self.nodeConfigurationService.getV2LightMode()
return self.nodeConfigurationService.isLightClient()

proc setWakuV2LightClientEnabled*(self: Controller, enabled: bool) =
if (not self.nodeConfigurationService.setV2LightMode(enabled)):
if (not self.nodeConfigurationService.setLightClient(enabled)):
# in the future we may do a call from here to show a popup about this error
error "an error occurred, we couldn't set WakuV2 light client"
return
Expand Down Expand Up @@ -122,7 +122,7 @@ proc isNimbusProxyEnabled*(self: Controller): bool =
proc toggleNimbusProxy*(self: Controller) =
let enabled = self.nodeConfigurationService.isNimbusProxyEnabled()

if(not self.nodeConfigurationService.setNimbusProxyConfig(not enabled)):
if not self.nodeConfigurationService.setNimbusProxyConfigEnabled(not enabled):
Copy link
Contributor

@kounkou kounkou May 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setNimbusProxyConfigEnabled is a setter that returns a boolean, what does it mean 😲 ? See comment below.

Copy link
Contributor Author

@friofry friofry May 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a setter that returns a boolean, what does it mean

Sorry, not sure what you mean. I thought you had added this code. But I guess the purpose here is to handle status-go errors for whatever reason and log it

error "an error occurred, we couldn't toggle nimbus proxy"
return

Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/main/profile_section/waku/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ proc init*(self: Controller) =
proc getAllWakuNodes*(self: Controller): seq[string] =
return self.nodeConfigurationService.getAllWakuNodes()

proc saveNewWakuNode*(self: Controller, nodeAddress: string) =
self.nodeConfigurationService.saveNewWakuNode(nodeAddress)
proc saveNewWakuNode*(self: Controller, nodeAddress: string): bool =
return self.nodeConfigurationService.saveNewWakuNode(nodeAddress)
6 changes: 3 additions & 3 deletions src/app/modules/main/profile_section/waku/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant

method saveNewWakuNode*(self: Module, nodeAddress: string) =
self.controller.saveNewWakuNode(nodeAddress)
let item = initItem(nodeAddress)
self.view.model().addItem(item)
if self.controller.saveNewWakuNode(nodeAddress):
let item = initItem(nodeAddress)
self.view.model().addItem(item)
64 changes: 36 additions & 28 deletions src/app_service/service/node_configuration/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ proc init*(self: Service) =
error "error: ", errDesription
return

proc saveConfiguration(self: Service, configuration: NodeConfigDto): bool =
# FIXME: this method should be removed and the configuration should be updated in the status-go
# (see SetLogLevel, #14643)
if(not self.settingsService.saveNodeConfiguration(configuration.toJsonNode())):
error "error saving node configuration "
return false
self.configuration = configuration
return true

proc getWakuVersion*(self: Service): int =
if self.configuration.WakuConfig.Enabled:
return WAKU_VERSION_1
Expand Down Expand Up @@ -143,11 +134,19 @@ proc getFleetAsString*(self: Service): string =
proc getAllWakuNodes*(self: Service): seq[string] =
return self.wakuNodes

proc saveNewWakuNode*(self: Service, nodeAddress: string) =
var newConfiguration = self.configuration
newConfiguration.ClusterConfig.WakuNodes.add(nodeAddress)
self.configuration = newConfiguration
discard self.saveConfiguration(newConfiguration)
proc saveNewWakuNode*(self: Service, nodeAddress: string): bool =
try:
let response = status_node_config.saveNewWakuNode(nodeAddress)

if not response.error.isNil:
error "failed to add new waku node: ", errDescription = response.error.message
return false

self.configuration.ClusterConfig.WakuNodes.add(nodeAddress)
except Exception as e:
error "error saving new waku node: ", errDescription = e.msg
return false
return true

proc setFleet*(self: Service, fleet: string): bool =
if (not self.settingsService.saveFleet(fleet)):
Expand Down Expand Up @@ -197,13 +196,15 @@ proc setFleet*(self: Service, fleet: string): bool =
error "Could not switch fleet"
return false

proc getV2LightMode*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient
proc setLightClient*(self: Service, enabled: bool): bool =
let response = status_node_config.setLightClient(enabled)

proc setV2LightMode*(self: Service, enabled: bool): bool =
var newConfiguration = self.configuration
newConfiguration.WakuV2Config.LightClient = enabled
return self.saveConfiguration(newConfiguration)
if not response.error.isNil:
error "failed to set light client: ", errDescription = response.error.message
return false

self.configuration.WakuV2Config.LightClient = enabled
return true

proc getLogLevel(self: Service): string =
return self.configuration.LogLevel
Expand Down Expand Up @@ -231,12 +232,13 @@ proc getNimbusProxyConfig(self: Service): bool =
proc isNimbusProxyEnabled*(self: Service): bool =
return self.getNimbusProxyConfig()

proc setNimbusProxyConfig*(self: Service, value: bool): bool =
var newConfiguration = self.configuration
newConfiguration.NimbusProxyConfig.Enabled = value
return self.saveConfiguration(newConfiguration)
proc setNimbusProxyConfigEnabled*(self: Service, enabled: bool): bool =
# FIXME: call status-go API to update NodeConfig
# when this is merged https://github.com/status-im/status-go/pull/4254
self.configuration.NimbusProxyConfig.Enabled = enabled
return true
friofry marked this conversation as resolved.
Show resolved Hide resolved

proc isV2LightMode*(self: Service): bool =
proc isLightClient*(self: Service): bool =
return self.configuration.WakuV2Config.LightClient

proc isFullNode*(self: Service): bool =
Expand All @@ -246,6 +248,12 @@ proc getLogMaxBackups*(self: Service): int =
return self.configuration.LogMaxBackups

proc setMaxLogBackups*(self: Service, value: int): bool =
var newConfiguration = self.configuration
newConfiguration.LogMaxBackups = value
return self.saveConfiguration(newConfiguration)
let response = status_node_config.setMaxLogBackups(value)

if not response.error.isNil:
error "failed to set max log backups: ", errDescription = response.error.message
return false

self.configuration.LogMaxBackups = value
return true

6 changes: 0 additions & 6 deletions src/app_service/service/settings/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,6 @@ QtObject:
proc unpinMailserver*(self: Service, fleet: Fleet): bool =
return self.setPinnedMailserverId("", fleet)

proc saveNodeConfiguration*(self: Service, value: JsonNode): bool =
if(self.saveSetting(KEY_NODE_CONFIG, value)):
self.settings.nodeConfig = value
return true
return false

proc saveAutoMessageEnabled*(self: Service, value: bool): bool =
if(self.saveSetting(KEY_AUTO_MESSAGE_ENABLED, value)):
self.settings.autoMessageEnabled = value
Expand Down
46 changes: 26 additions & 20 deletions src/backend/node_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,31 @@ proc switchFleet*(fleet: string, nodeConfig: JsonNode): RpcResponse[JsonNode] =
raise newException(RpcException, e.msg)

proc enableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
try:
result = core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "enableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)
return core.callPrivateRPC("enableCommunityHistoryArchiveProtocol".prefix, %* [])

proc disableCommunityHistoryArchiveSupport*(): RpcResponse[JsonNode] =
try:
result = core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix)
except RpcException as e:
error "error doing rpc request", methodName = "disableCommunityHistoryArchiveProtocol", exception=e.msg
raise newException(RpcException, e.msg)

proc setLogLevel*(logLevel: LogLevel): RpcResponse[JsonNode] =
try:
let payload = %*[{
"logLevel": $logLevel
}]
result = core.callPrivateRPC("setLogLevel".prefix, payload)
except RpcException as e:
error "error doing rpc request", methodName = "setLogLevel", exception=e.msg
raise newException(RpcException, e.msg)
return core.callPrivateRPC("disableCommunityHistoryArchiveProtocol".prefix, %* [])

proc setLogLevel*(logLevel: LogLevel): RpcResponse[JsonNode] =
let payload = %*[{
"logLevel": $logLevel
}]
result = core.callPrivateRPC("setLogLevel".prefix, payload)

proc setMaxLogBackups*(maxLogBackups: int): RpcResponse[JsonNode] =
let payload = %*[{
"maxLogBackups": maxLogBackups
}]
return core.callPrivateRPC("setMaxLogBackups".prefix, payload)

proc setLightClient*(enabled: bool): RpcResponse[JsonNode] =
let payload = %*[{
"enabled": enabled
}]
return core.callPrivateRPC("setLightClient".prefix, payload)

proc saveNewWakuNode*(nodeAddress: string): RpcResponse[JsonNode] =
let payload = %*[{
"nodeAddress": nodeAddress
}]
return core.callPrivateRPC("saveNewWakuNode".prefix, payload)