Allow custom path for adb in dashboard
This commit is contained in:
+27
-9
@@ -23,6 +23,7 @@
|
||||
#include <QCoroQmlTask>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QSettings>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
@@ -30,12 +31,20 @@ using namespace std::chrono_literals;
|
||||
|
||||
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()
|
||||
{
|
||||
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);
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -68,14 +80,14 @@ QCoro::Task<> adb::on_poll_devices_timeout()
|
||||
{
|
||||
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);
|
||||
|
||||
co_await co_wait_for_usb_device.start();
|
||||
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);
|
||||
auto co_adb_devices = qCoro(*adb_devices);
|
||||
|
||||
@@ -147,7 +159,7 @@ QCoro::Task<> adb::add_device(QString 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);
|
||||
|
||||
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);
|
||||
|
||||
auto co_get_prop = qCoro(*getprop);
|
||||
@@ -277,6 +289,12 @@ QVariant adb::data(const QModelIndex & index, int role) const
|
||||
}
|
||||
// END
|
||||
|
||||
void adb::setPath(QString path)
|
||||
{
|
||||
m_path = path;
|
||||
QTimer::singleShot(0, this, &adb::checkIfAdbIsInstalled);
|
||||
}
|
||||
|
||||
QCoro::QmlTask adb::startUsbConnection(QString serial, QString pin)
|
||||
{
|
||||
return doStartUsbConnection(serial, pin);
|
||||
@@ -289,7 +307,7 @@ QCoro::Task<> adb::doStartUsbConnection(QString serial, QString pin)
|
||||
if (it == m_android_devices.end())
|
||||
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);
|
||||
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";
|
||||
|
||||
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);
|
||||
auto co_adb_start_activity = qCoro(*adb_start_activity);
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ class adb : public QAbstractListModel
|
||||
Q_PROPERTY(bool adbInstalled READ adbInstalled NOTIFY adbInstalledChanged)
|
||||
|
||||
bool m_adb_installed = false;
|
||||
QString m_path;
|
||||
std::vector<device> m_android_devices;
|
||||
|
||||
QCoro::Task<> on_poll_devices_timeout();
|
||||
@@ -73,6 +74,8 @@ public:
|
||||
|
||||
QVariant data(const QModelIndex & index, int role) const override;
|
||||
|
||||
Q_INVOKABLE void setPath(QString path);
|
||||
|
||||
protected:
|
||||
QHash<int, QByteArray> roleNames() const override;
|
||||
|
||||
|
||||
+13
-13
@@ -22,23 +22,12 @@
|
||||
#include <QProcess>
|
||||
#include <string>
|
||||
|
||||
template <typename... Args>
|
||||
std::unique_ptr<QProcess> escape_sandbox(const std::string & executable, Args &&... args_orig)
|
||||
template <typename U, typename... Args>
|
||||
std::unique_ptr<QProcess> escape_sandbox(U && executable, Args &&... args_orig)
|
||||
{
|
||||
auto process = std::make_unique<QProcess>();
|
||||
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) {
|
||||
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);
|
||||
};
|
||||
|
||||
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)), ...);
|
||||
|
||||
process->setArguments(args);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtCore as Core
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import QtQuick.Controls as Controls
|
||||
import QtQuick.Dialogs as Dialogs
|
||||
import org.kde.kirigami as Kirigami
|
||||
|
||||
import io.github.wivrn.wivrn
|
||||
@@ -17,6 +19,13 @@ Kirigami.ScrollablePage {
|
||||
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 {
|
||||
id: column
|
||||
anchors.fill: parent
|
||||
@@ -302,6 +311,40 @@ Kirigami.ScrollablePage {
|
||||
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 {
|
||||
@@ -335,6 +378,9 @@ Kirigami.ScrollablePage {
|
||||
config.bitrate = bitrate.value * 1000000;
|
||||
config.scale = manual_foveation.checked ? 1 - scale_slider.value / 100.0 : -1;
|
||||
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() {
|
||||
@@ -354,6 +400,9 @@ Kirigami.ScrollablePage {
|
||||
// auto_encoders.checked = true;
|
||||
encoder_layout.currentIndex = 0;
|
||||
}
|
||||
|
||||
adb_custom.checked = settings.adb_custom;
|
||||
adb_location.text = settings.adb_location;
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
|
||||
Reference in New Issue
Block a user