2021-10-06 22:05:13 +02:00
|
|
|
import NimQml
|
|
|
|
|
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
|
|
|
|
import ../modules/startup/module as startup_module
|
|
|
|
import ../modules/main/module as main_module
|
|
|
|
|
|
|
|
import global_singleton
|
|
|
|
|
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-12 15:48:09 +02:00
|
|
|
|
2021-10-06 22:05:13 +02:00
|
|
|
# This to will be adapted to appropriate modules later:
|
2021-10-12 15:48:09 +02:00
|
|
|
# import ../onboarding/core as onboarding
|
|
|
|
# import ../login/core as login
|
|
|
|
# import status/types/[account]
|
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-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
|
|
|
|
# Modules
|
|
|
|
startupModule: startup_module.AccessInterface
|
|
|
|
mainModule: main_module.AccessInterface
|
|
|
|
|
|
|
|
# This to will be adapted to appropriate modules later:
|
2021-10-12 15:48:09 +02:00
|
|
|
# login: LoginController
|
|
|
|
# onboarding: OnboardingController
|
|
|
|
# accountArgs: AccountArgs
|
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-14 10:04:15 +02:00
|
|
|
proc accountCreated*(self: AppController)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
# Main Module Delegate Interface
|
|
|
|
proc mainDidLoad*(self: AppController)
|
|
|
|
#################################################
|
|
|
|
|
2021-10-12 15:48:09 +02:00
|
|
|
# proc connect(self: AppController) =
|
|
|
|
# self.appService.status.events.once("login") do(a: Args):
|
|
|
|
# self.accountArgs = AccountArgs(a)
|
|
|
|
# self.load()
|
|
|
|
|
|
|
|
# self.appService.status.events.once("nodeStopped") do(a: Args):
|
|
|
|
# self.login.reset()
|
|
|
|
# self.onboarding.reset()
|
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-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-06 22:05:13 +02:00
|
|
|
# Modules
|
2021-10-12 15:48:09 +02:00
|
|
|
result.startupModule = startup_module.newModule[AppController](result, appService,
|
|
|
|
result.accountsService)
|
2021-10-18 12:07:18 +02:00
|
|
|
result.mainModule = main_module.newModule[AppController](result, result.chatService,
|
|
|
|
result.communityService)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
# Adding status and appService here now is just because of having a controll
|
|
|
|
# over order of execution while we integrating this refactoring architecture
|
|
|
|
# into the current app state.
|
|
|
|
# Once we complete refactoring process we will get rid of "status" part/lib.
|
|
|
|
#
|
|
|
|
# This to will be adapted to appropriate modules later:
|
2021-10-12 15:48:09 +02:00
|
|
|
# result.login = login.newController(appService.status, appService)
|
|
|
|
# result.onboarding = onboarding.newController(appService.status)
|
|
|
|
# singletonInstance.engine.setRootContextProperty("loginModel", result.login.variant)
|
|
|
|
# singletonInstance.engine.setRootContextProperty("onboardingModel", result.onboarding.variant)
|
|
|
|
#result.connect()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc delete*(self: AppController) =
|
|
|
|
self.startupModule.delete
|
|
|
|
self.mainModule.delete
|
2021-10-12 15:48:09 +02:00
|
|
|
# self.login.delete
|
|
|
|
# self.onboarding.delete
|
|
|
|
|
|
|
|
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-12 15:48:09 +02:00
|
|
|
echo "StartupDidLoad"
|
2021-10-14 10:04:15 +02:00
|
|
|
singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
2021-10-12 15:48:09 +02:00
|
|
|
# self.login.init()
|
|
|
|
# self.onboarding.init()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc mainDidLoad*(self: AppController) =
|
|
|
|
# This to will be adapted to appropriate modules later:
|
|
|
|
self.appService.onLoggedIn()
|
2021-10-14 10:04:15 +02:00
|
|
|
self.startupModule.moveToAppState()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
# Reset login and onboarding to remove any mnemonic that would have been saved in the accounts list
|
2021-10-12 15:48:09 +02:00
|
|
|
# self.login.reset()
|
|
|
|
# self.onboarding.reset()
|
2021-10-06 22:05:13 +02:00
|
|
|
|
2021-10-12 15:48:09 +02:00
|
|
|
# self.login.moveToAppState()
|
|
|
|
# self.onboarding.moveToAppState()
|
|
|
|
# self.appService.status.events.emit("loginCompleted", self.accountArgs)
|
2021-10-06 22:05:13 +02:00
|
|
|
|
|
|
|
proc start*(self: AppController) =
|
2021-10-12 15:48:09 +02:00
|
|
|
echo "AppStart"
|
|
|
|
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()
|
|
|
|
|
|
|
|
proc accountCreated*(self: AppController) =
|
|
|
|
echo "AppController account created"
|
|
|
|
self.load()
|