54 lines
2.2 KiB
C++
54 lines
2.2 KiB
C++
|
|
// app/main.cpp
|
||
|
|
//
|
||
|
|
// DragonMoonlight application entry point.
|
||
|
|
//
|
||
|
|
// Initializes Qt, creates the QML engine, registers the DragonRelayBackend
|
||
|
|
// context property, and loads the main QML view (typically from moonlight-qt's
|
||
|
|
// main.qml or a fork thereof).
|
||
|
|
|
||
|
|
#include <QGuiApplication>
|
||
|
|
#include <QQmlApplicationEngine>
|
||
|
|
#include <QQmlContext>
|
||
|
|
|
||
|
|
#include "vpn/dragonrelaybackend.h"
|
||
|
|
|
||
|
|
int main(int argc, char *argv[])
|
||
|
|
{
|
||
|
|
QGuiApplication app(argc, argv);
|
||
|
|
|
||
|
|
// ── Create QML Engine ─────────────────────────────────────────────────────
|
||
|
|
QQmlApplicationEngine engine;
|
||
|
|
|
||
|
|
// ── Wire DragonRelayBackend context property ──────────────────────────────
|
||
|
|
//
|
||
|
|
// Create a DragonRelayBackend instance on the stack. This object must exist
|
||
|
|
// for as long as the QML engine is running (i.e., through the app event loop).
|
||
|
|
//
|
||
|
|
// The QML context property allows QML code to access C++ methods and properties:
|
||
|
|
//
|
||
|
|
// // in QML:
|
||
|
|
// dragonRelay.connectRelay(url, user, pass)
|
||
|
|
// dragonRelay.streamHost(hostIP, "Desktop")
|
||
|
|
// var hosts = dragonRelay.hosts
|
||
|
|
// var status = dragonRelay.status
|
||
|
|
//
|
||
|
|
DragonRelayBackend relayBackend;
|
||
|
|
engine.rootContext()->setContextProperty(QStringLiteral("dragonRelay"), &relayBackend);
|
||
|
|
|
||
|
|
// ── Load main QML view ────────────────────────────────────────────────────
|
||
|
|
//
|
||
|
|
// This assumes the moonlight-qt fork provides a main.qml that includes
|
||
|
|
// or references DragonRelayView.qml. Adjust the path as needed for your
|
||
|
|
// build configuration (e.g., if QML files are in a subdirectory or
|
||
|
|
// compiled as QRC resources).
|
||
|
|
//
|
||
|
|
const QUrl url(QStringLiteral("qrc:/app/gui/main.qml"));
|
||
|
|
engine.load(url);
|
||
|
|
|
||
|
|
// ── Error handling ────────────────────────────────────────────────────────
|
||
|
|
if (engine.rootObjects().isEmpty())
|
||
|
|
return -1;
|
||
|
|
|
||
|
|
return app.exec();
|
||
|
|
}
|