Skip to content

Commit

Permalink
Add and Remove Game from user
Browse files Browse the repository at this point in the history
  • Loading branch information
victorwads committed Jun 22, 2024
1 parent a1cb1c6 commit 0eeaa56
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 16 deletions.
2 changes: 1 addition & 1 deletion content/Tabs/Devices/ApplicationDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Kirigami.Card {
footer: Button {
id: action_button
icon.name: "uninstall"
text: qsTr("Uninstall")
text: qsTr("Uninstall to All Users")
onClicked: {
uninstallButtonClicked();
}
Expand Down
28 changes: 14 additions & 14 deletions content/Tabs/Users/Users.qml
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ RowLayout {
property int index: -1

anchors.centerIn: parent
title: "Uninstall " + packageName
title: "Remove " + packageName + " from user" + app.deviceManager.selectedUserName
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
installed_apps.model.remove(index);
app.deviceManager.uninstallApkQml(packageName);
app.deviceManager.uninstallFromUser(packageName)
}
}

Expand All @@ -160,11 +160,11 @@ RowLayout {
else
return "file://" + path;
}
// onUninstallButtonClicked: {
// confirm_dialog.packageName = model.package_name;
// confirm_dialog.index = index;
// confirm_dialog.open();
// }
onRemoveButtonClicked: {
remove_confirm_dialog.packageName = model.package_name;
remove_confirm_dialog.index = index;
remove_confirm_dialog.open();
}
}
}
GridView {
Expand All @@ -185,11 +185,11 @@ RowLayout {
property int index: -1

anchors.centerIn: parent
title: "Uninstall " + packageName
title: "Add " + packageName + " to user" + app.deviceManager.selectedUserName
standardButtons: Dialog.Ok | Dialog.Cancel
onAccepted: {
avaliable_apps.model.remove(index);
app.deviceManager.uninstallApkQml(packageName);
app.deviceManager.installToUser(packageName);
}
}

Expand All @@ -208,11 +208,11 @@ RowLayout {
else
return "file://" + path;
}
// onUninstallButtonClicked: {
// confirm_dialog.packageName = model.package_name;
// confirm_dialog.index = index;
// confirm_dialog.open();
// }
onAddButtonClicked: {
confirm_dialog.packageName = model.package_name;
confirm_dialog.index = index;
confirm_dialog.open();
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion content/Tabs/Users/UsersInstalledDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Kirigami.Card {
id: action_button
icon.name: "delete"
text: qsTr("Remove from user")
enabled: false
onClicked: {
removeButtonClicked();
}
Expand Down
48 changes: 48 additions & 0 deletions src/device_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,4 +1002,52 @@ QCoro::Task<void> DeviceManager::updateAvailableAppsList() {
}
}
co_return;
}

QCoro::Task<bool> DeviceManager::uninstallFromUser(const QString package_name)
{
if (!hasConnectedDevice()) {
co_return false;
}

auto serial = connectedDevice();
QString id = QString::number(selected_user_->id);

QProcess basic_process;
auto adb = qCoro(basic_process);
adb.start(resolvePrefix(ADB_PATH), {"-s", serial, "shell", "pm", "uninstall", "--user", id, package_name});
co_await adb.waitForFinished(-1);

if (basic_process.exitStatus() != QProcess::NormalExit || basic_process.exitCode() != 0) {
qWarning() << "Failed to uninstall" << package_name << "for user" << selected_user_->name << "on device" << serial;
qWarning() << basic_process.readAllStandardError();
co_return false;
}

listPackagesForUser();
co_return true;
}

QCoro::Task<bool> DeviceManager::installToUser(const QString package_name)
{
if (!hasConnectedDevice()) {
co_return false;
}

auto serial = connectedDevice();
QString id = QString::number(selected_user_->id);

QProcess basic_process;
auto adb = qCoro(basic_process);
adb.start(resolvePrefix(ADB_PATH), {"-s", serial, "shell", "pm", "install-existing", "--user", id, package_name});
co_await adb.waitForFinished(-1);

if (basic_process.exitStatus() != QProcess::NormalExit || basic_process.exitCode() != 0) {
qWarning() << "Failed to install" << package_name << "for user" << selected_user_->name << "on device" << serial;
qWarning() << basic_process.readAllStandardError();
co_return false;
}

listPackagesForUser();
co_return true;
}
12 changes: 12 additions & 0 deletions src/device_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class DeviceManager : public QObject
return uninstallApk(package_name, true);
};

Q_INVOKABLE QCoro::QmlTask uninstallFromSelectedUser(const QString package_name)
{
return uninstallFromUser(package_name);
};

Q_INVOKABLE QCoro::QmlTask installToSelectedUser(const QString package_name)
{
return installToUser(package_name);
};

Q_INVOKABLE QVariantList devicesList() const
{
QVariantList list;
Expand Down Expand Up @@ -113,6 +123,8 @@ class DeviceManager : public QObject
Q_INVOKABLE QCoro::Task<void> selectUser(int index);
Q_INVOKABLE QCoro::Task<void> listPackagesForUser();
Q_INVOKABLE QCoro::Task<void> updateAvailableAppsList();
Q_INVOKABLE QCoro::Task<bool> uninstallFromUser(const QString package_name);
Q_INVOKABLE QCoro::Task<bool> installToUser(const QString package_name);

Q_INVOKABLE QString selectedUserName() const
{
Expand Down

0 comments on commit 0eeaa56

Please sign in to comment.