Skip to content

Commit

Permalink
list each user apps
Browse files Browse the repository at this point in the history
  • Loading branch information
victorwads committed Jun 21, 2024
1 parent 970f31d commit 0de2a09
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 11 deletions.
5 changes: 5 additions & 0 deletions content/App.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import QtQuick.Layouts
import VrpManager
import org.kde.kirigami as Kirigami

import "Tabs/Games/"
import "Tabs/Downloads/"
import "Tabs/Devices/"
import "Tabs/Users/"

Kirigami.ApplicationWindow {
id: app

Expand Down
18 changes: 10 additions & 8 deletions content/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ qt6_add_qml_module(content
RESOURCE_PREFIX "/qt/qml"
QML_FILES
App.qml
Games.qml
GameDelegate.qml
Downloads.qml
DownloadDelegate.qml
LocalDelegate.qml
Device.qml
Users.qml
ApplicationDelegate.qml
Tabs/Games/Games.qml
Tabs/Games/GameDelegate.qml
Tabs/Downloads/Downloads.qml
Tabs/Downloads/DownloadDelegate.qml
Tabs/Downloads/LocalDelegate.qml
Tabs/Devices/Device.qml
Tabs/Devices/ApplicationDelegate.qml
Tabs/Users/Users.qml
Tabs/Users/UsersInstalledDelegate.qml
Tabs/Users/UsersToAddDelegate.qml
RESOURCES
fonts/fonts.txt
Image/matrix.png
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 57 additions & 1 deletion content/Users.qml → content/Tabs/Users/Users.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ RowLayout {
user_running.text = app.deviceManager.selectedUserIsLogged
? qsTr("Yes")
: qsTr("No");
installed_apps.text = app.deviceManager.selectedUsersInstalledApps;
onUserAppsListChanged();
}

function onUserAppsListChanged() {
installed_apps.text = app.deviceManager.selectedUsersInstalledApps > -1
? app.deviceManager.selectedUsersInstalledApps
: qsTr("loading...");
}

target: app.deviceManager
Expand Down Expand Up @@ -106,4 +112,54 @@ RowLayout {
}
}
}

GridView {
id: apps_info

Layout.fillHeight: true
Layout.fillWidth: true
snapMode: GridView.SnapToRow
clip: true
cellWidth: 220
cellHeight: 180
model: app.deviceManager.userAppsListModel()

Dialog {
id: confirm_dialog

property string packageName: ""
property int index: -1

anchors.centerIn: parent
title: "Uninstall " + packageName
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
apps_info.model.remove(index);
app.deviceManager.uninstallApkQml(packageName);
}
}

ScrollBar.vertical: ScrollBar {
visible: true
}

delegate: UsersInstalledDelegate {
width: apps_info.cellWidth - 10
height: apps_info.cellHeight - 10
name: model.package_name
thumbnailPath: {
let path = app.vrp.getGameThumbnailPath(model.package_name);
if (path === "")
return "qrc:/qt/qml/content/Image/matrix.png";
else
return "file://" + path;
}
// onUninstallButtonClicked: {
// confirm_dialog.packageName = model.package_name;
// confirm_dialog.index = index;
// confirm_dialog.open();
// }
}

}
}
29 changes: 29 additions & 0 deletions content/Tabs/Users/UsersInstalledDelegate.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import VrpManager
import org.kde.kirigami as Kirigami

Kirigami.Card {
property string name
property string thumbnailPath

signal removeButtonClicked()

banner {
source: thumbnailPath
title: name
titleAlignment: Qt.AlignLeft | Qt.AlignBottom
}

footer: Button {
id: action_button
icon.name: "uninstall"
text: qsTr("Remove from user")
enabled: false
onClicked: {
removeButtonClicked();
}
}

}
29 changes: 29 additions & 0 deletions content/Tabs/Users/UsersToAddDelegate.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import VrpManager
import org.kde.kirigami as Kirigami

Kirigami.Card {
property string name
property string thumbnailPath

signal addButtonClicked()

banner {
source: thumbnailPath
title: name
titleAlignment: Qt.AlignLeft | Qt.AlignBottom
}

footer: Button {
id: action_button
icon.name: "install"
text: qsTr("Remove from user")
onClicked: {
addButtonClicked();
}
}

}
54 changes: 54 additions & 0 deletions src/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DeviceManager::DeviceManager(QObject *parent)
connect(&auto_update_timer_, &QTimer::timeout, this, &DeviceManager::updateSerials);
connect(this, &DeviceManager::connectedDeviceChanged, this, &DeviceManager::updateDeviceInfo);
connect(this, &DeviceManager::connectedDeviceChanged, this, &DeviceManager::updateUsers);
connect(this, &DeviceManager::userInfoChanged, this, &DeviceManager::listPackagesForUser);
}

DeviceManager::~DeviceManager()
Expand Down Expand Up @@ -881,6 +882,11 @@ QCoro::Task<void> DeviceManager::updateUsers()
co_return;
}

/* EXAMPLE OUTPUT:
Users:
UserInfo{0:Victor Wads:c13} running
UserInfo{10:Afonso Ivo Cunha:410}
*/
QString output = basic_process.readAllStandardOutput();
QStringList lines = output.split("\n");
lines.removeAll("");
Expand Down Expand Up @@ -928,4 +934,52 @@ QCoro::Task<void> DeviceManager::selectUser(int index) {

selected_user_ = &users_list_[index];
emit userInfoChanged();
}

QCoro::Task<void> DeviceManager::listPackagesForUser()
{

user_apps_list_model_.clear();
if (!hasConnectedDevice()) {
emit userAppsListChanged();
co_return;
}
auto serial = connectedDevice();

QProcess basic_process;
QString id = QString::number(selected_user_->id);
auto adb = qCoro(basic_process);
adb.start(resolvePrefix(ADB_PATH), {"-s", serial, "shell", "pm", "list", "packages", "--user", id, "--show-versioncode", "-3"});

co_await adb.waitForFinished();

if (basic_process.exitStatus() != QProcess::NormalExit || basic_process.exitCode() != 0) {
qWarning() << "Failed to get apps for device" << serial;
co_return;
}

/* EXAMPLE OUTPUT:
package:com.facebook.arvr.quillplayer versionCode:135
package:com.oculus.mobile_mrc_setup versionCode:1637173263
*/
QString output = basic_process.readAllStandardOutput();
QStringList lines = output.split("\n");
lines.removeAll("");
QRegularExpression re("package:(\\S+) versionCode:(\\d+)");

user_apps_list_model_.clear();
for (const QString &line : lines) {
auto match = re.match(line);
if (match.hasMatch()) {
QString package_name = match.captured(1);
QString version_code = match.captured(2);
auto app = GameInfo{.package_name = package_name, .version_code = version_code};

user_apps_list_model_.append(app);
}
}
selected_user_->installedApps = user_apps_list_model_.size();

emit userAppsListChanged();
co_return;
}
10 changes: 9 additions & 1 deletion src/device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class DeviceManager : public QObject
return &app_list_model_;
}

Q_INVOKABLE GameInfoModel *userAppsListModel()
{
return &user_apps_list_model_;
}

Q_INVOKABLE QCoro::Task<void> updateSerials();
Q_INVOKABLE void updateDeviceInfo();
Q_INVOKABLE QCoro::Task<void> updateDeviceName();
Expand All @@ -100,6 +105,7 @@ class DeviceManager : public QObject
Q_INVOKABLE QCoro::Task<void> updateAppList();
Q_INVOKABLE QCoro::Task<void> updateUsers();
Q_INVOKABLE QCoro::Task<void> selectUser(int index);
Q_INVOKABLE QCoro::Task<void> listPackagesForUser();

Q_INVOKABLE QString selectedUserName() const
{
Expand All @@ -118,7 +124,7 @@ class DeviceManager : public QObject

Q_INVOKABLE int selectedUsersInstalledApps() const
{
return 0;
return selected_user_ ? selected_user_->installedApps : -1;
}

Q_INVOKABLE QString runningUserName() const
Expand Down Expand Up @@ -301,12 +307,14 @@ class DeviceManager : public QObject
void oculusRuntimeVersionChanged(QString oculus_runtime_version);
void androidVersionChanged(int android_version);
void androidSdkVersionChanged(int android_sdk_version);
void userAppsListChanged();
void usersListChanged();
void userInfoChanged();

private:
QStringList devices_list_;
GameInfoModel app_list_model_;
GameInfoModel user_apps_list_model_;
QTimer auto_update_timer_;
QString connected_device_;
QString device_name_;
Expand Down
3 changes: 2 additions & 1 deletion src/models/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ class User
{
public:
User(int id, const QString &name, bool running)
: name(name), id(id), running(running) {}
: name(name), id(id), running(running), installedApps(-1) {}

public:
QString name;
int id;
bool running;
int installedApps;
};

0 comments on commit 0de2a09

Please sign in to comment.