Expose lastURL/lastUsername to QML for form pre-fill
This commit is contained in:
parent
4ebc674a89
commit
06dccbe147
1 changed files with 26 additions and 30 deletions
|
|
@ -3,7 +3,7 @@
|
||||||
//
|
//
|
||||||
// DragonRelayBackend is the QObject that QML binds to via the context property
|
// DragonRelayBackend is the QObject that QML binds to via the context property
|
||||||
// "dragonRelay". It owns a RelayClient and a TunnelManager, coordinates the
|
// "dragonRelay". It owns a RelayClient and a TunnelManager, coordinates the
|
||||||
// login → VPN provision → tunnel-up → host-discovery workflow, and exposes
|
// login -> VPN provision -> tunnel-up -> host-discovery workflow, and exposes
|
||||||
// everything QML needs through Q_PROPERTY / Q_INVOKABLE.
|
// everything QML needs through Q_PROPERTY / Q_INVOKABLE.
|
||||||
//
|
//
|
||||||
// Registration in main.cpp (or wherever the QML engine is created):
|
// Registration in main.cpp (or wherever the QML engine is created):
|
||||||
|
|
@ -17,10 +17,12 @@
|
||||||
// dragonRelay.disconnectRelay()
|
// dragonRelay.disconnectRelay()
|
||||||
// dragonRelay.streamHost(ip, app)
|
// dragonRelay.streamHost(ip, app)
|
||||||
// dragonRelay.streamHost(ip, app, displayIndex)
|
// dragonRelay.streamHost(ip, app, displayIndex)
|
||||||
// dragonRelay.status // int — DragonRelayBackend::Status enum
|
// dragonRelay.status // int - DragonRelayBackend::Status enum
|
||||||
// dragonRelay.statusText // QString
|
// dragonRelay.statusText // QString
|
||||||
// dragonRelay.hosts // QVariantList of {name, ip, port, online, source}
|
// dragonRelay.hosts // QVariantList of {name, ip, port, online, source}
|
||||||
// dragonRelay.tunnelIP // QString — local WG address (e.g. "10.99.0.2")
|
// dragonRelay.tunnelIP // QString - local WG address (e.g. "10.99.0.2")
|
||||||
|
// dragonRelay.lastURL // QString - most recently used relay URL (for form pre-fill)
|
||||||
|
// dragonRelay.lastUsername // QString - most recently used username
|
||||||
|
|
||||||
#ifndef DRAGONRELAYBACKEND_H
|
#ifndef DRAGONRELAYBACKEND_H
|
||||||
#define DRAGONRELAYBACKEND_H
|
#define DRAGONRELAYBACKEND_H
|
||||||
|
|
@ -40,20 +42,21 @@
|
||||||
class DragonRelayBackend : public QObject {
|
class DragonRelayBackend : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
// ── Properties exposed to QML ─────────────────────────────────────────────
|
// Properties exposed to QML
|
||||||
|
|
||||||
Q_PROPERTY(int status READ status NOTIFY statusChanged)
|
Q_PROPERTY(int status READ status NOTIFY statusChanged)
|
||||||
Q_PROPERTY(QString statusText READ statusText NOTIFY statusChanged)
|
Q_PROPERTY(QString statusText READ statusText NOTIFY statusChanged)
|
||||||
Q_PROPERTY(QVariantList hosts READ hosts NOTIFY hostsChanged)
|
Q_PROPERTY(QVariantList hosts READ hosts NOTIFY hostsChanged)
|
||||||
Q_PROPERTY(QString tunnelIP READ tunnelIP NOTIFY tunnelIPChanged)
|
Q_PROPERTY(QString tunnelIP READ tunnelIP NOTIFY tunnelIPChanged)
|
||||||
|
Q_PROPERTY(QString lastURL READ lastURL CONSTANT)
|
||||||
|
Q_PROPERTY(QString lastUsername READ lastUsername CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Status codes (exposed to QML as dragonRelay.StatusXxx or raw int)
|
|
||||||
enum Status {
|
enum Status {
|
||||||
Disconnected = 0,
|
Disconnected = 0,
|
||||||
Connecting = 1, // logging in / provisioning VPN peer
|
Connecting = 1,
|
||||||
TunnelUp = 2, // WireGuard tunnel active, hosts loading
|
TunnelUp = 2,
|
||||||
Ready = 3, // tunnel up + at least one host visible
|
Ready = 3,
|
||||||
Error = 4,
|
Error = 4,
|
||||||
};
|
};
|
||||||
Q_ENUM(Status)
|
Q_ENUM(Status)
|
||||||
|
|
@ -61,36 +64,29 @@ public:
|
||||||
explicit DragonRelayBackend(QObject *parent = nullptr);
|
explicit DragonRelayBackend(QObject *parent = nullptr);
|
||||||
~DragonRelayBackend() override;
|
~DragonRelayBackend() override;
|
||||||
|
|
||||||
// ── Property accessors ────────────────────────────────────────────────────
|
int status() const { return m_status; }
|
||||||
|
QString statusText() const { return m_statusText; }
|
||||||
int status() const { return m_status; }
|
QVariantList hosts() const { return m_hosts; }
|
||||||
QString statusText() const { return m_statusText; }
|
QString tunnelIP() const { return m_tunnelIP; }
|
||||||
QVariantList hosts() const { return m_hosts; }
|
QString lastURL() const { return m_savedURL; }
|
||||||
QString tunnelIP() const { return m_tunnelIP; }
|
QString lastUsername() const { return m_savedUser; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// ── Invokable from QML ────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
// Begin the full connect workflow: login → provision VPN → start tunnel → poll hosts.
|
|
||||||
// Idempotent if already connected.
|
|
||||||
Q_INVOKABLE void connectRelay(const QString &url,
|
Q_INVOKABLE void connectRelay(const QString &url,
|
||||||
const QString &username,
|
const QString &username,
|
||||||
const QString &password);
|
const QString &password);
|
||||||
|
|
||||||
// Tear down tunnel, unregister peer, return to Disconnected state.
|
|
||||||
Q_INVOKABLE void disconnectRelay();
|
Q_INVOKABLE void disconnectRelay();
|
||||||
|
|
||||||
// Ask Moonlight to stream to a host discovered via the relay.
|
// displayIndex: 0 = primary, 1+ = secondary displays.
|
||||||
// displayIndex specifies which display to stream (0 = primary, 1+ = secondary displays).
|
Q_INVOKABLE void streamHost(const QString &ip,
|
||||||
Q_INVOKABLE void streamHost(const QString &ip, const QString &app = QStringLiteral("Desktop"), int displayIndex = 0);
|
const QString &app = QStringLiteral("Desktop"),
|
||||||
|
int displayIndex = 0);
|
||||||
|
|
||||||
// Get displays for a host by its IP.
|
|
||||||
Q_INVOKABLE QVariantList displaysForHost(const QString &hostIP) const;
|
Q_INVOKABLE QVariantList displaysForHost(const QString &hostIP) const;
|
||||||
|
|
||||||
// Stream a specific display from a host.
|
|
||||||
Q_INVOKABLE void streamHostDisplay(const QString &hostIP, int displayIndex);
|
Q_INVOKABLE void streamHostDisplay(const QString &hostIP, int displayIndex);
|
||||||
|
|
||||||
// Refresh the host list immediately (called by QML pull-to-refresh).
|
|
||||||
Q_INVOKABLE void refreshHosts();
|
Q_INVOKABLE void refreshHosts();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
@ -134,7 +130,7 @@ private:
|
||||||
|
|
||||||
QMap<QString, QVariantList> m_hostDisplays;
|
QMap<QString, QVariantList> m_hostDisplays;
|
||||||
|
|
||||||
QSettings m_settings; // persists last-used URL + username
|
QSettings m_settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DRAGONRELAYBACKEND_H
|
#endif // DRAGONRELAYBACKEND_H
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue