Use common app list for dashboard

This commit is contained in:
Patrick Nicolas
2025-07-25 22:10:47 +02:00
parent f0e625e095
commit 6f039a6bac
5 changed files with 63 additions and 151 deletions
+1 -1
View File
@@ -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
+43
View File
@@ -0,0 +1,43 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "apps.h"
#include "application.h"
#include <ranges>
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"
+15 -31
View File
@@ -1,6 +1,7 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
*
* 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 <QAbstractListModel>
#include <qqmlintegration.h>
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<steamApp> apps READ apps)
QList<steamApp> m_apps;
Q_PROPERTY(QList<vrApp> apps READ apps)
QList<vrApp> m_apps;
public:
SteamApps(QObject * parent = nullptr);
Apps(QObject * parent = nullptr);
const QList<steamApp> & apps() const
const QList<vrApp> & apps() const
{
return m_apps;
}
+4 -7
View File
@@ -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
});
}
-112
View File
@@ -1,112 +0,0 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
#include "steam_apps.h"
#include "escape_string.h"
#include "utils/flatpak.h"
#include <QProcess>
#include <QtLogging>
#include <filesystem>
#include <fstream>
#include <nlohmann/json.hpp>
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<char> 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"