status-desktop/src/nim_status_client.nim

107 lines
3.4 KiB
Nim
Raw Normal View History

2020-05-06 17:40:00 +00:00
import NimQml
2020-05-21 19:07:55 +00:00
import chronicles
import app/chat/core as chat
import app/wallet/core as wallet
import app/node/core as node
import app/profile/core as profile
import signals/core as signals
2020-05-20 17:36:44 +00:00
import app/onboarding/core as onboarding
import app/login/core as login
import state
import status/libstatus/accounts as status_accounts
import status/libstatus/core as status_core
import status/libstatus/types as types
import status/libstatus/libstatus
import status/libstatus/types
import state
import eventemitter
import json_serialization
2020-05-18 18:48:20 +00:00
var signalsQObjPointer: pointer
2020-05-21 19:07:55 +00:00
logScope:
topics = "main"
2020-05-06 17:40:00 +00:00
proc mainProc() =
let nodeAccounts = status_accounts.initNodeAccounts()
2020-05-18 20:32:53 +00:00
let app = newQApplication()
let engine = newQQmlApplicationEngine()
let signalController = signals.newController(app)
let appEvents = createEventEmitter()
2020-05-18 18:48:20 +00:00
2020-05-18 20:32:53 +00:00
defer: # Defer will run this just before mainProc() function ends
app.delete()
engine.delete()
signalController.delete()
2020-05-18 18:48:20 +00: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)
var appState = state.newAppState()
2020-05-21 19:07:55 +00:00
debug "Application State", title=appState.title
var wallet = wallet.newController(appEvents)
2020-05-15 21:40:05 +00:00
engine.setRootContextProperty("assetsModel", wallet.variant)
2020-05-13 19:14:35 +00:00
var chat = chat.newController(appEvents)
2020-05-15 21:40:05 +00:00
engine.setRootContextProperty("chatsModel", chat.variant)
var node = node.newController(appEvents)
node.init()
2020-05-15 21:40:05 +00:00
engine.setRootContextProperty("nodeModel", node.variant)
2020-05-20 17:11:30 +00:00
var profile = profile.newController(appEvents)
engine.setRootContextProperty("profileModel", profile.variant)
appEvents.once("login") do(a: Args):
var args = AccountArgs(a)
status_core.startMessenger()
2020-05-28 20:14:31 +00:00
chat.init()
2020-05-21 20:52:00 +00:00
wallet.init()
profile.init(args.account)
2020-05-21 20:52:00 +00:00
var login = login.newController(appEvents)
var onboarding = onboarding.newController(appEvents)
# TODO: replace this with routing
let showLogin = nodeAccounts.len > 0
engine.setRootContextProperty("showLogin", newQVariant(showLogin))
login.init(nodeAccounts)
engine.setRootContextProperty("loginModel", login.variant)
onboarding.init()
engine.setRootContextProperty("onboardingModel", onboarding.variant)
2020-05-21 20:52:00 +00:00
2020-05-18 15:07:30 +00:00
signalController.init()
signalController.addSubscriber(SignalType.Wallet, wallet)
2020-05-19 21:00:04 +00:00
signalController.addSubscriber(SignalType.Wallet, node)
2020-05-18 18:20:20 +00:00
signalController.addSubscriber(SignalType.Message, chat)
signalController.addSubscriber(SignalType.WhisperFilterAdded, chat)
signalController.addSubscriber(SignalType.NodeLogin, login)
signalController.addSubscriber(SignalType.NodeLogin, onboarding)
2020-05-18 15:07:30 +00:00
engine.setRootContextProperty("signals", signalController.variant)
engine.load("../ui/main.qml")
2020-05-18 18:48:20 +00: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.} =
setupForeignThreadGc()
2020-05-18 15:07:30 +00:00
signal_handler(signalsQObjPointer, p0, "receiveSignal")
tearDownForeignThreadGc()
libstatus.setSignalEventCallback(callback)
2020-05-10 23:24:06 +00: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 19:07:55 +00:00
info "Starting application..."
2020-05-06 17:40:00 +00:00
app.exec()
when isMainModule:
mainProc()
GC_fullcollect()