From 4f40595d6b2eb65aa3b6e3a4d5b93169d93e745c Mon Sep 17 00:00:00 2001 From: uncor3 Date: Sun, 14 Sep 2025 00:47:03 +0000 Subject: [PATCH] WIP: implement instanceRemoveDevice --- src/appcontext.cpp | 30 +++++++++++++++++++++++++++++- src/appcontext.h | 1 + src/core/services/restart.cpp | 16 +++++++++------- src/toolboxwidget.cpp | 17 ++++++++++++++--- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/appcontext.cpp b/src/appcontext.cpp index acc5e98..ffa6ac3 100644 --- a/src/appcontext.cpp +++ b/src/appcontext.cpp @@ -118,6 +118,33 @@ void AppContext::addDevice(QString udid, idevice_connection_type conn_type, // processing device information"); } } +// TODO:WIP +void AppContext::instanceRemoveDevice(QString _udid) +{ + const std::string uuid = _udid.toStdString(); + if (!m_devices.contains(uuid)) { + qDebug() << "Device with UUID " + _udid + + " not found. Please report this issue.", + "Error"; + return; + } + + qDebug() << "Removing device with UUID:" << QString::fromStdString(uuid); + + // cleanDevice(device); + iDescriptorDevice *device = m_devices[uuid]; + m_devices.remove(uuid); + + emit deviceRemoved(uuid); + // TODO: Cleanup now should be done wherever there are initialized + // lockdownd_client_free(device->lockdownClient); + if (device->afcClient) + afc_client_free(device->afcClient); + idevice_free(device->device); + // lockdownd_service_descriptor_free(device->lockdownService); + delete device; + // return true; +} void AppContext::removeDevice(QString _udid) @@ -139,7 +166,8 @@ void AppContext::removeDevice(QString _udid) emit deviceRemoved(uuid); // TODO: Cleanup now should be done wherever there are initialized // lockdownd_client_free(device->lockdownClient); - // afc_client_free(device->afcClient); + if (device->afcClient) + afc_client_free(device->afcClient); idevice_free(device->device); // lockdownd_service_descriptor_free(device->lockdownService); delete device; diff --git a/src/appcontext.h b/src/appcontext.h index 5d52495..8c3499c 100644 --- a/src/appcontext.h +++ b/src/appcontext.h @@ -26,6 +26,7 @@ public: bool noDevicesConnected(); QList getAllRecoveryDevices(); ~AppContext(); + void instanceRemoveDevice(QString _udid); private: QMap m_devices; diff --git a/src/core/services/restart.cpp b/src/core/services/restart.cpp index 994d670..474a731 100644 --- a/src/core/services/restart.cpp +++ b/src/core/services/restart.cpp @@ -27,15 +27,22 @@ // TODO:break all the client because device wont restart if any client is still // connected we need to change the main device init function to not connect to // any client -bool restart(idevice_t device) +bool restart(std::string _udid) { + idevice_t device = NULL; lockdownd_client_t lockdown_client = NULL; diagnostics_relay_client_t diagnostics_client = NULL; lockdownd_error_t ret = LOCKDOWN_E_UNKNOWN_ERROR; lockdownd_service_descriptor_t service = NULL; - const char *udid = NULL; + const char *udid = _udid.c_str(); int use_network = 0; + if (idevice_new_with_options(&device, udid, IDEVICE_LOOKUP_USBMUX) != + IDEVICE_E_SUCCESS) { + printf("ERROR: No device found, is it plugged in?\n"); + return false; + } + if (LOCKDOWN_E_SUCCESS != (ret = lockdownd_client_new_with_handshake( device, &lockdown_client, TOOL_NAME))) { idevice_free(device); @@ -82,10 +89,5 @@ bool restart(idevice_t device) diagnostics_relay_client_free(diagnostics_client); } - if (service) { - lockdownd_service_descriptor_free(service); - service = NULL; - } - return false; } \ No newline at end of file diff --git a/src/toolboxwidget.cpp b/src/toolboxwidget.cpp index 8109a11..9f77d2b 100644 --- a/src/toolboxwidget.cpp +++ b/src/toolboxwidget.cpp @@ -346,9 +346,20 @@ void ToolboxWidget::onToolboxClicked(const QString &toolName) virtualLocation->resize(800, 600); // Optional: default size virtualLocation->show(); } else if (toolName == "Restart") { - if (!(restart(m_currentDevice->device))) + // TODO:WIP + std::string udid = m_currentDevice->udid; + AppContext::sharedInstance()->instanceRemoveDevice( + QString::fromStdString(udid)); + // QMetaObject::invokeMethod(AppContext::sharedInstance(), + // "removeDevice", + // Qt::QueuedConnection, + // Q_ARG(QString, QString(udid.c_str()))); + if (!(restart(udid))) warn("Failed to restart device"); - qDebug() << "Restarting device services..."; + else { + warn("Device services restarted successfully", "Success"); + qDebug() << "Restarting device"; + } } else if (toolName == "Shutdown") { // TODO // if (!(shutdown(m_currentDevice->device))) @@ -371,7 +382,7 @@ void ToolboxWidget::onToolboxClicked(const QString &toolName) } else if (toolName == "Query MobileGestalt") { // Handle querying MobileGestalt QueryMobileGestaltWidget *queryMobileGestaltWidget = - new QueryMobileGestaltWidget(); + new QueryMobileGestaltWidget(m_currentDevice); queryMobileGestaltWidget->show(); } else if (toolName == "Developer Disk Images") { // Handle developer disk images