Use common app list for dashboard
This commit is contained in:
@@ -10,7 +10,7 @@ add_executable(wivrn-dashboard
|
|||||||
main.cpp
|
main.cpp
|
||||||
wivrn_server.cpp
|
wivrn_server.cpp
|
||||||
wivrn_qdbus_types.cpp
|
wivrn_qdbus_types.cpp
|
||||||
steam_apps.cpp
|
apps.cpp
|
||||||
escape_string.cpp
|
escape_string.cpp
|
||||||
settings.cpp
|
settings.cpp
|
||||||
rectangle_partitionner.cpp
|
rectangle_partitionner.cpp
|
||||||
|
|||||||
@@ -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"
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* WiVRn VR streaming
|
* WiVRn VR streaming
|
||||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
* 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
@@ -21,37 +22,30 @@
|
|||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include <qqmlintegration.h>
|
#include <qqmlintegration.h>
|
||||||
|
|
||||||
class steamApp
|
class vrApp
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
QML_VALUE_TYPE(steamApp)
|
QML_VALUE_TYPE(vrApp)
|
||||||
Q_PROPERTY(QString name READ name WRITE setName)
|
Q_PROPERTY(QString name READ name WRITE setName)
|
||||||
Q_PROPERTY(QString imagePath READ imagePath WRITE setImagePath)
|
|
||||||
Q_PROPERTY(QString command READ command WRITE setCommand)
|
Q_PROPERTY(QString command READ command WRITE setCommand)
|
||||||
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_imagePath;
|
|
||||||
QString m_command;
|
QString m_command;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
steamApp() = default;
|
vrApp() = default;
|
||||||
steamApp(const steamApp &) = default;
|
vrApp(const vrApp &) = default;
|
||||||
steamApp(steamApp &&) = default;
|
vrApp(vrApp &&) = default;
|
||||||
steamApp & operator=(const steamApp &) = default;
|
vrApp & operator=(const vrApp &) = default;
|
||||||
steamApp & operator=(steamApp &&) = default;
|
vrApp & operator=(vrApp &&) = default;
|
||||||
steamApp(QString name, QString imagePath, QString command) :
|
vrApp(QString name, QString command) :
|
||||||
m_name(name), m_imagePath(imagePath), m_command(command) {}
|
m_name(name), m_command(command) {}
|
||||||
|
|
||||||
QString name() const
|
QString name() const
|
||||||
{
|
{
|
||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString imagePath() const
|
|
||||||
{
|
|
||||||
return m_imagePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString command() const
|
QString command() const
|
||||||
{
|
{
|
||||||
return m_command;
|
return m_command;
|
||||||
@@ -62,11 +56,6 @@ public:
|
|||||||
m_name = value;
|
m_name = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setImagePath(QString value)
|
|
||||||
{
|
|
||||||
m_imagePath = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCommand(QString value)
|
void setCommand(QString value)
|
||||||
{
|
{
|
||||||
m_command = value;
|
m_command = value;
|
||||||
@@ -77,30 +66,25 @@ public:
|
|||||||
m_name = QString::fromStdString(value);
|
m_name = QString::fromStdString(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setImagePath(const std::string & value)
|
|
||||||
{
|
|
||||||
m_imagePath = QString::fromStdString(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setCommand(const std::string & value)
|
void setCommand(const std::string & value)
|
||||||
{
|
{
|
||||||
m_command = QString::fromStdString(value);
|
m_command = QString::fromStdString(value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class SteamApps : public QObject
|
class Apps : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
QML_ELEMENT
|
QML_ELEMENT
|
||||||
QML_SINGLETON
|
QML_SINGLETON
|
||||||
|
|
||||||
Q_PROPERTY(QList<steamApp> apps READ apps)
|
Q_PROPERTY(QList<vrApp> apps READ apps)
|
||||||
QList<steamApp> m_apps;
|
QList<vrApp> m_apps;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SteamApps(QObject * parent = nullptr);
|
Apps(QObject * parent = nullptr);
|
||||||
|
|
||||||
const QList<steamApp> & apps() const
|
const QList<vrApp> & apps() const
|
||||||
{
|
{
|
||||||
return m_apps;
|
return m_apps;
|
||||||
}
|
}
|
||||||
@@ -12,24 +12,21 @@ ColumnLayout {
|
|||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
apps.append({
|
apps.append({
|
||||||
"name": i18nc("don't start an application automatically", "None"),
|
"name": i18nc("don't start an application automatically", "None"),
|
||||||
"image_path": "",
|
|
||||||
"command": "",
|
"command": "",
|
||||||
"is_custom": false
|
"is_custom": false
|
||||||
});
|
});
|
||||||
|
|
||||||
apps.append({
|
apps.append({
|
||||||
"name": i18nc("choose a custom application to start", "Custom"),
|
"name": i18nc("choose a custom application to start", "Custom"),
|
||||||
"image_path": "",
|
|
||||||
"command": "",
|
"command": "",
|
||||||
"is_custom": true
|
"is_custom": true
|
||||||
});
|
});
|
||||||
|
|
||||||
var steam_apps = SteamApps.apps;
|
var vr_apps = Apps.apps;
|
||||||
for (var i = 0; i < steam_apps.length; i++) {
|
for (var i = 0; i < vr_apps.length; i++) {
|
||||||
apps.append({
|
apps.append({
|
||||||
"name": steam_apps[i].name,
|
"name": vr_apps[i].name,
|
||||||
"image_path": steam_apps[i].imagePath,
|
"command": vr_apps[i].command,
|
||||||
"command": steam_apps[i].command,
|
|
||||||
"is_custom": false
|
"is_custom": false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
|
||||||
Reference in New Issue
Block a user