2021-10-16 16:42:40 +02:00
|
|
|
import NimQml, os, strformat
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
import ../../app_service/service/local_settings/service as local_settings_service
|
2021-10-16 18:14:08 +02:00
|
|
|
import ../../app_service/service/keychain/service as keychain_service
|
2021-10-12 15:48:09 +02:00
|
|
|
import ../../app_service/service/accounts/service as accounts_service
|
2021-10-06 22:05:13 +02:00
|
|
|
import ../../app_service/service/contacts/service as contact_service
|
|
|
|
import ../../app_service/service/chat/service as chat_service
|
|
|
|
import ../../app_service/service/community/service as community_service
|
2021-10-14 09:58:28 +02:00
|
|
|
import ../../app_service/service/token/service as token_service
|
2021-10-15 10:24:32 +02:00
|
|
|
import ../../app_service/service/transaction/service as transaction_service
|
2021-10-15 11:12:48 +02:00
|
|
|
import ../../app_service/service/collectible/service as collectible_service
|
2021-10-18 13:00:56 +02:00
|
|
|
import ../../app_service/service/wallet_account/service as wallet_account_service
|
2021-10-15 11:12:48 +02:00
|
|
|
|
2021-10-14 09:58:28 +02:00
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
import ../core/local_account_settings
|
2021-10-06 22:05:13 +02:00
|
|
|
import ../modules/startup/module as startup_module
|
|
|
|
import ../modules/main/module as main_module
|
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
import ../core/global_singleton
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-12 15:48:09 +02:00
|
|
|
# This will be removed later once we move to c++ and handle there async things
|
|
|
|
# and improved some services, like EventsService which should implement
|
|
|
|
# provider/subscriber principe:
|
2021-10-06 22:05:13 +02:00
|
|
|
import ../../app_service/[main]
|
2021-10-16 18:14:08 +02:00
|
|
|
import eventemitter
|
|
|
|
import status/[fleet]
|
2021-10-12 15:48:09 +02:00
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
|
|
|
import ../profile/core as profile
|
|
|
|
import status/types/[account]
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
|
|
|
|
var i18nPath = ""
|
|
|
|
if defined(development):
|
|
|
|
i18nPath = joinPath(getAppDir(), "../ui/i18n")
|
|
|
|
elif (defined(windows)):
|
|
|
|
i18nPath = joinPath(getAppDir(), "../resources/i18n")
|
|
|
|
elif (defined(macosx)):
|
|
|
|
i18nPath = joinPath(getAppDir(), "../i18n")
|
|
|
|
elif (defined(linux)):
|
|
|
|
i18nPath = joinPath(getAppDir(), "../i18n")
|
|
|
|
|
|
|
|
var currentLanguageCode: string
|
|
|
|
proc changeLanguage(locale: string) =
|
|
|
|
if (locale == currentLanguageCode):
|
|
|
|
return
|
|
|
|
currentLanguageCode = locale
|
|
|
|
let shouldRetranslate = not defined(linux)
|
2021-10-16 21:54:00 +02:00
|
|
|
singletonInstance.engine.setTranslationPackage(
|
|
|
|
joinPath(i18nPath, fmt"qml_{locale}.qm"), shouldRetranslate)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
AppController* = ref object of RootObj
|
2021-10-12 15:48:09 +02:00
|
|
|
appService: AppService
|
2021-10-06 22:05:13 +02:00
|
|
|
# Services
|
2021-10-16 16:42:40 +02:00
|
|
|
localSettingsService: local_settings_service.Service
|
2021-10-16 18:14:08 +02:00
|
|
|
keychainService: keychain_service.Service
|
2021-10-12 15:48:09 +02:00
|
|
|
accountsService: accounts_service.Service
|
2021-10-06 22:05:13 +02:00
|
|
|
contactService: contact_service.Service
|
|
|
|
chatService: chat_service.Service
|
|
|
|
communityService: community_service.Service
|
2021-10-14 09:58:28 +02:00
|
|
|
tokenService: token_service.Service
|
2021-10-15 10:24:32 +02:00
|
|
|
transactionService: transaction_service.Service
|
2021-10-15 11:12:48 +02:00
|
|
|
collectibleService: collectible_service.Service
|
2021-10-18 13:00:56 +02:00
|
|
|
walletAccountService: wallet_account_service.Service
|
2021-10-14 09:58:28 +02:00
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
# Core
|
|
|
|
localAccountSettings: LocalAccountSettings
|
|
|
|
localAccountSettingsVariant: QVariant
|
2021-10-06 22:05:13 +02:00
|
|
|
mainModule: main_module.AccessInterface
|
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
|
|
|
profile: ProfileController
|
|
|
|
#################################################
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# Forward declaration section
|
|
|
|
proc load*(self: AppController)
|
|
|
|
|
|
|
|
# Startup Module Delegate Interface
|
|
|
|
proc startupDidLoad*(self: AppController)
|
2021-10-15 21:47:43 +02:00
|
|
|
proc userLoggedIn*(self: AppController)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
# Main Module Delegate Interface
|
|
|
|
proc mainDidLoad*(self: AppController)
|
|
|
|
#################################################
|
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
|
|
|
proc connect(self: AppController) =
|
|
|
|
self.appService.status.events.once("loginCompleted") do(a: Args):
|
|
|
|
var args = AccountArgs(a)
|
|
|
|
self.profile.init(args.account)
|
|
|
|
#################################################
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-12 15:48:09 +02:00
|
|
|
proc newAppController*(appService: AppService): AppController =
|
2021-10-06 22:05:13 +02:00
|
|
|
result = AppController()
|
2021-10-12 15:48:09 +02:00
|
|
|
result.appService = appService
|
2021-10-06 22:05:13 +02:00
|
|
|
# Services
|
2021-10-18 10:21:59 +02:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# 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.
|
2021-10-16 16:42:40 +02:00
|
|
|
result.localSettingsService = local_settings_service.newService()
|
2021-10-18 10:21:59 +02:00
|
|
|
#################################################
|
|
|
|
|
|
|
|
result.keychainService = keychain_service.newService(appService.status.events)
|
2021-10-12 15:48:09 +02:00
|
|
|
result.accountsService = accounts_service.newService()
|
2021-10-06 22:05:13 +02:00
|
|
|
result.contactService = contact_service.newService()
|
|
|
|
result.chatService = chat_service.newService()
|
2021-10-18 12:07:18 +02:00
|
|
|
result.communityService = community_service.newService(result.chatService)
|
2021-10-14 09:58:28 +02:00
|
|
|
result.tokenService = token_service.newService()
|
2021-10-15 10:24:32 +02:00
|
|
|
result.transactionService = transaction_service.newService()
|
2021-10-15 11:12:48 +02:00
|
|
|
result.collectibleService = collectible_service.newService()
|
2021-10-18 13:00:56 +02:00
|
|
|
result.walletAccountService = wallet_account_service.newService()
|
|
|
|
|
2021-10-14 09:58:28 +02:00
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
# Core
|
2021-10-18 10:21:59 +02:00
|
|
|
result.localAccountSettingsVariant = newQVariant(
|
|
|
|
singletonInstance.localAccountSettings)
|
2021-10-06 22:05:13 +02:00
|
|
|
# Modules
|
2021-10-16 18:14:08 +02:00
|
|
|
result.startupModule = startup_module.newModule[AppController](result,
|
2021-10-18 10:21:59 +02:00
|
|
|
appService.status.events, appService.status.fleet, result.keychainService,
|
|
|
|
result.accountsService)
|
2021-10-15 10:24:32 +02:00
|
|
|
result.mainModule = main_module.newModule[AppController](
|
|
|
|
result,
|
|
|
|
appService.status.events,
|
|
|
|
result.keychainService,
|
|
|
|
result.accountsService,
|
|
|
|
result.chatService,
|
|
|
|
result.communityService,
|
|
|
|
result.tokenService,
|
2021-10-15 11:12:48 +02:00
|
|
|
result.transactionService,
|
2021-10-18 13:00:56 +02:00
|
|
|
result.collectibleService,
|
|
|
|
result.walletAccountService
|
2021-10-15 10:24:32 +02:00
|
|
|
)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
2021-10-16 21:54:00 +02:00
|
|
|
result.profile = profile.newController(appService.status, appService,
|
|
|
|
result.localSettingsService, changeLanguage)
|
2021-10-16 16:42:40 +02:00
|
|
|
result.connect()
|
|
|
|
#################################################
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc delete*(self: AppController) =
|
|
|
|
self.startupModule.delete
|
|
|
|
self.mainModule.delete
|
2021-10-16 16:42:40 +02:00
|
|
|
|
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
|
|
|
self.profile.delete
|
|
|
|
#################################################
|
2021-10-12 15:48:09 +02:00
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
self.localAccountSettingsVariant.delete
|
|
|
|
|
2021-10-16 16:42:40 +02:00
|
|
|
self.localSettingsService.delete
|
2021-10-12 15:48:09 +02:00
|
|
|
self.accountsService.delete
|
|
|
|
self.contactService.delete
|
|
|
|
self.chatService.delete
|
|
|
|
self.communityService.delete
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc startupDidLoad*(self: AppController) =
|
2021-10-16 16:42:40 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be moved to
|
|
|
|
# appropriate place or removed:
|
|
|
|
singletonInstance.engine.setRootContextProperty("profileModel", self.profile.variant)
|
|
|
|
#################################################
|
|
|
|
|
|
|
|
# We're applying default language before we load qml. Also we're aware that
|
|
|
|
# switch language at runtime will have some impact to cpu usage.
|
|
|
|
# https://doc.qt.io/archives/qtjambi-4.5.2_01/com/trolltech/qt/qtjambi-linguist-programmers.html
|
|
|
|
changeLanguage("en")
|
|
|
|
|
2021-10-16 21:54:00 +02:00
|
|
|
singletonInstance.engine.setRootContextProperty("localAccountSettings",
|
|
|
|
self.localAccountSettingsVariant)
|
2021-10-16 16:42:40 +02:00
|
|
|
singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc mainDidLoad*(self: AppController) =
|
|
|
|
self.appService.onLoggedIn()
|
2021-10-14 10:04:15 +02:00
|
|
|
self.startupModule.moveToAppState()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-16 21:03:01 +02:00
|
|
|
self.mainModule.checkForStoringPassword()
|
|
|
|
|
2021-10-06 22:05:13 +02:00
|
|
|
proc start*(self: AppController) =
|
2021-10-12 15:48:09 +02:00
|
|
|
self.accountsService.init()
|
|
|
|
|
|
|
|
self.startupModule.load()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc load*(self: AppController) =
|
|
|
|
self.contactService.init()
|
|
|
|
self.chatService.init()
|
|
|
|
self.communityService.init()
|
2021-10-14 09:58:28 +02:00
|
|
|
self.tokenService.init()
|
2021-10-18 13:00:56 +02:00
|
|
|
self.walletAccountService.init()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-14 10:04:15 +02:00
|
|
|
self.mainModule.load()
|
|
|
|
|
2021-10-15 21:47:43 +02:00
|
|
|
proc userLoggedIn*(self: AppController) =
|
2021-10-19 16:22:49 +02:00
|
|
|
#################################################
|
|
|
|
# At the end of refactoring this will be removed:
|
|
|
|
let loggedInUser = self.accountsService.getLoggedInAccount()
|
|
|
|
let account = Account(name: loggedInUser.name, keyUid: loggedInUser.keyUid)
|
|
|
|
self.appService.status.events.emit("loginCompleted", AccountArgs(account: account))
|
|
|
|
#################################################
|
2021-10-14 10:04:15 +02:00
|
|
|
self.load()
|