refactor(@desktop/settings-advanced): hook to the toggled experimental features from the advanced tab added

This commit is contained in:
Sale Djenic 2021-12-24 09:24:26 +01:00 committed by Sale Djenic
parent 7ea85097df
commit a6b8fbe4b3
15 changed files with 184 additions and 73 deletions

View File

@ -0,0 +1,11 @@
from ../modules/shared_models/section_item import SectionType
import eventemitter
export SectionType
type
ToggleSectionArgs* = ref object of Args
sectionType*: SectionType
const TOGGLE_SECTION* = "toggleSection"

View File

@ -1,6 +1,6 @@
import ../shared_models/section_item, controller_interface, io_interface, chronicles
import ../../global/global_singleton
import ../../global/app_signals
import ../../../app_service/service/settings/service_interface as settings_service
import ../../../app_service/service/keychain/service as keychain_service
import ../../../app_service/service/accounts/service_interface as accounts_service
@ -87,16 +87,9 @@ method init*(self: Controller) =
self.messageService
)
self.events.on("sectionAvailabilityChanged") do(e:Args):
## We will receive here a signal with two fields:
## sectionType: int
## enabled: bool
##
## Then we only need to do something like:
## if(enabled):
## self.delegate.enableSection(sectionType)
## else:
## self.delegate.disableSection(sectionType)
self.events.on(TOGGLE_SECTION) do(e:Args):
let args = ToggleSectionArgs(e)
self.delegate.toggleSection(args.sectionType)
discard
method getJoinedCommunities*(self: Controller): seq[CommunityDto] =

View File

@ -2,6 +2,7 @@ import NimQml, Tables
import io_interface, view, controller, ../shared_models/section_item, ../shared_models/section_model
import ../../global/app_sections_config as conf
import ../../global/app_signals
import ../../global/global_singleton
import chat_section/module as chat_section_module
@ -415,11 +416,29 @@ method activeSectionSet*[T](self: Module[T], sectionId: string) =
self.notifySubModulesAboutChange(sectionId)
method enableSection*[T](self: Module[T], sectionType: SectionType) =
self.view.model().enableSection(sectionType)
proc setSectionAvailability[T](self: Module[T], sectionType: SectionType, available: bool) =
if(available):
self.view.model().enableSection(sectionType)
else:
self.view.model().disableSection(sectionType)
method disableSection*[T](self: Module[T], sectionType: SectionType) =
self.view.disableSection(sectionType)
method toggleSection*[T](self: Module[T], sectionType: SectionType) =
if (sectionType == SectionType.Wallet):
let enabled = singletonInstance.localAccountSensitiveSettings.getIsWalletEnabled()
self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setIsWalletEnabled(not enabled)
elif (sectionType == SectionType.Browser):
let enabled = singletonInstance.localAccountSensitiveSettings.getIsBrowserEnabled()
self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setIsBrowserEnabled(not enabled)
elif (sectionType == SectionType.Community):
let enabled = singletonInstance.localAccountSensitiveSettings.getCommunitiesEnabled()
self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setCommunitiesEnabled(not enabled)
elif (sectionType == SectionType.NodeManagement):
let enabled = singletonInstance.localAccountSensitiveSettings.getNodeManagementEnabled()
self.setSectionAvailability(sectionType, not enabled)
singletonInstance.localAccountSensitiveSettings.setNodeManagementEnabled(not enabled)
method setUserStatus*[T](self: Module[T], status: bool) =
self.controller.setUserStatus(status)

View File

@ -12,10 +12,7 @@ method emitStoringPasswordSuccess*(self: AccessInterface) {.base.} =
method activeSectionSet*(self: AccessInterface, sectionId: string) {.base.} =
raise newException(ValueError, "No implementation available")
method enableSection*(self: AccessInterface, sectionType: SectionType) {.base.} =
raise newException(ValueError, "No implementation available")
method disableSection*(self: AccessInterface, sectionType: SectionType) {.base.} =
method toggleSection*(self: AccessInterface, sectionType: SectionType) {.base.} =
raise newException(ValueError, "No implementation available")
method communityJoined*(self: AccessInterface, community: CommunityDto, events: EventEmitter,

View File

@ -3,9 +3,12 @@ import controller_interface
import io_interface
import ../../../../core/fleets/fleet_configuration
import ../../../../global/app_signals
import ../../../../../app_service/service/settings/service_interface as settings_service
import ../../../../../app_service/service/node_configuration/service_interface as node_configuration_service
import eventemitter
export controller_interface
logScope:
@ -14,13 +17,16 @@ logScope:
type
Controller* = ref object of controller_interface.AccessInterface
delegate: io_interface.AccessInterface
events: EventEmitter
settingsService: settings_service.ServiceInterface
nodeConfigurationService: node_configuration_service.ServiceInterface
proc newController*(delegate: io_interface.AccessInterface, settingsService: settings_service.ServiceInterface,
proc newController*(delegate: io_interface.AccessInterface, events: EventEmitter,
settingsService: settings_service.ServiceInterface,
nodeConfigurationService: node_configuration_service.ServiceInterface): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.settingsService = settingsService
result.nodeConfigurationService = nodeConfigurationService
@ -146,4 +152,16 @@ method addCustomNetwork*(self: Controller, network: settings_service.Network) =
error "an error occurred, we couldn't add a custom network"
return
self.delegate.onCustomNetworkAdded(network)
self.delegate.onCustomNetworkAdded(network)
method toggleWalletSection*(self: Controller) =
self.events.emit(TOGGLE_SECTION, ToggleSectionArgs(sectionType: SectionType.Wallet))
method toggleBrowserSection*(self: Controller) =
self.events.emit(TOGGLE_SECTION, ToggleSectionArgs(sectionType: SectionType.Browser))
method toggleCommunitySection*(self: Controller) =
self.events.emit(TOGGLE_SECTION, ToggleSectionArgs(sectionType: SectionType.Community))
method toggleNodeManagementSection*(self: Controller) =
self.events.emit(TOGGLE_SECTION, ToggleSectionArgs(sectionType: SectionType.NodeManagement))

View File

@ -56,4 +56,16 @@ method getCustomNetworks*(self: AccessInterface): seq[settings_service_type.Netw
raise newException(ValueError, "No implementation available")
method addCustomNetwork*(self: AccessInterface, network: Network) {.base.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
method toggleWalletSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleBrowserSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleCommunitySection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleNodeManagementSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -8,6 +8,8 @@ import ../../../../global/global_singleton
import ../../../../../app_service/service/settings/service_interface as settings_service
import ../../../../../app_service/service/node_configuration/service_interface as node_configuration_service
import eventemitter
export io_interface
logScope:
@ -21,13 +23,14 @@ type
controller: controller.AccessInterface
moduleLoaded: bool
proc newModule*(delegate: delegate_interface.AccessInterface, settingsService: settings_service.ServiceInterface,
proc newModule*(delegate: delegate_interface.AccessInterface, events: EventEmitter,
settingsService: settings_service.ServiceInterface,
nodeConfigurationService: node_configuration_service.ServiceInterface): Module =
result = Module()
result.delegate = delegate
result.view = view.newView(result)
result.viewVariant = newQVariant(result.view)
result.controller = controller.newController(result, settingsService, nodeConfigurationService)
result.controller = controller.newController(result, events, settingsService, nodeConfigurationService)
result.moduleLoaded = false
method delete*(self: Module) =
@ -139,4 +142,16 @@ method addCustomNetwork*(self: Module, name: string, endpoint: string, networkId
self.controller.addCustomNetwork(network)
method onCustomNetworkAdded*(self: Module, network: settings_service.Network) =
self.view.customNetworksModel().add(network.id, network.name)
self.view.customNetworksModel().add(network.id, network.name)
method toggleWalletSection*(self: Module) =
self.controller.toggleWalletSection()
method toggleBrowserSection*(self: Module) =
self.controller.toggleBrowserSection()
method toggleCommunitySection*(self: Module) =
self.controller.toggleCommunitySection()
method toggleNodeManagementSection*(self: Module) =
self.controller.toggleNodeManagementSection()

View File

@ -51,4 +51,16 @@ method toggleDebug*(self: AccessInterface) {.base.} =
method addCustomNetwork*(self: AccessInterface, name: string, endpoint: string, networkId: int, networkType: string)
{.slot.} =
raise newException(ValueError, "No implementation available")
raise newException(ValueError, "No implementation available")
method toggleWalletSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleBrowserSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleCommunitySection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method toggleNodeManagementSection*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -140,4 +140,16 @@ QtObject:
notify = customNetworksModelChanged
proc addCustomNetwork*(self: View, name: string, endpoint: string, networkId: int, networkType: string) {.slot.} =
self.delegate.addCustomNetwork(name, endpoint, networkId, networkType)
self.delegate.addCustomNetwork(name, endpoint, networkId, networkType)
proc toggleWalletSection*(self: View) {.slot.} =
self.delegate.toggleWalletSection()
proc toggleBrowserSection*(self: View) {.slot.} =
self.delegate.toggleBrowserSection()
proc toggleCommunitySection*(self: View) {.slot.} =
self.delegate.toggleCommunitySection()
proc toggleNodeManagementSection*(self: View) {.slot.} =
self.delegate.toggleNodeManagementSection()

View File

@ -66,7 +66,7 @@ proc newModule*[T](delegate: T,
result.mnemonicModule = mnemonic_module.newModule(result, mnemonicService)
result.privacyModule = privacy_module.newModule(result, privacyService, accountsService)
result.aboutModule = about_module.newModule(result, events, aboutService)
result.advancedModule = advanced_module.newModule(result, settingsService, nodeConfigurationService)
result.advancedModule = advanced_module.newModule(result, events, settingsService, nodeConfigurationService)
singletonInstance.engine.setRootContextProperty("profileSectionModule", result.viewVariant)

View File

@ -90,16 +90,6 @@ QtObject:
let item = self.model.getItemBySectionType(sectionType.SectionType)
self.delegate.setActiveSection(item)
proc enableSection*(self: View, sectionType: SectionType) =
# Since enable/disable section is possible only from the `Profile` tab, there is no need for setting
# `activeSection` in this moment, as it will be in any case set to `ProfileSettings` type.
self.model.enableSection(sectionType)
proc disableSection*(self: View, sectionType: SectionType) =
# Since enable/disable section is possible only from the `Profile` tab, there is no need for setting
# `activeSection` in this moment, as it will be in any case set to `ProfileSettings` type.
self.model.disableSection(sectionType)
proc setUserStatus*(self: View, status: bool) {.slot.} =
self.delegate.setUserStatus(status)

View File

@ -143,6 +143,8 @@ QtObject:
self.items[i].active = true
self.dataChanged(index, index, @[ModelRole.Active.int])
proc sectionVisibilityUpdated*(self: SectionModel) {.signal.}
proc enableDisableSection(self: SectionModel, sectionType: SectionType, value: bool) =
if(sectionType != SectionType.Community):
for i in 0 ..< self.items.len:
@ -165,6 +167,10 @@ QtObject:
let bottomIndex = self.createIndex(bottomInd, 0, nil)
self.dataChanged(topIndex, bottomIndex, @[ModelRole.Enabled.int])
# This signal is emitted to update buttons visibility in the left navigation bar,
# `dataChanged` signal doesn't do the job because of `DelegateModel` used in `StatusAppNavBar` component
self.sectionVisibilityUpdated()
proc enableSection*(self: SectionModel, sectionType: SectionType) =
self.enableDisableSection(sectionType, true)

View File

@ -21,6 +21,17 @@ QtObject {
property bool isWakuV2: root.fleet === Constants.waku_prod ||
root.fleet === Constants.waku_test
readonly property QtObject experimentalFeatures: QtObject {
readonly property string wallet: "wallet"
readonly property string browser: "browser"
readonly property string communities: "communities"
readonly property string activityCenter: "activityCenter"
readonly property string nodeManagement: "nodeManagement"
readonly property string onlineUsers: "onlineUsers"
readonly property string gifWidget: "gifWidget"
readonly property string keycard: "keycard"
}
function logDir() {
return root.advancedModule.logDir()
}
@ -56,4 +67,31 @@ QtObject {
function addCustomNetwork(name, endpoint, networkId, networkType) {
root.advancedModule.addCustomNetwork(name, endpoint, networkId, networkType)
}
function toggleExperimentalFeature(feature) {
if (feature === experimentalFeatures.wallet) {
advancedModule.toggleWalletSection()
}
else if (feature === experimentalFeatures.browser) {
advancedModule.toggleBrowserSection()
}
else if (feature === experimentalFeatures.communities) {
advancedModule.toggleCommunitySection()
}
else if (feature === experimentalFeatures.activityCenter) {
localAccountSensitiveSettings.isActivityCenterEnabled = !localAccountSensitiveSettings.isActivityCenterEnabled
}
else if (feature === experimentalFeatures.nodeManagement) {
advancedModule.toggleNodeManagementSection()
}
else if (feature === experimentalFeatures.onlineUsers) {
localAccountSensitiveSettings.showOnlineUsers = !localAccountSensitiveSettings.showOnlineUsers
}
else if (feature === experimentalFeatures.gifWidget) {
localAccountSensitiveSettings.isGifWidgetEnabled = !localAccountSensitiveSettings.isGifWidgetEnabled
}
else if (feature === experimentalFeatures.keycard) {
localAccountSettings.isKeycardEnabled = !localAccountSettings.isKeycardEnabled
}
}
}

View File

@ -16,8 +16,6 @@ import "../panels"
ScrollView {
id: root
property bool isWakuV2: store.fleet == Constants.waku_prod || store.fleet === Constants.waku_test
property var store
property int profileContentWidth
height: parent.height
@ -116,25 +114,10 @@ ScrollView {
switchChecked: localAccountSensitiveSettings.isWalletEnabled
onClicked: {
if (!localAccountSensitiveSettings.isWalletEnabled) {
confirmationPopup.settingsProp = "isWalletEnabled"
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.wallet
confirmationPopup.open()
} else {
localAccountSensitiveSettings.isWalletEnabled = false
}
}
}
// TODO: replace with StatusQ component
StatusSettingsLineButton {
text: qsTr("Wallet v2 - do not use, under active development")
isSwitch: true
switchChecked: localAccountSensitiveSettings.isWalletV2Enabled
onClicked: {
if (!localAccountSensitiveSettings.isWalletV2Enabled) {
confirmationPopup.settingsProp = "isWalletV2Enabled"
confirmationPopup.open()
} else {
localAccountSensitiveSettings.isWalletV2Enabled = false
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.wallet)
}
}
}
@ -147,10 +130,10 @@ ScrollView {
switchChecked: localAccountSensitiveSettings.isBrowserEnabled
onClicked: {
if (!localAccountSensitiveSettings.isBrowserEnabled) {
confirmationPopup.settingsProp = "isBrowserEnabled"
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.browser
confirmationPopup.open()
} else {
localAccountSensitiveSettings.isBrowserEnabled = false
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.browser)
}
}
}
@ -163,10 +146,10 @@ ScrollView {
switchChecked: localAccountSensitiveSettings.communitiesEnabled
onClicked: {
if (!localAccountSensitiveSettings.communitiesEnabled) {
confirmationPopup.settingsProp = "communitiesEnabled"
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.communities
confirmationPopup.open()
} else {
localAccountSensitiveSettings.communitiesEnabled = false
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.communities)
}
}
}
@ -179,10 +162,10 @@ ScrollView {
switchChecked: localAccountSensitiveSettings.isActivityCenterEnabled
onClicked: {
if (!localAccountSensitiveSettings.isActivityCenterEnabled) {
confirmationPopup.settingsProp = "isActivityCenterEnabled"
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.activityCenter
confirmationPopup.open()
} else {
localAccountSensitiveSettings.isActivityCenterEnabled = false
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.activityCenter)
}
}
}
@ -195,10 +178,10 @@ ScrollView {
switchChecked: localAccountSensitiveSettings.nodeManagementEnabled
onClicked: {
if (!localAccountSensitiveSettings.nodeManagementEnabled) {
confirmationPopup.settingsProp = "nodeManagementEnabled"
confirmationPopup.experimentalFeature = root.advancedStore.experimentalFeatures.nodeManagement
confirmationPopup.open()
} else {
localAccountSensitiveSettings.nodeManagementEnabled = false
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.nodeManagement)
}
}
}
@ -211,7 +194,7 @@ ScrollView {
isSwitch: true
switchChecked: localAccountSensitiveSettings.showOnlineUsers
onClicked: {
localAccountSensitiveSettings.showOnlineUsers = !localAccountSensitiveSettings.showOnlineUsers
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.onlineUsers)
}
}
@ -222,7 +205,7 @@ ScrollView {
isSwitch: true
switchChecked: localAccountSensitiveSettings.isGifWidgetEnabled
onClicked: {
localAccountSensitiveSettings.isGifWidgetEnabled = !localAccountSensitiveSettings.isGifWidgetEnabled
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.gifWidget)
}
}
@ -233,7 +216,7 @@ ScrollView {
isSwitch: true
switchChecked: localAccountSettings.isKeycardEnabled
onClicked: {
localAccountSettings.isKeycardEnabled = !localAccountSettings.isKeycardEnabled
root.advancedStore.toggleExperimentalFeature(root.advancedStore.experimentalFeatures.keycard)
}
}
@ -510,16 +493,15 @@ ScrollView {
ConfirmationDialog {
id: confirmationPopup
property string settingsProp: ""
property string experimentalFeature: ""
showCancelButton: true
//% "This feature is experimental and is meant for testing purposes by core contributors and the community. It's not meant for real use and makes no claims of security or integrity of funds or data. Use at your own risk."
confirmationText: (settingsProp === "isWalletV2Enabled" ? qsTr("<b>--DO NOT USE - UNDER ACTIVE DEVELOPMENT--</b>\n") : "") +
qsTrId("this-feature-is-experimental-and-is-meant-for-testing-purposes-by-core-contributors-and-the-community--it-s-not-meant-for-real-use-and-makes-no-claims-of-security-or-integrity-of-funds-or-data--use-at-your-own-risk-")
confirmationText: qsTrId("this-feature-is-experimental-and-is-meant-for-testing-purposes-by-core-contributors-and-the-community--it-s-not-meant-for-real-use-and-makes-no-claims-of-security-or-integrity-of-funds-or-data--use-at-your-own-risk-")
//% "I understand"
confirmButtonLabel: qsTrId("i-understand")
onConfirmButtonClicked: {
localAccountSensitiveSettings[settingsProp] = true
settingsProp = ""
root.advancedStore.toggleExperimentalFeature(experimentalFeature)
experimentalFeature = ""
close()
}

View File

@ -176,6 +176,12 @@ Item {
communityTypeValue: Constants.appSection.community
sectionModel: mainModule.sectionsModel
Component.onCompleted: {
mainModule.sectionsModel.sectionVisibilityUpdated.connect(function(){
triggerUpdate()
})
}
property bool communityAdded: false
onAboutToUpdateFilteredRegularModel: {