refactor(@desktop/general): code cleaned app after accountSettings and globalSettings moved to Nim

Since we have `accountSettings` and `globalSettings` available on both sides Nim
and qml, we don't need `src/app_service/service/local_settings/service` any more.
Indeed it has never been a service logically, but we made it as service according to
the old code base.

Accessing any of local setting instances is easy doable from any part of the app just
using `singletonInstance` and appropriate settings from it.
This commit is contained in:
Sale Djenic 2021-10-20 13:06:29 +02:00 committed by Iuri Matias
parent 3f6bb66536
commit 8c3c4d7607
4 changed files with 2 additions and 110 deletions

View File

@ -1,6 +1,5 @@
import NimQml, os, strformat import NimQml, os, strformat
import ../../app_service/service/local_settings/service as local_settings_service
import ../../app_service/service/keychain/service as keychain_service import ../../app_service/service/keychain/service as keychain_service
import ../../app_service/service/accounts/service as accounts_service import ../../app_service/service/accounts/service as accounts_service
import ../../app_service/service/contacts/service as contact_service import ../../app_service/service/contacts/service as contact_service
@ -61,7 +60,6 @@ type
AppController* = ref object of RootObj AppController* = ref object of RootObj
appService: AppService appService: AppService
# Services # Services
localSettingsService: local_settings_service.Service
keychainService: keychain_service.Service keychainService: keychain_service.Service
accountsService: accounts_service.Service accountsService: accounts_service.Service
contactService: contact_service.Service contactService: contact_service.Service
@ -118,16 +116,6 @@ proc newAppController*(appService: AppService): AppController =
result = AppController() result = AppController()
result.appService = appService result.appService = appService
# Services # Services
#################################################
# Since localSettingsService is a product of old architecture, and used only to
# manage `Settings` component (global and profile) in qml, this should be removed
# at the end of refactroing process and moved to the same approach we use for
# LocalAccountSettings, and that will be maintained only on the Nim side. There
# should not be two instances maintain the same settings.
result.localSettingsService = local_settings_service.newService()
#################################################
result.keychainService = keychain_service.newService(appService.status.events) result.keychainService = keychain_service.newService(appService.status.events)
result.settingService = setting_service.newService() result.settingService = setting_service.newService()
result.accountsService = accounts_service.newService() result.accountsService = accounts_service.newService()
@ -180,8 +168,7 @@ proc newAppController*(appService: AppService): AppController =
################################################# #################################################
# At the end of refactoring this will be moved to # At the end of refactoring this will be moved to
# appropriate place or removed: # appropriate place or removed:
result.profile = profile.newController(appService.status, appService, result.profile = profile.newController(appService.status, appService, changeLanguage)
result.localSettingsService, changeLanguage)
result.connect() result.connect()
################################################# #################################################
@ -215,7 +202,6 @@ proc delete*(self: AppController) =
self.localAccountSettingsVariant.delete self.localAccountSettingsVariant.delete
self.localAccountSensitiveSettingsVariant.delete self.localAccountSensitiveSettingsVariant.delete
self.localSettingsService.delete
self.accountsService.delete self.accountsService.delete
self.contactService.delete self.contactService.delete
self.chatService.delete self.chatService.delete

View File

@ -9,7 +9,6 @@ import status/wallet
import status/types/[account, transaction, setting, profile, mailserver] import status/types/[account, transaction, setting, profile, mailserver]
import ../../app_service/[main] import ../../app_service/[main]
import ../../app_service/tasks/marathon/mailserver/events import ../../app_service/tasks/marathon/mailserver/events
import ../../app_service/service/local_settings/service as local_settings_service
import eventemitter import eventemitter
import view import view
import views/[ens_manager, devices, network, mailservers, contacts, muted_chats] import views/[ens_manager, devices, network, mailservers, contacts, muted_chats]
@ -23,15 +22,13 @@ type ProfileController* = ref object
variant*: QVariant variant*: QVariant
status: Status status: Status
appService: AppService appService: AppService
localSettingsService: local_settings_service.Service
proc newController*(status: Status, appService: AppService, proc newController*(status: Status, appService: AppService,
localSettingsService: local_settings_service.Service,
changeLanguage: proc(locale: string)): ProfileController = changeLanguage: proc(locale: string)): ProfileController =
result = ProfileController() result = ProfileController()
result.status = status result.status = status
result.appService = appService result.appService = appService
result.view = newProfileView(status, appService, localSettingsService, changeLanguage) result.view = newProfileView(status, appService, changeLanguage)
result.variant = newQVariant(result.view) result.variant = newQVariant(result.view)
proc delete*(self: ProfileController) = proc delete*(self: ProfileController) =
@ -62,7 +59,6 @@ proc init*(self: ProfileController, account: Account) =
self.view.devices.addDevices(status_devices.getAllDevices()) self.view.devices.addDevices(status_devices.getAllDevices())
self.view.devices.setDeviceSetup(status_devices.isDeviceSetup()) self.view.devices.setDeviceSetup(status_devices.isDeviceSetup())
self.view.setNewProfile(profile) self.view.setNewProfile(profile)
self.view.setSettingsFile(profile.id)
self.view.network.setNetwork(network) self.view.network.setNetwork(network)
self.view.ens.init() self.view.ens.init()
self.view.initialized() self.view.initialized()

View File

@ -17,7 +17,6 @@ import status/notifications/[os_notifications]
import ../chat/views/channels_list import ../chat/views/channels_list
import ../../constants import ../../constants
import ../../app_service/[main] import ../../app_service/[main]
import ../../app_service/service/local_settings/service as local_settings_service
import ../utils/image_utils import ../utils/image_utils
import ../../constants import ../../constants
@ -38,7 +37,6 @@ QtObject:
network*: NetworkView network*: NetworkView
status*: Status status*: Status
appService: AppService appService: AppService
localSettingsService: local_settings_service.Service
changeLanguage*: proc(locale: string) changeLanguage*: proc(locale: string)
ens*: EnsManager ens*: EnsManager
@ -60,7 +58,6 @@ QtObject:
self.QObject.delete self.QObject.delete
proc newProfileView*(status: Status, appService: AppService, proc newProfileView*(status: Status, appService: AppService,
localSettingsService: local_settings_service.Service,
changeLanguage: proc(locale: string)): ProfileView = changeLanguage: proc(locale: string)): ProfileView =
new(result, delete) new(result, delete)
result = ProfileView() result = ProfileView()
@ -78,7 +75,6 @@ QtObject:
result.changeLanguage = changeLanguage result.changeLanguage = changeLanguage
result.status = status result.status = status
result.appService = appService result.appService = appService
result.localSettingsService = localSettingsService
result.setup result.setup
proc initialized*(self: ProfileView) {.signal.} proc initialized*(self: ProfileView) {.signal.}
@ -192,31 +188,12 @@ QtObject:
QtProperty[QVariant] picture: QtProperty[QVariant] picture:
read = getProfilePicture read = getProfilePicture
proc getGlobalSettingsFile*(self: ProfileView): string {.slot.} =
self.localSettingsService.getGlobalSettingsFilePath
QtProperty[string] globalSettingsFile:
read = getGlobalSettingsFile
proc getMutedChats*(self: ProfileView): QVariant {.slot.} = proc getMutedChats*(self: ProfileView): QVariant {.slot.} =
newQVariant(self.mutedChats) newQVariant(self.mutedChats)
QtProperty[QVariant] mutedChats: QtProperty[QVariant] mutedChats:
read = getMutedChats read = getMutedChats
proc settingsFileChanged*(self: ProfileView) {.signal.}
proc getSettingsFile*(self: ProfileView): string {.slot.} =
self.localSettingsService.getSettingsFilePath
proc setSettingsFile*(self: ProfileView, pubKey: string) =
self.localSettingsService.updateSettingsFilePath(pubKey)
self.settingsFileChanged()
QtProperty[string] settingsFile:
read = getSettingsFile
notify = settingsFileChanged
proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} = proc setSendUserStatus*(self: ProfileView, sendUserStatus: bool) {.slot.} =
if (sendUserStatus == self.profile.sendUserStatus): if (sendUserStatus == self.profile.sendUserStatus):
return return

View File

@ -1,67 +0,0 @@
import NimQml, os, chronicles
import ../../../constants
logScope:
topics = "local-settings"
const UNKNOWN_PROFILE = "unknownProfile"
QtObject:
type Service* = ref object of QObject
settingsFilePath: string
settings: QSettings
globalSettingsFilePath: string
globalSettings: QSettings
proc setup(self: Service) =
self.settingsFilePath = os.joinPath(DATADIR, "qt", UNKNOWN_PROFILE)
self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat)
self.globalSettingsFilePath = os.joinPath(DATADIR, "qt", "global")
self.globalSettings = newQSettings(self.globalSettingsFilePath, QSettingsFormat.IniFormat)
self.QObject.setup
proc delete*(self: Service) =
self.settings.delete
self.globalSettings.delete
self.QObject.delete
proc newService*(): Service =
new(result, delete)
result.setup
proc getGlobalSettingsFilePath*(self: Service): string =
return self.globalSettingsFilePath
proc getSettingsFilePath*(self: Service): string =
return self.settingsFilePath
proc updateSettingsFilePath*(self: Service, pubKey: string) =
let unknownSettingsPath = os.joinPath(DATADIR, "qt", UNKNOWN_PROFILE)
if (not unknownSettingsPath.tryRemoveFile):
# Only fails if the file exists and an there was an error removing it
# More info: https://nim-lang.org/docs/os.html#tryRemoveFile%2Cstring
warn "Failed to remove unused settings file", file=unknownSettingsPath
self.settings.delete
self.settingsFilePath = os.joinPath(DATADIR, "qt", pubKey)
self.settings = newQSettings(self.settingsFilePath, QSettingsFormat.IniFormat)
proc setValue*(self: Service, key: string, value: QVariant) =
self.settings.setValue(key, value)
proc getValue*(self: Service, key: string,
defaultValue: QVariant = newQVariant()): QVariant =
self.settings.value(key, defaultValue)
proc removeValue*(self: Service, key: string) =
self.settings.remove(key)
proc setGlobalValue*(self: Service, key: string, value: QVariant) =
self.globalSettings.setValue(key, value)
proc getGlobalValue*(self: Service, key: string,
defaultValue: QVariant = newQVariant()): QVariant =
self.globalSettings.value(key, defaultValue)
proc removeGlobalValue*(self: Service, key: string) =
self.globalSettings.remove(key)