From 3f3b33fac4a299fda282d9f049ea05a23ac20d08 Mon Sep 17 00:00:00 2001 From: uncor3 Date: Fri, 20 Mar 2026 03:08:47 +0000 Subject: [PATCH] refactor: improve loading state management and fix bugs in InstalledAppsWidget --- src/installedappswidget.cpp | 42 ++++++++++++++++++------------------- src/installedappswidget.h | 3 ++- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/installedappswidget.cpp b/src/installedappswidget.cpp index 3ea8ef1..e56d4a8 100644 --- a/src/installedappswidget.cpp +++ b/src/installedappswidget.cpp @@ -144,7 +144,6 @@ void AppTabWidget::updateStyles() } // prevent infinite loop if (style != styleSheet()) { - qDebug() << "Style" << style; setStyleSheet(style); } } @@ -564,7 +563,6 @@ void InstalledAppsWidget::selectAppTab(AppTabWidget *tab) QString bundleId = tab->getBundleId(); // Load app container data - // FIXME: handle quickly repeated selections loadAppContainer(bundleId); } @@ -596,10 +594,12 @@ void InstalledAppsWidget::filterApps(const QString &searchText) */ void InstalledAppsWidget::loadAppContainer(const QString &bundleId) { - if (!m_device) { + if (!m_device || m_loadingContainer) { return; } + m_loadingContainer = true; + disableTabs(true); // Clean up previous house arrest clients before creating new ones cleanupHouseArrestClients(); @@ -654,19 +654,20 @@ void InstalledAppsWidget::loadAppContainer(const QString &bundleId) << QString::fromUtf8(err->message); result["error"] = QString("Error vending documents: %1") .arg(QString::fromUtf8(err->message)); - // FIXME:Crashes here, needs investigation - // can houseArrestClient be nullptr here? - // house_arrest_client_free(houseArrestClient); + // DO NOT call house_arrest_client_free(houseArrestClient) + // here: vend_documents already took ownership and freed it. return result; } char **dirs = nullptr; size_t count = 0; + // vend_documents takes ownership of the house arrest client, so + // we don't free it here + houseArrestClient = nullptr; + result["afcClient"] = QVariant::fromValue(reinterpret_cast(afcClient)); - result["houseArrestClient"] = QVariant::fromValue( - reinterpret_cast(houseArrestClient)); result["success"] = true; } catch (const std::exception &e) { @@ -674,8 +675,6 @@ void InstalledAppsWidget::loadAppContainer(const QString &bundleId) << e.what(); if (afcClient) afc_client_free(afcClient); - if (houseArrestClient) - house_arrest_client_free(houseArrestClient); result["error"] = QString("Exception: %1").arg(e.what()); } @@ -690,8 +689,6 @@ void InstalledAppsWidget::onContainerDataReady() { QVariantMap result = m_containerWatcher->result(); - // todo - // Clear loading state QLayoutItem *item; while ((item = m_containerLayout->takeAt(0)) != nullptr) { if (item->widget()) { @@ -700,6 +697,9 @@ void InstalledAppsWidget::onContainerDataReady() delete item; } + m_loadingContainer = false; + disableTabs(false); + if (!result.value("success", false).toBool()) { qDebug() << "Error loading app container:" << result.value("error").toString(); @@ -713,8 +713,6 @@ void InstalledAppsWidget::onContainerDataReady() // variables m_houseArrestAfcClient = reinterpret_cast( result.value("afcClient").value()); - m_houseArrestClient = reinterpret_cast( - result.value("houseArrestClient").value()); if (!m_houseArrestAfcClient) { QLabel *errorLabel = @@ -740,16 +738,9 @@ void InstalledAppsWidget::onFileSharingFilterChanged(bool enabled) void InstalledAppsWidget::cleanupHouseArrestClients() { if (m_houseArrestAfcClient) { - // FIXME: create an issue afc_client_free crashes - // afc_client_free(m_houseArrestAfcClient); + afc_client_free(m_houseArrestAfcClient); m_houseArrestAfcClient = nullptr; } - - if (m_houseArrestClient) { - // FIXME: crash - // house_arrest_client_free(m_houseArrestClient); - m_houseArrestClient = nullptr; - } } void InstalledAppsWidget::createLeftPanel() @@ -824,3 +815,10 @@ void InstalledAppsWidget::createRightPanel() m_splitter->addWidget(rightContentWidget); } + +void InstalledAppsWidget::disableTabs(bool disable) +{ + for (AppTabWidget *tab : m_appTabs) { + tab->setEnabled(!disable); + } +} \ No newline at end of file diff --git a/src/installedappswidget.h b/src/installedappswidget.h index 40d3916..609e34f 100644 --- a/src/installedappswidget.h +++ b/src/installedappswidget.h @@ -118,6 +118,7 @@ private: void filterApps(const QString &searchText); void loadAppContainer(const QString &bundleId); void cleanupHouseArrestClients(); + void disableTabs(bool disable); const iDescriptorDevice *m_device; QHBoxLayout *m_mainLayout; @@ -138,12 +139,12 @@ private: QFutureWatcher *m_watcher; QFutureWatcher *m_containerWatcher; QSplitter *m_splitter; - HouseArrestClientHandle *m_houseArrestClient = nullptr; AfcClientHandle *m_houseArrestAfcClient = nullptr; // App data storage QList m_appTabs; AppTabWidget *m_selectedTab = nullptr; SpringBoardServicesClientHandle *m_springboardClient = nullptr; + bool m_loadingContainer = false; }; #endif // INSTALLEDAPPSWIDGET_H \ No newline at end of file