2020-06-23 12:32:56 +00:00
|
|
|
import NimQml, eventemitter, chronicles
|
2020-05-29 19:54:35 +00:00
|
|
|
|
2020-05-15 22:02:20 +00:00
|
|
|
import app/chat/core as chat
|
|
|
|
import app/wallet/core as wallet
|
|
|
|
import app/node/core as node
|
2020-05-20 01:59:15 +00:00
|
|
|
import app/profile/core as profile
|
2020-05-20 17:36:44 +00:00
|
|
|
import app/onboarding/core as onboarding
|
2020-05-27 07:15:42 +00:00
|
|
|
import app/login/core as login
|
2020-05-29 19:54:35 +00:00
|
|
|
import signals/core as signals
|
|
|
|
|
2020-06-23 12:32:56 +00:00
|
|
|
import status/libstatus/[types, libstatus]
|
2020-05-29 19:54:35 +00:00
|
|
|
import status/status as statuslib
|
2020-05-16 23:46:46 +00:00
|
|
|
|
2020-05-18 18:48:20 +00:00
|
|
|
var signalsQObjPointer: pointer
|
2020-05-11 17:31:07 +00:00
|
|
|
|
2020-05-21 19:07:55 +00:00
|
|
|
logScope:
|
|
|
|
topics = "main"
|
|
|
|
|
2020-05-06 17:40:00 +00:00
|
|
|
proc mainProc() =
|
2020-05-29 19:54:35 +00:00
|
|
|
let status = statuslib.newStatusInstance()
|
2020-06-04 07:38:24 +00:00
|
|
|
status.initNode()
|
2020-05-29 19:54:35 +00:00
|
|
|
|
2020-06-23 19:31:52 +00:00
|
|
|
enableHDPI()
|
|
|
|
|
2020-06-25 14:39:59 +00:00
|
|
|
let app = newQApplication("Nim Status Client")
|
2020-06-23 22:54:21 +00:00
|
|
|
app.icon("./status.svg")
|
|
|
|
|
2020-05-18 20:32:53 +00:00
|
|
|
let engine = newQQmlApplicationEngine()
|
|
|
|
let signalController = signals.newController(app)
|
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)
|
|
|
|
|
2020-05-29 19:54:35 +00:00
|
|
|
var wallet = wallet.newController(status)
|
2020-06-02 20:10:48 +00:00
|
|
|
engine.setRootContextProperty("walletModel", wallet.variant)
|
2020-05-13 19:14:35 +00:00
|
|
|
|
2020-05-29 19:54:35 +00:00
|
|
|
var chat = chat.newController(status)
|
2020-05-15 21:40:05 +00:00
|
|
|
engine.setRootContextProperty("chatsModel", chat.variant)
|
2020-05-11 21:24:08 +00:00
|
|
|
|
2020-05-29 19:54:35 +00:00
|
|
|
var node = node.newController(status)
|
2020-05-15 21:40:05 +00:00
|
|
|
engine.setRootContextProperty("nodeModel", node.variant)
|
2020-05-20 17:11:30 +00:00
|
|
|
|
2020-05-29 19:54:35 +00:00
|
|
|
var profile = profile.newController(status)
|
2020-05-20 01:59:15 +00:00
|
|
|
engine.setRootContextProperty("profileModel", profile.variant)
|
|
|
|
|
2020-06-17 16:13:13 +00:00
|
|
|
status.events.once("login") do(a: Args):
|
2020-05-22 12:35:40 +00:00
|
|
|
var args = AccountArgs(a)
|
2020-05-29 19:54:35 +00:00
|
|
|
status.startMessenger()
|
2020-05-28 20:14:31 +00:00
|
|
|
chat.init()
|
2020-05-21 20:52:00 +00:00
|
|
|
wallet.init()
|
2020-05-27 07:15:42 +00:00
|
|
|
profile.init(args.account)
|
2020-05-21 20:52:00 +00:00
|
|
|
|
2020-05-29 19:54:35 +00:00
|
|
|
var login = login.newController(status)
|
|
|
|
var onboarding = onboarding.newController(status)
|
2020-05-27 07:15:42 +00:00
|
|
|
|
2020-05-28 04:06:57 +00:00
|
|
|
engine.setRootContextProperty("loginModel", login.variant)
|
|
|
|
engine.setRootContextProperty("onboardingModel", onboarding.variant)
|
2020-05-21 20:52:00 +00:00
|
|
|
|
2020-06-18 21:56:04 +00:00
|
|
|
defer:
|
|
|
|
error "TODO: if user is logged in, logout"
|
|
|
|
engine.delete()
|
|
|
|
app.delete()
|
|
|
|
signalController.delete()
|
|
|
|
login.delete()
|
|
|
|
onboarding.delete()
|
|
|
|
wallet.delete()
|
|
|
|
chat.delete()
|
|
|
|
profile.delete()
|
|
|
|
|
|
|
|
|
2020-06-04 07:38:24 +00:00
|
|
|
# Initialize only controllers whose init functions
|
|
|
|
# do not need a running node
|
|
|
|
proc initControllers() =
|
|
|
|
node.init()
|
|
|
|
login.init()
|
|
|
|
onboarding.init()
|
|
|
|
|
|
|
|
initControllers()
|
|
|
|
|
|
|
|
# Handle node.stopped signal when user has logged out
|
2020-06-17 16:13:13 +00:00
|
|
|
status.events.once("nodeStopped") do(a: Args):
|
2020-06-04 07:38:24 +00:00
|
|
|
# TODO: remove this once accounts are not tracked in the AccountsModel
|
|
|
|
status.reset()
|
|
|
|
|
|
|
|
# 1. Reset controller data
|
|
|
|
login.reset()
|
|
|
|
onboarding.reset()
|
|
|
|
# TODO: implement all controller resets
|
|
|
|
# chat.reset()
|
|
|
|
# node.reset()
|
|
|
|
# wallet.reset()
|
|
|
|
# profile.reset()
|
|
|
|
|
|
|
|
# 2. Re-init controllers that don't require a running node
|
|
|
|
initControllers()
|
|
|
|
|
|
|
|
|
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)
|
2020-06-16 21:24:43 +00:00
|
|
|
signalController.addSubscriber(SignalType.Message, profile)
|
2020-06-02 16:35:21 +00:00
|
|
|
signalController.addSubscriber(SignalType.DiscoverySummary, chat)
|
2020-05-27 07:15:42 +00:00
|
|
|
signalController.addSubscriber(SignalType.NodeLogin, login)
|
|
|
|
signalController.addSubscriber(SignalType.NodeLogin, onboarding)
|
2020-06-04 07:38:24 +00:00
|
|
|
signalController.addSubscriber(SignalType.NodeStopped, login)
|
|
|
|
signalController.addSubscriber(SignalType.NodeStarted, login)
|
|
|
|
signalController.addSubscriber(SignalType.NodeReady, login)
|
2020-05-25 02:18:37 +00:00
|
|
|
|
2020-05-18 15:07:30 +00:00
|
|
|
engine.setRootContextProperty("signals", signalController.variant)
|
|
|
|
|
2020-05-16 23:46:46 +00:00
|
|
|
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.} =
|
2020-06-04 21:18:11 +00:00
|
|
|
setupForeignThreadGc()
|
2020-05-18 15:07:30 +00:00
|
|
|
signal_handler(signalsQObjPointer, p0, "receiveSignal")
|
2020-06-04 21:18:11 +00:00
|
|
|
tearDownForeignThreadGc()
|
2020-05-16 23:46:46 +00:00
|
|
|
|
|
|
|
libstatus.setSignalEventCallback(callback)
|
2020-05-15 21:10:00 +00:00
|
|
|
|
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()
|