From af3b2ba5b17853b13ad346007619adb30cd6e97a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesu=CC=81s=20A=2E=20A=CC=81lvarez?= Date: Fri, 25 Sep 2020 00:16:53 +0200 Subject: [PATCH] cache bundle icons manually otherwise they seem to get mixed up on iOS 14 --- Mini vMac/SettingsViewController.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Mini vMac/SettingsViewController.m b/Mini vMac/SettingsViewController.m index b3fd446..cd53447 100644 --- a/Mini vMac/SettingsViewController.m +++ b/Mini vMac/SettingsViewController.m @@ -27,6 +27,7 @@ typedef enum : NSInteger { NSArray *keyboardLayouts; NSArray *emulatorBundles; NSMutableArray *machineList; // NSString (header) or NSBundle (emulator bundle) + NSMutableDictionary *bundleIcons; NSMutableSet *groupedEmulatorBundles; NSBundle *selectedEmulatorBundle; NSString *aboutTitle; @@ -48,6 +49,7 @@ typedef enum : NSInteger { - (void)loadEmulatorBundles { emulatorBundles = [AppDelegate sharedInstance].emulatorBundles; + bundleIcons = [NSMutableDictionary dictionaryWithCapacity:emulatorBundles.count]; NSMutableDictionary*> *bundlesByName = [NSMutableDictionary dictionaryWithCapacity:emulatorBundles.count]; NSString *selectedBundleName = [[NSUserDefaults standardUserDefaults] stringForKey:@"machine"]; for (NSBundle *bundle in emulatorBundles) { @@ -270,8 +272,7 @@ typedef enum : NSInteger { cell.imageView.image = nil; cell.indentationLevel = 1; } else { - NSString *iconName = [NSString stringWithFormat:@"%@/Icon", bundle.bundlePath]; - cell.imageView.image = [UIImage imageNamed:iconName]; + cell.imageView.image = [self iconForBundle:bundle]; cell.indentationLevel = 0; } cell.accessoryType = (item == selectedEmulatorBundle) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone; @@ -298,6 +299,19 @@ typedef enum : NSInteger { return cell; } +- (UIImage*)iconForBundle:(NSBundle*)bundle { + UIImage *icon = bundleIcons[bundle.bundlePath]; + if (icon != nil) { + return icon; + } + NSString *iconPath = [NSString stringWithFormat:@"%@/Icon.png", bundle.bundlePath]; + icon = [UIImage imageWithContentsOfFile:iconPath]; + if (icon != nil) { + bundleIcons[bundle.bundlePath] = icon; + } + return icon; +} + - (UITableViewCell*)aboutCellForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"about" forIndexPath:indexPath]; NSDictionary *item = aboutItems[indexPath.row];