2020-05-06 13:40:00 -04:00
|
|
|
import NimQml
|
2020-05-21 15:07:55 -04:00
|
|
|
import chronicles
|
2020-05-15 18:02:20 -04:00
|
|
|
import app/chat/core as chat
|
|
|
|
import app/wallet/core as wallet
|
|
|
|
import app/node/core as node
|
2020-05-19 21:59:15 -04:00
|
|
|
import app/profile/core as profile
|
2020-05-22 19:33:36 -04:00
|
|
|
import signals/core as signals
|
2020-05-20 13:36:44 -04:00
|
|
|
import app/onboarding/core as onboarding
|
2020-05-08 18:12:32 -04:00
|
|
|
import state
|
2020-05-19 21:59:15 -04:00
|
|
|
import json
|
2020-05-20 13:11:30 -04:00
|
|
|
import status/accounts as status_accounts
|
2020-05-16 19:46:46 -04:00
|
|
|
import status/chat as status_chat
|
|
|
|
import status/types as types
|
|
|
|
import status/libstatus
|
2020-05-21 16:52:00 -04:00
|
|
|
import models/accounts
|
2020-05-16 19:46:46 -04:00
|
|
|
import state
|
2020-05-19 23:22:38 +10:00
|
|
|
import status/types
|
|
|
|
import eventemitter
|
2020-05-16 19:46:46 -04:00
|
|
|
|
2020-05-18 21:48:20 +03:00
|
|
|
var signalsQObjPointer: pointer
|
2020-05-11 13:31:07 -04:00
|
|
|
|
2020-05-21 15:07:55 -04:00
|
|
|
logScope:
|
|
|
|
topics = "main"
|
|
|
|
|
2020-05-06 13:40:00 -04:00
|
|
|
proc mainProc() =
|
2020-05-22 22:35:40 +10:00
|
|
|
let nodeAccounts = parseJson(status_accounts.initNodeAccounts()).toNodeAccounts # to be used for login
|
2020-05-18 16:32:53 -04:00
|
|
|
let app = newQApplication()
|
|
|
|
let engine = newQQmlApplicationEngine()
|
|
|
|
let signalController = signals.newController(app)
|
2020-05-19 23:22:38 +10:00
|
|
|
let events = createEventEmitter()
|
2020-05-18 21:48:20 +03:00
|
|
|
|
2020-05-18 16:32:53 -04:00
|
|
|
defer: # Defer will run this just before mainProc() function ends
|
|
|
|
app.delete()
|
|
|
|
engine.delete()
|
|
|
|
signalController.delete()
|
2020-05-18 21:48:20 +03:00
|
|
|
|
|
|
|
# We need this global variable in order to be able to access the application
|
|
|
|
# from the non-closure callback passed to `libstatus.setSignalEventCallback`
|
|
|
|
signalsQObjPointer = cast[pointer](signalController.vptr)
|
|
|
|
|
2020-05-15 17:10:00 -04:00
|
|
|
var appState = state.newAppState()
|
2020-05-21 15:07:55 -04:00
|
|
|
debug "Application State", title=appState.title
|
2020-05-15 17:10:00 -04:00
|
|
|
|
2020-05-22 19:33:36 -04:00
|
|
|
var wallet = wallet.newController(events)
|
2020-05-15 17:40:05 -04:00
|
|
|
engine.setRootContextProperty("assetsModel", wallet.variant)
|
2020-05-13 15:14:35 -04:00
|
|
|
|
2020-05-21 14:32:24 -04:00
|
|
|
var chat = chat.newController(events)
|
2020-05-15 17:10:00 -04:00
|
|
|
chat.init()
|
2020-05-15 17:40:05 -04:00
|
|
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
2020-05-12 07:24:08 +10:00
|
|
|
|
2020-05-15 17:40:05 -04:00
|
|
|
var node = node.newController()
|
2020-05-15 17:10:00 -04:00
|
|
|
node.init()
|
2020-05-15 17:40:05 -04:00
|
|
|
engine.setRootContextProperty("nodeModel", node.variant)
|
2020-05-20 13:11:30 -04:00
|
|
|
|
2020-05-19 21:59:15 -04:00
|
|
|
var profile = profile.newController()
|
|
|
|
engine.setRootContextProperty("profileModel", profile.variant)
|
|
|
|
|
2020-05-21 16:52:00 -04:00
|
|
|
var accountsModel = newAccountModel()
|
|
|
|
accountsModel.events.on("accountsReady") do(a: Args):
|
2020-05-22 22:35:40 +10:00
|
|
|
var args = AccountArgs(a)
|
2020-05-21 16:52:00 -04:00
|
|
|
status_chat.startMessenger()
|
|
|
|
wallet.init()
|
2020-05-22 22:35:40 +10:00
|
|
|
profile.init(args.account) # TODO: use correct account
|
2020-05-21 16:52:00 -04:00
|
|
|
|
2020-05-21 19:32:27 -04:00
|
|
|
var onboarding = onboarding.newController(accountsModel)
|
2020-05-21 16:52:00 -04:00
|
|
|
onboarding.init()
|
|
|
|
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
|
|
|
|
2020-05-18 11:07:30 -04:00
|
|
|
signalController.init()
|
|
|
|
signalController.addSubscriber(SignalType.Wallet, wallet)
|
2020-05-19 17:00:04 -04:00
|
|
|
signalController.addSubscriber(SignalType.Wallet, node)
|
2020-05-18 14:20:20 -04:00
|
|
|
signalController.addSubscriber(SignalType.Message, chat)
|
2020-05-19 17:00:04 -04:00
|
|
|
|
2020-05-18 11:07:30 -04:00
|
|
|
engine.setRootContextProperty("signals", signalController.variant)
|
|
|
|
|
2020-05-08 18:12:32 -04:00
|
|
|
appState.subscribe(proc () =
|
|
|
|
for channel in appState.channels:
|
2020-05-21 14:32:24 -04:00
|
|
|
chat.load(channel.name)
|
2020-05-08 18:12:32 -04:00
|
|
|
)
|
|
|
|
|
2020-05-21 16:52:00 -04:00
|
|
|
accountsModel.events.on("accountsReady") do(a: Args):
|
2020-05-19 23:22:38 +10:00
|
|
|
appState.addChannel("test")
|
|
|
|
appState.addChannel("test2")
|
2020-05-22 19:33:36 -04:00
|
|
|
appState.addChannel("status")
|
2020-05-21 19:32:27 -04:00
|
|
|
|
2020-05-16 19:46:46 -04:00
|
|
|
engine.load("../ui/main.qml")
|
2020-05-18 21:48:20 +03:00
|
|
|
|
|
|
|
# Please note that this must use the `cdecl` calling convention because
|
|
|
|
# it will be passed as a regular C function to libstatus. This means that
|
|
|
|
# we cannot capture any local variables here (we must rely on globals)
|
|
|
|
var callback: SignalCallback = proc(p0: cstring) {.cdecl.} =
|
2020-05-16 19:46:46 -04:00
|
|
|
setupForeignThreadGc()
|
2020-05-18 11:07:30 -04:00
|
|
|
signal_handler(signalsQObjPointer, p0, "receiveSignal")
|
2020-05-16 19:46:46 -04:00
|
|
|
tearDownForeignThreadGc()
|
|
|
|
|
|
|
|
libstatus.setSignalEventCallback(callback)
|
2020-05-15 17:10:00 -04:00
|
|
|
|
2020-05-10 19:24:06 -04:00
|
|
|
# Qt main event loop is entered here
|
|
|
|
# The termination of the loop will be performed when exit() or quit() is called
|
2020-05-21 15:07:55 -04:00
|
|
|
info "Starting application..."
|
2020-05-06 13:40:00 -04:00
|
|
|
app.exec()
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
mainProc()
|
|
|
|
GC_fullcollect()
|