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-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-16 21:54:00 +02:00
|
|
|
# Core
|
|
|
|
localAccountSettings: LocalAccountSettings
|
|
|
|
localAccountSettingsVariant: QVariant
|
2021-10-06 22:05:13 +02:00
|
|
|
# Modules
|
|
|
|
startupModule: startup_module.AccessInterface
|
|
|
|
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-16 16:42:40 +02:00
|
|
|
result.localSettingsService = local_settings_service.newService()
|
2021-10-16 21:54:00 +02:00
|
|
|
result.keychainService = keychain_service.newService(result.localSettingsService,
|
|
|
|
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-16 21:54:00 +02:00
|
|
|
# Core
|
|
|
|
result.localAccountSettings = newLocalAccountSettings(result.localSettingsService)
|
2021-10-17 12:44:21 +02:00
|
|
|
result.localAccountSettingsVariant = newQVariant(result.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,
|
|
|
|
appService.status.events, appService.status.fleet, result.localSettingsService,
|
|
|
|
result.keychainService, result.accountsService)
|
2021-10-16 21:03:01 +02:00
|
|
|
result.mainModule = main_module.newModule[AppController](result,
|
|
|
|
appService.status.events, result.localSettingsService, result.keychainService,
|
|
|
|
result.accountsService, result.chatService, result.communityService)
|
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.localSettingsService.delete
|
|
|
|
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 10:04:15 +02:00
|
|
|
self.mainModule.load()
|
|
|
|
|
2021-10-15 21:47:43 +02:00
|
|
|
proc userLoggedIn*(self: AppController) =
|
2021-10-14 10:04:15 +02:00
|
|
|
self.load()
|