Allow custom path for adb in dashboard

This commit is contained in:
Patrick Nicolas
2025-04-17 19:35:31 +02:00
parent 28943c117f
commit 5b0182ed5f
5 changed files with 137 additions and 51 deletions
+27 -9
View File
@@ -23,6 +23,7 @@
#include <QCoroQmlTask> #include <QCoroQmlTask>
#include <QProcess> #include <QProcess>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSettings>
#include <algorithm> #include <algorithm>
#include <vector> #include <vector>
@@ -30,12 +31,20 @@ using namespace std::chrono_literals;
adb::adb() adb::adb()
{ {
QTimer::singleShot(0, this, &adb::checkIfAdbIsInstalled); QSettings settings;
if (settings.value("adb_custom").toBool())
setPath(settings.value("adb_location").toString());
else
setPath("adb");
} }
QCoro::Task<> adb::checkIfAdbIsInstalled() QCoro::Task<> adb::checkIfAdbIsInstalled()
{ {
auto which_adb = escape_sandbox("which", "adb"); std::unique_ptr<QProcess> which_adb;
if (m_path == "adb")
which_adb = escape_sandbox("which", "adb");
else
which_adb = escape_sandbox("test", "-x", m_path);
which_adb->setProcessChannelMode(QProcess::ForwardedErrorChannel); which_adb->setProcessChannelMode(QProcess::ForwardedErrorChannel);
auto co_which_adb = qCoro(*which_adb); auto co_which_adb = qCoro(*which_adb);
@@ -44,7 +53,10 @@ QCoro::Task<> adb::checkIfAdbIsInstalled()
if (which_adb->exitStatus() == QProcess::NormalExit and which_adb->exitCode() == 0) if (which_adb->exitStatus() == QProcess::NormalExit and which_adb->exitCode() == 0)
{ {
qDebug() << "adb found at" << QString{which_adb->readAllStandardOutput()}.trimmed(); if (m_path == "adb")
qDebug() << "adb found at" << QString{which_adb->readAllStandardOutput()}.trimmed();
else
qDebug() << "adb found at" << m_path << "(custom path)";
if (!m_adb_installed) if (!m_adb_installed)
{ {
@@ -68,14 +80,14 @@ QCoro::Task<> adb::on_poll_devices_timeout()
{ {
if (m_android_devices.empty()) if (m_android_devices.empty())
{ {
auto wait_for_usb_device = escape_sandbox("adb", "wait-for-usb-device"); auto wait_for_usb_device = escape_sandbox(m_path, "wait-for-usb-device");
auto co_wait_for_usb_device = qCoro(*wait_for_usb_device); auto co_wait_for_usb_device = qCoro(*wait_for_usb_device);
co_await co_wait_for_usb_device.start(); co_await co_wait_for_usb_device.start();
co_await co_wait_for_usb_device.waitForFinished(-1); co_await co_wait_for_usb_device.waitForFinished(-1);
} }
auto adb_devices = escape_sandbox("adb", "devices"); auto adb_devices = escape_sandbox(m_path, "devices");
adb_devices->setProcessChannelMode(QProcess::ForwardedErrorChannel); adb_devices->setProcessChannelMode(QProcess::ForwardedErrorChannel);
auto co_adb_devices = qCoro(*adb_devices); auto co_adb_devices = qCoro(*adb_devices);
@@ -147,7 +159,7 @@ QCoro::Task<> adb::add_device(QString serial)
{ {
device new_dev{.serial = serial}; device new_dev{.serial = serial};
auto list_packages = escape_sandbox("adb", "-s", serial, "shell", "pm", "list", "packages"); auto list_packages = escape_sandbox(m_path, "-s", serial, "shell", "pm", "list", "packages");
list_packages->setProcessChannelMode(QProcess::ForwardedErrorChannel); list_packages->setProcessChannelMode(QProcess::ForwardedErrorChannel);
auto co_list_packages = qCoro(*list_packages); auto co_list_packages = qCoro(*list_packages);
@@ -172,7 +184,7 @@ QCoro::Task<> adb::add_device(QString serial)
} }
} }
auto getprop = escape_sandbox("adb", "-s", new_dev.serial, "shell", "getprop"); auto getprop = escape_sandbox(m_path, "-s", new_dev.serial, "shell", "getprop");
getprop->setProcessChannelMode(QProcess::ForwardedErrorChannel); getprop->setProcessChannelMode(QProcess::ForwardedErrorChannel);
auto co_get_prop = qCoro(*getprop); auto co_get_prop = qCoro(*getprop);
@@ -277,6 +289,12 @@ QVariant adb::data(const QModelIndex & index, int role) const
} }
// END // END
void adb::setPath(QString path)
{
m_path = path;
QTimer::singleShot(0, this, &adb::checkIfAdbIsInstalled);
}
QCoro::QmlTask adb::startUsbConnection(QString serial, QString pin) QCoro::QmlTask adb::startUsbConnection(QString serial, QString pin)
{ {
return doStartUsbConnection(serial, pin); return doStartUsbConnection(serial, pin);
@@ -289,7 +307,7 @@ QCoro::Task<> adb::doStartUsbConnection(QString serial, QString pin)
if (it == m_android_devices.end()) if (it == m_android_devices.end())
co_return; co_return;
auto adb_reverse = escape_sandbox("adb", "-s", serial, "reverse", "tcp:9757", "tcp:9757"); auto adb_reverse = escape_sandbox(m_path, "-s", serial, "reverse", "tcp:9757", "tcp:9757");
adb_reverse->setProcessChannelMode(QProcess::ForwardedChannels); adb_reverse->setProcessChannelMode(QProcess::ForwardedChannels);
auto co_process = qCoro(*adb_reverse); auto co_process = qCoro(*adb_reverse);
@@ -304,7 +322,7 @@ QCoro::Task<> adb::doStartUsbConnection(QString serial, QString pin)
QString uri = pin == "" ? "wivrn+tcp://127.0.0.1:9757" : "wivrn+tcp://:" + pin + "@127.0.0.1:9757"; QString uri = pin == "" ? "wivrn+tcp://127.0.0.1:9757" : "wivrn+tcp://:" + pin + "@127.0.0.1:9757";
auto adb_start_activity = escape_sandbox("adb", "-s", serial, "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", uri, it->app); auto adb_start_activity = escape_sandbox(m_path, "-s", serial, "shell", "am", "start", "-a", "android.intent.action.VIEW", "-d", uri, it->app);
adb_start_activity->setProcessChannelMode(QProcess::ForwardedChannels); adb_start_activity->setProcessChannelMode(QProcess::ForwardedChannels);
auto co_adb_start_activity = qCoro(*adb_start_activity); auto co_adb_start_activity = qCoro(*adb_start_activity);
+3
View File
@@ -42,6 +42,7 @@ class adb : public QAbstractListModel
Q_PROPERTY(bool adbInstalled READ adbInstalled NOTIFY adbInstalledChanged) Q_PROPERTY(bool adbInstalled READ adbInstalled NOTIFY adbInstalledChanged)
bool m_adb_installed = false; bool m_adb_installed = false;
QString m_path;
std::vector<device> m_android_devices; std::vector<device> m_android_devices;
QCoro::Task<> on_poll_devices_timeout(); QCoro::Task<> on_poll_devices_timeout();
@@ -73,6 +74,8 @@ public:
QVariant data(const QModelIndex & index, int role) const override; QVariant data(const QModelIndex & index, int role) const override;
Q_INVOKABLE void setPath(QString path);
protected: protected:
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
+13 -13
View File
@@ -22,23 +22,12 @@
#include <QProcess> #include <QProcess>
#include <string> #include <string>
template <typename... Args> template <typename U, typename... Args>
std::unique_ptr<QProcess> escape_sandbox(const std::string & executable, Args &&... args_orig) std::unique_ptr<QProcess> escape_sandbox(U && executable, Args &&... args_orig)
{ {
auto process = std::make_unique<QProcess>(); auto process = std::make_unique<QProcess>();
QStringList args; QStringList args;
if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
{
process->setProgram("flatpak-spawn");
args.push_back("--host");
args.push_back(QString::fromStdString(executable));
}
else
{
process->setProgram(QString::fromStdString(executable));
}
auto to_QString = [](const auto & s) { auto to_QString = [](const auto & s) {
using T = std::decay_t<std::remove_cv_t<std::remove_reference_t<decltype(s)>>>; using T = std::decay_t<std::remove_cv_t<std::remove_reference_t<decltype(s)>>>;
@@ -50,6 +39,17 @@ std::unique_ptr<QProcess> escape_sandbox(const std::string & executable, Args &&
return QString::fromStdString(s); return QString::fromStdString(s);
}; };
if (wivrn::flatpak_key(wivrn::flatpak::section::session_bus_policy, "org.freedesktop.Flatpak") == "talk")
{
process->setProgram("flatpak-spawn");
args.push_back("--host");
args.push_back(to_QString(executable));
}
else
{
process->setProgram(to_QString(executable));
}
(args.push_back(to_QString(args_orig)), ...); (args.push_back(to_QString(args_orig)), ...);
process->setArguments(args); process->setArguments(args);
+49
View File
@@ -1,8 +1,10 @@
pragma ComponentBehavior: Bound pragma ComponentBehavior: Bound
import QtCore as Core
import QtQuick import QtQuick
import QtQuick.Layouts import QtQuick.Layouts
import QtQuick.Controls as Controls import QtQuick.Controls as Controls
import QtQuick.Dialogs as Dialogs
import org.kde.kirigami as Kirigami import org.kde.kirigami as Kirigami
import io.github.wivrn.wivrn import io.github.wivrn.wivrn
@@ -17,6 +19,13 @@ Kirigami.ScrollablePage {
id: config id: config
} }
Core.Settings {
property alias adb_custom: settings.adb_custom
property alias adb_location: settings.adb_location
}
property bool adb_custom
property string adb_location
ColumnLayout { ColumnLayout {
id: column id: column
anchors.fill: parent anchors.fill: parent
@@ -302,6 +311,40 @@ Kirigami.ScrollablePage {
enabled: encoder_combo.model[encoder_combo.currentIndex].codecs.split(",").includes(name) enabled: encoder_combo.model[encoder_combo.currentIndex].codecs.split(",").includes(name)
} }
} }
Kirigami.Separator {
Kirigami.FormData.isSection: true
}
Controls.CheckBox {
id: adb_custom
Layout.row: 0
Layout.column: 0
text: i18n("Custom adb location")
}
Dialogs.FileDialog {
id: adb_browse
onAccepted: {
adb_location.text = new URL(selectedFile).pathname;
}
}
RowLayout {
Kirigami.FormData.label: i18n("Adb location:")
Layout.fillWidth: true
enabled: adb_custom.checked
Controls.TextField {
id: adb_location
placeholderText: settings.adb
Layout.fillWidth: true
}
Controls.Button {
text: i18nc("browse a file to choose the adb binary", "Browse")
onClicked: adb_browse.open()
}
}
} }
Item { Item {
@@ -335,6 +378,9 @@ Kirigami.ScrollablePage {
config.bitrate = bitrate.value * 1000000; config.bitrate = bitrate.value * 1000000;
config.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1; config.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1;
config.manualEncoders = encoder_layout.currentIndex > 0; config.manualEncoders = encoder_layout.currentIndex > 0;
settings.adb_custom = adb_custom.checked;
settings.adb_location = adb_location.text;
Adb.setPath(adb_custom.checked ? adb_location.text : "adb");
} }
function load() { function load() {
@@ -354,6 +400,9 @@ Kirigami.ScrollablePage {
// auto_encoders.checked = true; // auto_encoders.checked = true;
encoder_layout.currentIndex = 0; encoder_layout.currentIndex = 0;
} }
adb_custom.checked = settings.adb_custom;
adb_location.text = settings.adb_location;
} }
Shortcut { Shortcut {
+45 -29
View File
@@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: WiVRn-dashboard\n" "Project-Id-Version: WiVRn-dashboard\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-03-25 21:15+0100\n" "POT-Creation-Date: 2025-04-17 19:30+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Guillaume Meunier <guillaume.meunier@centraliens.net>\n" "Last-Translator: Guillaume Meunier <guillaume.meunier@centraliens.net>\n"
"Language: French\n" "Language: French\n"
@@ -331,7 +331,7 @@ msgstr "Assistant"
msgid "Install the app" msgid "Install the app"
msgstr "Installer l'appli" msgstr "Installer l'appli"
#: dashboard/qml/Main.qml:349 dashboard/qml/SettingsPage.qml:12 #: dashboard/qml/Main.qml:349 dashboard/qml/SettingsPage.qml:14
#, kde-format #, kde-format
msgid "Settings" msgid "Settings"
msgstr "Paramètres" msgstr "Paramètres"
@@ -359,23 +359,23 @@ msgctxt "browse a file to choose the application to start"
msgid "Browse" msgid "Browse"
msgstr "Parcourir" msgstr "Parcourir"
#: dashboard/qml/SettingsPage.qml:31 #: dashboard/qml/SettingsPage.qml:40
#, kde-format #, kde-format
msgctxt "automatic foveation setup" msgctxt "automatic foveation setup"
msgid "Manual foveation" msgid "Manual foveation"
msgstr "Fovéation manuelle" msgstr "Fovéation manuelle"
#: dashboard/qml/SettingsPage.qml:37 #: dashboard/qml/SettingsPage.qml:46
#, kde-format #, kde-format
msgid "Foveation strength:" msgid "Foveation strength:"
msgstr "Intensité de fovéation :" msgstr "Intensité de fovéation :"
#: dashboard/qml/SettingsPage.qml:53 #: dashboard/qml/SettingsPage.qml:62
#, kde-format #, kde-format
msgid "%1 %" msgid "%1 %"
msgstr "%1 %" msgstr "%1 %"
#: dashboard/qml/SettingsPage.qml:59 #: dashboard/qml/SettingsPage.qml:68
#, kde-format #, kde-format
msgid "" msgid ""
"A stronger foveation makes the image sharper in the center than in the " "A stronger foveation makes the image sharper in the center than in the "
@@ -394,65 +394,65 @@ msgstr ""
"Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi " "Les valeurs recommandées sont entre 20% et 50% pour les casques sans suivi "
"des yeux et entre 50% et 70% pour les casques avec suivi des yeux." "des yeux et entre 50% et 70% pour les casques avec suivi des yeux."
#: dashboard/qml/SettingsPage.qml:65 #: dashboard/qml/SettingsPage.qml:74
#, kde-format #, kde-format
msgctxt "weaker foveation" msgctxt "weaker foveation"
msgid "Weaker" msgid "Weaker"
msgstr "Faible" msgstr "Faible"
#: dashboard/qml/SettingsPage.qml:76 #: dashboard/qml/SettingsPage.qml:85
#, kde-format #, kde-format
msgctxt "stronger foveation" msgctxt "stronger foveation"
msgid "Stronger" msgid "Stronger"
msgstr "Fort" msgstr "Fort"
#: dashboard/qml/SettingsPage.qml:86 #: dashboard/qml/SettingsPage.qml:95
#, kde-format #, kde-format
msgid "Bitrate:" msgid "Bitrate:"
msgstr "Débit :" msgstr "Débit :"
#: dashboard/qml/SettingsPage.qml:90 dashboard/qml/SettingsPage.qml:92 #: dashboard/qml/SettingsPage.qml:99 dashboard/qml/SettingsPage.qml:101
#, kde-format #, kde-format
msgctxt "bitrate" msgctxt "bitrate"
msgid "%1 Mbit/s" msgid "%1 Mbit/s"
msgstr "%1 Mbit/s" msgstr "%1 Mbit/s"
#: dashboard/qml/SettingsPage.qml:102 #: dashboard/qml/SettingsPage.qml:111
#, kde-format #, kde-format
msgid "Encoder layout:" msgid "Encoder layout:"
msgstr "Disposition :" msgstr "Disposition :"
#: dashboard/qml/SettingsPage.qml:105 #: dashboard/qml/SettingsPage.qml:114
#, kde-format #, kde-format
msgctxt "encoder preset" msgctxt "encoder preset"
msgid "Automatic" msgid "Automatic"
msgstr "Automatique" msgstr "Automatique"
#: dashboard/qml/SettingsPage.qml:109 #: dashboard/qml/SettingsPage.qml:118
#, kde-format #, kde-format
msgctxt "encoder preset" msgctxt "encoder preset"
msgid "Manual" msgid "Manual"
msgstr "Manuelle" msgstr "Manuelle"
#: dashboard/qml/SettingsPage.qml:113 #: dashboard/qml/SettingsPage.qml:122
#, kde-format #, kde-format
msgctxt "encoder preset" msgctxt "encoder preset"
msgid "Default preset" msgid "Default preset"
msgstr "Configuration prédéfinie : par défaut" msgstr "Configuration prédéfinie : par défaut"
#: dashboard/qml/SettingsPage.qml:136 #: dashboard/qml/SettingsPage.qml:145
#, kde-format #, kde-format
msgctxt "encoder preset" msgctxt "encoder preset"
msgid "Low latency preset" msgid "Low latency preset"
msgstr "Configuration prédéfinie : basse latence" msgstr "Configuration prédéfinie : basse latence"
#: dashboard/qml/SettingsPage.qml:161 #: dashboard/qml/SettingsPage.qml:170
#, kde-format #, kde-format
msgctxt "encoder preset" msgctxt "encoder preset"
msgid "Safe preset" msgid "Safe preset"
msgstr "Configuration prédéfinie : sure" msgstr "Configuration prédéfinie : sure"
#: dashboard/qml/SettingsPage.qml:184 #: dashboard/qml/SettingsPage.qml:193
#, kde-format #, kde-format
msgid "" msgid ""
"To add a new encoder, split an existing encoder by clicking near an edge.\n" "To add a new encoder, split an existing encoder by clicking near an edge.\n"
@@ -462,69 +462,85 @@ msgstr ""
"d'un bord.\n" "d'un bord.\n"
"Déplacez un bord pour redimensionner ou supprimer un encodeur." "Déplacez un bord pour redimensionner ou supprimer un encodeur."
#: dashboard/qml/SettingsPage.qml:211 #: dashboard/qml/SettingsPage.qml:220
#, kde-format #, kde-format
msgid "Encoder:" msgid "Encoder:"
msgstr "Encodeur :" msgstr "Encodeur :"
#: dashboard/qml/SettingsPage.qml:220 #: dashboard/qml/SettingsPage.qml:229
#, kde-format #, kde-format
msgctxt "automatic encoder setup" msgctxt "automatic encoder setup"
msgid "Auto" msgid "Auto"
msgstr "Automatique" msgstr "Automatique"
#: dashboard/qml/SettingsPage.qml:225 #: dashboard/qml/SettingsPage.qml:234
#, kde-format #, kde-format
msgid "nvenc (NVIDIA GPUs)" msgid "nvenc (NVIDIA GPUs)"
msgstr "nvenc (GPUs NVIDIA)" msgstr "nvenc (GPUs NVIDIA)"
#: dashboard/qml/SettingsPage.qml:230 #: dashboard/qml/SettingsPage.qml:239
#, kde-format #, kde-format
msgid "vaapi (AMD and Intel GPUs)" msgid "vaapi (AMD and Intel GPUs)"
msgstr "vaapi (GPUs AMD et Intel)" msgstr "vaapi (GPUs AMD et Intel)"
#: dashboard/qml/SettingsPage.qml:235 #: dashboard/qml/SettingsPage.qml:244
#, kde-format #, kde-format
msgid "x264 (software encoding)" msgid "x264 (software encoding)"
msgstr "x264 (encodage logiciel)" msgstr "x264 (encodage logiciel)"
#: dashboard/qml/SettingsPage.qml:240 #: dashboard/qml/SettingsPage.qml:249
#, kde-format #, kde-format
msgid "Vulkan (Vulkan Video)" msgid "Vulkan (Vulkan Video)"
msgstr "Vulkan (Vulkan Vidéo)" msgstr "Vulkan (Vulkan Vidéo)"
#: dashboard/qml/SettingsPage.qml:263 #: dashboard/qml/SettingsPage.qml:272
#, kde-format #, kde-format
msgid "\"Auto\" will use hardware acceleration if it is available" msgid "\"Auto\" will use hardware acceleration if it is available"
msgstr "" msgstr ""
"\"Automatique\" utilisera l'accélération matérielle si elle est disponible" "\"Automatique\" utilisera l'accélération matérielle si elle est disponible"
#: dashboard/qml/SettingsPage.qml:269 #: dashboard/qml/SettingsPage.qml:278
#, kde-format #, kde-format
msgid "Codec:" msgid "Codec:"
msgstr "Codec :" msgstr "Codec :"
#: dashboard/qml/SettingsPage.qml:276 #: dashboard/qml/SettingsPage.qml:285
#, kde-format #, kde-format
msgctxt "automatic codec setup" msgctxt "automatic codec setup"
msgid "Auto" msgid "Auto"
msgstr "Automatique" msgstr "Automatique"
#: dashboard/qml/SettingsPage.qml:280 #: dashboard/qml/SettingsPage.qml:289
#, kde-format #, kde-format
msgid "H.264" msgid "H.264"
msgstr "H.264" msgstr "H.264"
#: dashboard/qml/SettingsPage.qml:284 #: dashboard/qml/SettingsPage.qml:293
#, kde-format #, kde-format
msgid "H.265" msgid "H.265"
msgstr "H.265" msgstr "H.265"
#: dashboard/qml/SettingsPage.qml:288 #: dashboard/qml/SettingsPage.qml:297
#, kde-format #, kde-format
msgid "AV1" msgid "AV1"
msgstr "AV1" msgstr "AV1"
#: dashboard/qml/SettingsPage.qml:323
#, kde-format
msgid "Custom adb location"
msgstr "Spécifier l'emplacement d'adb"
#: dashboard/qml/SettingsPage.qml:334
#, kde-format
msgid "Adb location:"
msgstr "Emplacement d'adb"
#: dashboard/qml/SettingsPage.qml:343
#, kde-format
msgctxt "browse a file to choose the adb binary"
msgid "Browse"
msgstr "Parcourir"
#: dashboard/qml/SteamLaunchOptions.qml:8 #: dashboard/qml/SteamLaunchOptions.qml:8
#, kde-format #, kde-format
msgid "" msgid ""