dashboard: defer ServerStatus::Started until D-Bus properties are populated

The server only exports its D-Bus interface and sets JsonConfiguration
from inside on_name_acquired (server/main.cpp), after owning the
well-known name io.github.wivrn.Server. The dashboard's GetAll
triggered from on_server_dbus_registered can therefore race ahead of
that and come back with an error or an empty reply.

Previously the dashboard set ServerStatus to Started as soon as the
name was owned, so the rest of the UI assumed the server was usable
while JsonConfiguration was still missing. SettingsPage in particular
loaded its values once in Component.onCompleted and ended up showing
defaults (Encoder Auto, SteamVR checkbox unchecked, OpenVR / Autostart
blank), even though the configuration on disk was correct.

Move the Started transition into refresh_server_properties, only after
GetAll returns a reply that actually contains JsonConfiguration. If the
initial reply is errored or empty, retry every 200 ms until the server
has exported its interface. When the dashboard starts and finds the
service already registered, set Status::Starting in the constructor so
Main.qml does not see Stopped and spawn a duplicate process.

With this, ServerStatus::Started now consistently means 'server is
fully usable, properties are populated', and SettingsPage no longer
needs to handle the asynchronous arrival of JsonConfiguration itself.
This commit is contained in:
Clansty
2026-05-20 21:40:51 +02:00
committed by xytovl
parent a870344405
commit 18d685976e
+29 -4
View File
@@ -25,6 +25,7 @@
#include <QApplication>
#include <QClipboard>
#include <QDesktopServices>
#include <QTimer>
#include <QtLogging>
#include <cassert>
#include <memory>
@@ -52,7 +53,14 @@ wivrn_server::wivrn_server(QObject * parent) :
const QStringList services = QDBusConnection::sessionBus().interface()->registeredServiceNames();
if (services.contains("io.github.wivrn.Server"))
{
// Server is already up. Move to a transitional state so Main.qml's
// onCompleted does not see Status::Stopped and spawn a duplicate
// process. The state will transition to Started after the initial
// properties have been fetched (see refresh_server_properties).
m_serverStatus = Status::Starting;
on_server_dbus_registered();
}
}
wivrn_server::~wivrn_server()
@@ -220,8 +228,6 @@ void wivrn_server::on_server_ready_read_standard_output()
void wivrn_server::on_server_dbus_registered()
{
serverStatusChanged(m_serverStatus = Status::Started);
if (server_interface)
server_interface->deleteLater();
if (server_properties_interface)
@@ -233,7 +239,11 @@ void wivrn_server::on_server_dbus_registered()
connect(server_properties_interface.get(), &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this, &wivrn_server::on_server_properties_changed);
connect(server_interface.get(), &IoGithubWivrnServerInterface::ServerError, [this](const QString & w, const QString & m) { serverError(serverErrorData(w, m)); });
serverStatusChanged(m_serverStatus = Status::Started);
// Server status transitions to Started only after refresh_server_properties
// successfully fetches the initial properties. The well-known D-Bus name
// can be owned before the server exports its interface and populates the
// properties (see on_name_acquired in server/main.cpp), so the name being
// owned alone does not mean the server is usable yet.
refresh_server_properties();
}
@@ -283,7 +293,22 @@ void wivrn_server::refresh_server_properties()
get_all_properties_call_watcher = std::make_unique<QDBusPendingCallWatcher>(props_pending, this);
connect(get_all_properties_call_watcher.get(), &QDBusPendingCallWatcher::finished, [this, props_pending]() {
on_server_properties_changed("io.github.wivrn.Server", props_pending.value(), {});
QVariantMap props = props_pending.value();
// The server only exports the D-Bus interface and sets its properties
// from inside on_name_acquired (server/main.cpp), after it owns the
// well-known name. Our GetAll can race ahead of that and come back
// with an error or an empty reply that does not contain
// JsonConfiguration. In that case, retry shortly after until the
// properties become available.
if (props_pending.isError() || !props.contains("JsonConfiguration"))
{
QTimer::singleShot(200, this, &wivrn_server::refresh_server_properties);
return;
}
on_server_properties_changed("io.github.wivrn.Server", props, {});
if (m_serverStatus != Status::Started)
serverStatusChanged(m_serverStatus = Status::Started);
});
}