diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index bdb0bb9a..78d7e4b5 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -10,7 +10,7 @@ add_executable(wivrn-dashboard main.cpp wivrn_server.cpp wivrn_qdbus_types.cpp - steam_apps.cpp + apps.cpp escape_string.cpp settings.cpp rectangle_partitionner.cpp diff --git a/dashboard/apps.cpp b/dashboard/apps.cpp new file mode 100644 index 00000000..2ab62820 --- /dev/null +++ b/dashboard/apps.cpp @@ -0,0 +1,43 @@ +/* + * WiVRn VR streaming + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2025 Patrick Nicolas + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "apps.h" + +#include "application.h" + +#include + +Apps::Apps(QObject * parent) +{ + auto apps = wivrn::list_applications(); + + for (const auto & [id, app]: apps) + { + m_apps.push_back( + vrApp( + QString::fromStdString(app.name.at("")), + QString::fromStdString(app.exec))); + } + + std::ranges::sort(m_apps, [](const vrApp & a, const vrApp & b) { + return a.name() < b.name(); + }); +} + +#include "moc_apps.cpp" diff --git a/dashboard/steam_apps.h b/dashboard/apps.h similarity index 63% rename from dashboard/steam_apps.h rename to dashboard/apps.h index 91e6b9ee..d62bcdaa 100644 --- a/dashboard/steam_apps.h +++ b/dashboard/apps.h @@ -1,6 +1,7 @@ /* * WiVRn VR streaming * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2025 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,37 +22,30 @@ #include #include -class steamApp +class vrApp { Q_GADGET - QML_VALUE_TYPE(steamApp) + QML_VALUE_TYPE(vrApp) Q_PROPERTY(QString name READ name WRITE setName) - Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath) Q_PROPERTY(QString command READ command WRITE setCommand) QString m_name; - QString m_imagePath; QString m_command; public: - steamApp() = default; - steamApp(const steamApp &) = default; - steamApp(steamApp &&) = default; - steamApp & operator=(const steamApp &) = default; - steamApp & operator=(steamApp &&) = default; - steamApp(QString name, QString imagePath, QString command) : - m_name(name), m_imagePath(imagePath), m_command(command) {} + vrApp() = default; + vrApp(const vrApp &) = default; + vrApp(vrApp &&) = default; + vrApp & operator=(const vrApp &) = default; + vrApp & operator=(vrApp &&) = default; + vrApp(QString name, QString command) : + m_name(name), m_command(command) {} QString name() const { return m_name; } - QString imagePath() const - { - return m_imagePath; - } - QString command() const { return m_command; @@ -62,11 +56,6 @@ public: m_name = value; } - void setImagePath(QString value) - { - m_imagePath = value; - } - void setCommand(QString value) { m_command = value; @@ -77,30 +66,25 @@ public: m_name = QString::fromStdString(value); } - void setImagePath(const std::string & value) - { - m_imagePath = QString::fromStdString(value); - } - void setCommand(const std::string & value) { m_command = QString::fromStdString(value); } }; -class SteamApps : public QObject +class Apps : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON - Q_PROPERTY(QList apps READ apps) - QList m_apps; + Q_PROPERTY(QList apps READ apps) + QList m_apps; public: - SteamApps(QObject * parent = nullptr); + Apps(QObject * parent = nullptr); - const QList & apps() const + const QList & apps() const { return m_apps; } diff --git a/dashboard/qml/SelectGame.qml b/dashboard/qml/SelectGame.qml index 36807b47..f3ad522d 100644 --- a/dashboard/qml/SelectGame.qml +++ b/dashboard/qml/SelectGame.qml @@ -12,24 +12,21 @@ ColumnLayout { Component.onCompleted: { apps.append({ "name": i18nc("don't start an application automatically", "None"), - "image_path": "", "command": "", "is_custom": false }); apps.append({ "name": i18nc("choose a custom application to start", "Custom"), - "image_path": "", "command": "", "is_custom": true }); - var steam_apps = SteamApps.apps; - for (var i = 0; i < steam_apps.length; i++) { + var vr_apps = Apps.apps; + for (var i = 0; i < vr_apps.length; i++) { apps.append({ - "name": steam_apps[i].name, - "image_path": steam_apps[i].imagePath, - "command": steam_apps[i].command, + "name": vr_apps[i].name, + "command": vr_apps[i].command, "is_custom": false }); } diff --git a/dashboard/steam_apps.cpp b/dashboard/steam_apps.cpp deleted file mode 100644 index 0fd18ed4..00000000 --- a/dashboard/steam_apps.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * WiVRn VR streaming - * Copyright (C) 2024 Guillaume Meunier - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "steam_apps.h" -#include "escape_string.h" -#include "utils/flatpak.h" -#include -#include -#include -#include -#include - -namespace -{ -std::string read_vr_manifest() -{ - const char * home = getenv("HOME"); - - std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"; - - if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk") - { - QProcess flatpak_spawn; - flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); - flatpak_spawn.waitForFinished(); - return flatpak_spawn.readAllStandardOutput().toStdString(); - } - else - { - std::ifstream f(vrmanifest); - std::istreambuf_iterator begin{f}, end; - - return {begin, end}; - } -} -} // namespace - -SteamApps::SteamApps(QObject * parent) -{ - auto manifest = read_vr_manifest(); - if (manifest.empty()) - { - return; - } - - nlohmann::json json; - try - { - json = nlohmann::json::parse(manifest); - } - catch (std::exception & e) - { - qWarning() << "Error parsing VR manifest: " << e.what(); - return; - } - - for (auto & i: json["applications"]) - { - try - { - steamApp app; - - app.setImagePath(i.value("image_path", "")); - app.setName(i["strings"]["en_us"]["name"]); - - if (i["launch_type"] == "url") - { - app.setCommand("steam " + (std::string)i["url"]); - } - else if (i["launch_type"] == "binary") - { - std::string app_key = i["app_key"]; - - const char prefix[] = "steam.app."; - if (app_key.starts_with(prefix)) - { - // ¯\_(ツ)_/¯ - uint64_t appkey = stoll(app_key.substr(strlen(prefix))); - app.setCommand("steam steam://rungameid/" + std::to_string((appkey << 32) + 0x2000000)); - } - } - - if (app.command() != "") - m_apps.push_back(app); - } - catch (std::exception & e) - { - qWarning() << "Error adding app from VR manifest: " << e.what(); - } - } - - std::ranges::sort(m_apps, [](const steamApp & a, const steamApp & b) { - return a.name() < b.name(); - }); -} - -#include "moc_steam_apps.cpp"