Phase 1 sub-commit 4: Qt foundation types
All checks were successful
CI / Quality (push) Successful in 5s
All checks were successful
CI / Quality (push) Successful in 5s
BackendConnection (QML singleton via create() factory) reads BRIDGE_URL and BRIDGE_TOKEN from env, periodically probes <url>/healthz with a 2s transfer timeout, and exposes a Connecting/Online/Error state machine plus error/token properties to QML. Bundled-mode startup (spawning the embedded FrankenPHP child) is a Phase 4 deliverable; restart() is a no-op for now. tokenRotated signal is reserved for the per-session secret rotation described in PLAN.md §3. SingleInstance is C++-only — main() must call acquireOrForward() before the QML engine boots, so it's exposed via context property rather than QML_SINGLETON. QLocalServer-based lock with stale-socket detection, launch-arg forwarding via QDataStream, and the deadlock-avoiding race fallback specified in §3 *Edge cases*. CMakeLists.txt declares the PhpQml.Bridge static QML module with both sources and is dual-mode: stands alone for sanity builds, integrates via add_subdirectory from the skeleton's top-level CMake (Phase 1 sub-commit 6). Standalone build verified clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
47
framework/qml/src/SingleInstance.h
Normal file
47
framework/qml/src/SingleInstance.h
Normal file
@@ -0,0 +1,47 @@
|
||||
#pragma once
|
||||
|
||||
#include <QLocalServer>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
namespace PhpQml::Bridge {
|
||||
|
||||
/// Per-OS-user single-instance lock with launch-arg forwarding.
|
||||
///
|
||||
/// Owned by the application's `main()`, NOT a QML singleton — the
|
||||
/// acquire-or-forward decision must run before the QML engine boots,
|
||||
/// so we cannot rely on lazy QML construction. The application exposes
|
||||
/// the live instance to QML via `setContextProperty("SingleInstance", &si)`.
|
||||
///
|
||||
/// See PLAN.md §3 (Single-instance, Edge cases — Single-instance launch race).
|
||||
class SingleInstance : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SingleInstance(const QString& applicationId, QObject* parent = nullptr);
|
||||
|
||||
/// Returns true if this process is the live instance and should
|
||||
/// continue starting up. Returns false if another instance was
|
||||
/// already running; the launch arguments have been forwarded and
|
||||
/// the caller must exit before creating any QML/window resources.
|
||||
bool acquireOrForward(const QStringList& launchArgs);
|
||||
|
||||
signals:
|
||||
/// Emitted when a subsequent invocation forwards its launch args
|
||||
/// to the running instance. Application code is expected to act
|
||||
/// on this — typically focus the existing window or open a new one.
|
||||
void launchArgsReceived(const QStringList& args);
|
||||
|
||||
private slots:
|
||||
void onNewConnection();
|
||||
|
||||
private:
|
||||
QString endpointName() const;
|
||||
|
||||
QString m_appId;
|
||||
QLocalServer m_server;
|
||||
};
|
||||
|
||||
} // namespace PhpQml::Bridge
|
||||
Reference in New Issue
Block a user