From 8c3c4d76072ec9c5fa96522dc017430b68e07dd9 Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Wed, 20 Oct 2021 13:06:29 +0200 Subject: [PATCH] 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. --- src/app/boot/app_controller.nim | 16 +---- src/app/profile/core.nim | 6 +- src/app/profile/view.nim | 23 ------- .../service/local_settings/service.nim | 67 ------------------- 4 files changed, 2 insertions(+), 110 deletions(-) delete mode 100644 src/app_service/service/local_settings/service.nim diff --git a/src/app/boot/app_controller.nim b/src/app/boot/app_controller.nim index 0b24383952..a80f249453 100644 --- a/src/app/boot/app_controller.nim +++ b/src/app/boot/app_controller.nim @@ -1,6 +1,5 @@ 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/accounts/service as accounts_service import ../../app_service/service/contacts/service as contact_service @@ -61,7 +60,6 @@ type AppController* = ref object of RootObj appService: AppService # Services - localSettingsService: local_settings_service.Service keychainService: keychain_service.Service accountsService: accounts_service.Service contactService: contact_service.Service @@ -118,16 +116,6 @@ proc newAppController*(appService: AppService): AppController = result = AppController() result.appService = appService # 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.settingService = setting_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 # appropriate place or removed: - result.profile = profile.newController(appService.status, appService, - result.localSettingsService, changeLanguage) + result.profile = profile.newController(appService.status, appService, changeLanguage) result.connect() ################################################# @@ -215,7 +202,6 @@ proc delete*(self: AppController) = self.localAccountSettingsVariant.delete self.localAccountSensitiveSettingsVariant.delete - self.localSettingsService.delete self.accountsService.delete self.contactService.delete self.chatService.delete diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 98e3f81562..4ef64bc5b9 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -9,7 +9,6 @@ import status/wallet import status/types/[account, transaction, setting, profile, mailserver] import ../../app_service/[main] import ../../app_service/tasks/marathon/mailserver/events -import ../../app_service/service/local_settings/service as local_settings_service import eventemitter import view import views/[ens_manager, devices, network, mailservers, contacts, muted_chats] @@ -23,15 +22,13 @@ type ProfileController* = ref object variant*: QVariant status: Status appService: AppService - localSettingsService: local_settings_service.Service proc newController*(status: Status, appService: AppService, - localSettingsService: local_settings_service.Service, changeLanguage: proc(locale: string)): ProfileController = result = ProfileController() result.status = status result.appService = appService - result.view = newProfileView(status, appService, localSettingsService, changeLanguage) + result.view = newProfileView(status, appService, changeLanguage) result.variant = newQVariant(result.view) proc delete*(self: ProfileController) = @@ -62,7 +59,6 @@ proc init*(self: ProfileController, account: Account) = self.view.devices.addDevices(status_devices.getAllDevices()) self.view.devices.setDeviceSetup(status_devices.isDeviceSetup()) self.view.setNewProfile(profile) - self.view.setSettingsFile(profile.id) self.view.network.setNetwork(network) self.view.ens.init() self.view.initialized() diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index 82ff136be2..678af9b2ad 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -17,7 +17,6 @@ import status/notifications/[os_notifications] import ../chat/views/channels_list import ../../constants import ../../app_service/[main] -import ../../app_service/service/local_settings/service as local_settings_service import ../utils/image_utils import ../../constants @@ -38,7 +37,6 @@ QtObject: network*: NetworkView status*: Status appService: AppService - localSettingsService: local_settings_service.Service changeLanguage*: proc(locale: string) ens*: EnsManager @@ -60,7 +58,6 @@ QtObject: self.QObject.delete proc newProfileView*(status: Status, appService: AppService, - localSettingsService: local_settings_service.Service, changeLanguage: proc(locale: string)): ProfileView = new(result, delete) result = ProfileView() @@ -78,7 +75,6 @@ QtObject: result.changeLanguage = changeLanguage result.status = status result.appService = appService - result.localSettingsService = localSettingsService result.setup proc initialized*(self: ProfileView) {.signal.} @@ -192,31 +188,12 @@ QtObject: QtProperty[QVariant] picture: read = getProfilePicture - proc getGlobalSettingsFile*(self: ProfileView): string {.slot.} = - self.localSettingsService.getGlobalSettingsFilePath - - QtProperty[string] globalSettingsFile: - read = getGlobalSettingsFile - proc getMutedChats*(self: ProfileView): QVariant {.slot.} = newQVariant(self.mutedChats) QtProperty[QVariant] mutedChats: 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.} = if (sendUserStatus == self.profile.sendUserStatus): return diff --git a/src/app_service/service/local_settings/service.nim b/src/app_service/service/local_settings/service.nim deleted file mode 100644 index a8b9dce8b6..0000000000 --- a/src/app_service/service/local_settings/service.nim +++ /dev/null @@ -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) \ No newline at end of file