Upload main.cpp

This commit is contained in:
Zac Gaetano 2026-05-06 20:34:39 -04:00
parent 1ceff80914
commit a0d81b281f

53
app/main.cpp Normal file
View file

@ -0,0 +1,53 @@
// 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();
}