mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-26 03:46:49 -08:00
Add check for snap/flatpak Steam
This commit is contained in:
1 parent
9a55178b41
commit
aff498bc2d
8 files changed
+232
-7
No files matched your search
@@ -19,21 +19,21 @@
|
||||
|
||||
#include "strings.h"
|
||||
|
||||
std::vector<std::string> utils::split(const std::string & s, const std::string & sep)
|
||||
std::vector<std::string> utils::split(std::string_view s, std::string_view sep)
|
||||
{
|
||||
std::string::size_type i = 0;
|
||||
std::vector<std::string> v;
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string::size_type j = s.find_first_of(sep, i);
|
||||
if (j == std::string::npos)
|
||||
auto j = s.find_first_of(sep, i);
|
||||
if (j == std::string_view::npos)
|
||||
{
|
||||
v.push_back(s.substr(i));
|
||||
v.emplace_back(s.substr(i));
|
||||
return v;
|
||||
}
|
||||
|
||||
v.push_back(s.substr(i, j - i));
|
||||
v.emplace_back(s.substr(i, j - i));
|
||||
i = j + 1;
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
namespace utils
|
||||
{
|
||||
std::vector<std::string> split(const std::string & s, const std::string & sep = "\n");
|
||||
std::vector<std::string> split(std::string_view s, std::string_view = "\n");
|
||||
|
||||
// https://www.cppstories.com/2021/heterogeneous-access-cpp20/
|
||||
struct string_hash
|
||||
|
||||
@@ -15,6 +15,7 @@ add_executable(wivrn-dashboard
|
||||
dashboard_utils.cpp
|
||||
escape_string.cpp
|
||||
settings.cpp
|
||||
steam.cpp
|
||||
adb.cpp
|
||||
apk_installer.cpp
|
||||
firewall.cpp
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QDBusMetaType>
|
||||
#include <QDBusReply>
|
||||
#include <QDebug>
|
||||
#include <QProcess>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
class firewall : public QObject
|
||||
|
||||
@@ -216,6 +216,28 @@ Kirigami.ApplicationWindow {
|
||||
visible: WivrnServer.openVRCompat.length == 0 && config.openvr == ""
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
text: i18n("Steam is installed as a snap. Snaps are not compatible with WiVRn.")
|
||||
type: Kirigami.MessageType.Warning
|
||||
showCloseButton: true
|
||||
visible: DashboardSettings.show_system_checks && Steam.snap
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
Layout.fillWidth: true
|
||||
text: i18n("Steam is installed as a flatpak but does not have sufficient permissions.")
|
||||
type: Kirigami.MessageType.Warning
|
||||
showCloseButton: true
|
||||
visible: DashboardSettings.show_system_checks && Steam.flatpakNeedPerm
|
||||
actions: [
|
||||
Kirigami.Action {
|
||||
text: i18n("Fix it")
|
||||
onTriggered: Steam.fixFlatpakPerm()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Kirigami.InlineMessage {
|
||||
id: message_failed_to_start
|
||||
Layout.fillWidth: true
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <[email protected]>
|
||||
*
|
||||
* 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.h"
|
||||
|
||||
#include "escape_sandbox.h"
|
||||
#include "utils/flatpak.h"
|
||||
#include "utils/ini.h"
|
||||
#include "utils/strings.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
|
||||
bool steam::snap() const
|
||||
{
|
||||
if (wivrn::is_flatpak())
|
||||
{
|
||||
auto test = escape_sandbox("test", "-f", "/snap/bin/steam");
|
||||
test->setProcessChannelMode(QProcess::MergedChannels);
|
||||
test->start();
|
||||
if (test->waitForFinished())
|
||||
return test->exitCode() == 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return std::filesystem::exists("/snap/bin/steam");
|
||||
}
|
||||
|
||||
static QString get_flatpak_scope()
|
||||
{
|
||||
for (const QString scope: {"--user", "--system"})
|
||||
{
|
||||
auto proc = escape_sandbox("flatpak", scope, "info", "com.valvesoftware.Steam");
|
||||
proc->setProcessChannelMode(QProcess::MergedChannels);
|
||||
proc->start();
|
||||
if (proc->waitForFinished() and proc->exitCode() == 0)
|
||||
return scope;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static std::filesystem::path find_dir(const std::filesystem::path & d, const std::filesystem::path & needle)
|
||||
{
|
||||
for (auto copy = d; not copy.empty(); copy = copy.parent_path())
|
||||
{
|
||||
if (copy.filename() == needle)
|
||||
return copy;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
static std::optional<std::string> wivrn_app_path()
|
||||
{
|
||||
if (auto app_path = wivrn::flatpak_key(wivrn::flatpak::section::instance, "app-path"))
|
||||
{
|
||||
if (app_path->starts_with("/var"))
|
||||
return find_dir(*app_path, "io.github.wivrn.wivrn");
|
||||
// assume it's in home
|
||||
return "xdg-data/flatpak/app/io.github.wivrn.wivrn";
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
bool steam::flatpakNeedPerm() const
|
||||
{
|
||||
auto scope = get_flatpak_scope();
|
||||
if (scope.isEmpty())
|
||||
return false;
|
||||
auto proc = escape_sandbox("flatpak", scope, "override", "--show", "com.valvesoftware.Steam");
|
||||
proc->setProcessChannelMode(QProcess::SeparateChannels);
|
||||
proc->start();
|
||||
if (not proc->waitForFinished())
|
||||
{
|
||||
qWarning() << "timeout trying to get Steam flatpak overrides";
|
||||
return false;
|
||||
}
|
||||
if (proc->exitCode())
|
||||
{
|
||||
qWarning() << "failed to get Steam flatpak overrides";
|
||||
return false;
|
||||
}
|
||||
std::stringstream overrides(proc->readAllStandardOutput().toStdString());
|
||||
wivrn::ini ini(overrides);
|
||||
if (auto filesystems = ini.get_optional("Context", "filesystems"))
|
||||
{
|
||||
auto items = utils::split(*filesystems, ";");
|
||||
for (auto & item: items)
|
||||
item = item.substr(0, item.find_last_of(':'));
|
||||
for (const auto & path: {"xdg-run/wivrn", "xdg-config/openxr", "xdg-config/openvr"})
|
||||
{
|
||||
if (not std::ranges::contains(items, path))
|
||||
return true;
|
||||
}
|
||||
if (auto path = wivrn_app_path())
|
||||
{
|
||||
if (not std::ranges::contains(items, path))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void steam::fixFlatpakPerm()
|
||||
{
|
||||
auto scope = get_flatpak_scope();
|
||||
if (scope.isEmpty())
|
||||
return;
|
||||
std::unique_ptr<QProcess> proc;
|
||||
if (scope == "--system")
|
||||
proc = escape_sandbox(
|
||||
"pkexec",
|
||||
"flatpak",
|
||||
"--system",
|
||||
"override",
|
||||
"--filesystem=xdg-run/wivrn:ro",
|
||||
"--filesystem=xdg-config/openxr:ro",
|
||||
"--filesystem=xdg-config/openvr:ro",
|
||||
"--filesystem=" + wivrn_app_path().value_or("xdg-run/wivrn") + ":ro",
|
||||
"com.valvesoftware.Steam");
|
||||
else
|
||||
proc = escape_sandbox(
|
||||
"flatpak",
|
||||
scope,
|
||||
"override",
|
||||
"--filesystem=xdg-run/wivrn:ro",
|
||||
"--filesystem=xdg-config/openxr:ro",
|
||||
"--filesystem=xdg-config/openvr:ro",
|
||||
"--filesystem=" + wivrn_app_path().value_or("xdg-run/wivrn") + ":ro",
|
||||
"com.valvesoftware.Steam");
|
||||
proc->setProcessChannelMode(QProcess::SeparateChannels);
|
||||
proc->start();
|
||||
if (not proc->waitForFinished())
|
||||
{
|
||||
qWarning() << "timeout trying to set Steam flatpak overrides";
|
||||
return;
|
||||
}
|
||||
if (proc->exitCode())
|
||||
{
|
||||
qWarning() << "failed to set Steam flatpak overrides";
|
||||
return;
|
||||
}
|
||||
flatpakNeedPermChanged();
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <[email protected]>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QtQml/qqmlregistration.h>
|
||||
|
||||
class steam : public QObject
|
||||
{
|
||||
public:
|
||||
Q_OBJECT
|
||||
QML_NAMED_ELEMENT(Steam)
|
||||
QML_SINGLETON
|
||||
|
||||
Q_PROPERTY(bool snap READ snap CONSTANT)
|
||||
Q_PROPERTY(bool flatpakNeedPerm READ flatpakNeedPerm NOTIFY flatpakNeedPermChanged)
|
||||
|
||||
public:
|
||||
bool snap() const;
|
||||
bool flatpakNeedPerm() const;
|
||||
|
||||
Q_INVOKABLE void fixFlatpakPerm();
|
||||
|
||||
Q_SIGNALS:
|
||||
void flatpakNeedPermChanged();
|
||||
};
|
||||
Reference in new issue
Block a user