From ef90913426b20f9fa4a7fcdf578107c03c06efca Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Mon, 12 May 2025 20:58:57 +0200 Subject: [PATCH] Get host path for selected application --- dashboard/qml/SelectGame.qml | 2 +- dashboard/wivrn_server.cpp | 22 ++++++++++++++++++++++ dashboard/wivrn_server.h | 3 +++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dashboard/qml/SelectGame.qml b/dashboard/qml/SelectGame.qml index f92fe11f..36807b47 100644 --- a/dashboard/qml/SelectGame.qml +++ b/dashboard/qml/SelectGame.qml @@ -55,7 +55,7 @@ ColumnLayout { Dialogs.FileDialog { id: app_browse onAccepted: { - app_text.text = new URL(selectedFile).pathname; + app_text.text = WivrnServer.host_path(new URL(selectedFile).pathname); select_game.save(); } } diff --git a/dashboard/wivrn_server.cpp b/dashboard/wivrn_server.cpp index e977cf8e..254cfe8b 100644 --- a/dashboard/wivrn_server.cpp +++ b/dashboard/wivrn_server.cpp @@ -19,6 +19,7 @@ #include "wivrn_server.h" #include "gui_config.h" #include "magic_enum.hpp" +#include "utils/flatpak.h" #include "wivrn_server_dbus.h" #include #include @@ -554,6 +555,27 @@ QString wivrn_server::hostname() return _hostname; } +QString wivrn_server::host_path(QString path) +{ + if (not wivrn::is_flatpak()) + return path; + + QDBusInterface docs("org.freedesktop.portal.Documents", "/org/freedesktop/portal/documents", "org.freedesktop.portal.Documents", QDBusConnection::sessionBus()); + if (not docs.isValid()) + return path; + + QString id = QFileInfo(path).dir().dirName(); + [[maybe_unused]] static auto r = qDBusRegisterMetaType>(); + QDBusReply> res = docs.call("GetHostPaths", QStringList(id)); + if ((not res.isValid()) or res.value().empty()) + return path; + + path = res.value().first(); + if (path.endsWith('\0')) + path.chop(1); + return path; +} + void wivrn_server::disconnect_headset() { if (server_interface) diff --git a/dashboard/wivrn_server.h b/dashboard/wivrn_server.h index 18e157e3..009de35f 100644 --- a/dashboard/wivrn_server.h +++ b/dashboard/wivrn_server.h @@ -167,6 +167,9 @@ public: // hostnamed Q_PROPERTY(QString hostname READ hostname CONSTANT) + // flatpak API + Q_INVOKABLE QString host_path(QString path); + Status serverStatus() const { return m_serverStatus;