Skip to content

Commit f32524c

Browse files
committed
Shell improve to handle deleted apps
1 parent 3a4ba9b commit f32524c

4 files changed

Lines changed: 50 additions & 6 deletions

File tree

Applications/Shell/AppLauncherPicker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class AppLauncherPicker : public UIComponent {
2222
auto application_it = applications.find(app_id);
2323
if(application_it == applications.end())
2424
{
25-
MLOGE("Shell", "App ID %X not found in application list", app_id);
25+
// Skip invalid app ID - should have been cleaned up on startup
2626
continue;
2727
}
2828
Application_Info* application_info = application_it->second;
@@ -56,7 +56,7 @@ class AppLauncherPicker : public UIComponent {
5656
auto application_it = applications.find(app_id);
5757
if(application_it == applications.end())
5858
{
59-
MLOGE("Shell", "App ID %X not found in application list", app_id);
59+
// Skip invalid app ID - should have been cleaned up on startup
6060
return false;
6161
}
6262
Application_Info* application = application_it->second;

Applications/Shell/AppLauncherPickerEditMode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AppLauncherPickerEditMode : public UIComponent {
4040
auto application_it = applications.find(app_id);
4141
if(application_it == applications.end())
4242
{
43-
MLOGE("Shell", "App ID %X not found in application list", app_id);
43+
// Skip invalid app ID - should have been cleaned up on startup
4444
continue;
4545
}
4646
Application_Info* application_info = application_it->second;
@@ -89,7 +89,7 @@ class AppLauncherPickerEditMode : public UIComponent {
8989
auto application_it = applications.find(app_id);
9090
if(application_it == applications.end())
9191
{
92-
MLOGE("Shell", "App ID %X not found in application list", app_id);
92+
// Skip invalid app ID - should have been cleaned up on startup
9393
return false;
9494
}
9595
Application_Info* application = application_it->second;
@@ -129,7 +129,7 @@ class AppLauncherPickerEditMode : public UIComponent {
129129
auto application_it = applications.find(app_id);
130130
if(application_it == applications.end())
131131
{
132-
MLOGE("Shell", "App ID %X not found in application list", app_id);
132+
// Skip invalid app ID - should have been cleaned up on startup
133133
return false;
134134
}
135135
Application_Info* application = application_it->second;

Applications/Shell/Shell.cpp

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ void Shell::InitializeFolderSystem() {
157157
}
158158
LoadFolderVector(FOLDER_HIDDEN);
159159
LoadFolderVector(FOLDER_INVISIBLE);
160-
160+
161+
// Clean up any invalid app IDs that no longer exist
162+
CleanupInvalidApps();
163+
161164
// Build a set of all apps that are already in folders
162165
std::unordered_set<uint32_t> apps_in_folders;
163166
for (auto& [folder_id, folder] : folders) {
@@ -343,6 +346,46 @@ void Shell::SaveAllFolderVectors() {
343346
SaveFolderVector(FOLDER_INVISIBLE);
344347
}
345348

349+
void Shell::CleanupInvalidApps() {
350+
bool any_changes = false;
351+
352+
// Clean up all folders including special ones
353+
std::vector<uint8_t> all_folders;
354+
for (uint8_t i = 0; i < FOLDER_COUNT; i++) {
355+
all_folders.push_back(i);
356+
}
357+
all_folders.push_back(FOLDER_HIDDEN);
358+
all_folders.push_back(FOLDER_INVISIBLE);
359+
360+
for (uint8_t folder_id : all_folders) {
361+
std::vector<uint32_t>& app_ids = folders[folder_id].app_ids;
362+
std::vector<uint32_t> valid_apps;
363+
364+
for (uint32_t app_id : app_ids) {
365+
// Check if this app exists in the applications map
366+
auto app_it = applications.find(app_id);
367+
if (app_it != applications.end()) {
368+
// App exists, keep it
369+
valid_apps.push_back(app_id);
370+
} else {
371+
// App doesn't exist anymore, log and remove
372+
MLOGD("Shell", "Removing invalid app ID %X from folder %d", app_id, folder_id);
373+
any_changes = true;
374+
}
375+
}
376+
377+
// Update the folder with only valid apps
378+
if (app_ids.size() != valid_apps.size()) {
379+
app_ids = valid_apps;
380+
SaveFolderVector(folder_id);
381+
}
382+
}
383+
384+
if (any_changes) {
385+
MLOGI("Shell", "Cleaned up invalid app entries");
386+
}
387+
}
388+
346389
uint8_t Shell::GetAppFolder(uint32_t app_id, Application_Info* app_info) {
347390
// Check if app is invisible first
348391
if (!app_info->visibility) {

Applications/Shell/Shell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Shell : public Application {
5151
void SaveFolderVector(uint8_t folder_id);
5252
void LoadFolderVector(uint8_t folder_id);
5353
void SaveAllFolderVectors();
54+
void CleanupInvalidApps();
5455

5556
// Application launcher functions
5657
void ApplicationLauncher();

0 commit comments

Comments
 (0)