Update AppIconOptionsController.m (Experimental)

Experimental
This commit is contained in:
arichornlover 2024-06-03 12:27:34 -05:00 committed by GitHub
parent 021c5f916b
commit 813603b214
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -24,6 +24,8 @@
self.tableView.delegate = self; self.tableView.delegate = self;
[self.view addSubview:self.tableView]; [self.view addSubview:self.tableView];
self.appIcons = @[@"White", @"YTLitePlus", @"Blue", @"Outline", @"2012", @"2013", @"2007", @"Black", @"Oreo", @"uYou", @"2012_Cyan", @"uYouPlus"];
self.backButton = [UIButton buttonWithType:UIButtonTypeCustom]; self.backButton = [UIButton buttonWithType:UIButtonTypeCustom];
NSBundle *backIcon = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"]]; NSBundle *backIcon = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"uYouPlus" ofType:@"bundle"]];
UIImage *backImage = [UIImage imageNamed:@"Back.png" inBundle:backIcon compatibleWithTraitCollection:nil]; UIImage *backImage = [UIImage imageNamed:@"Back.png" inBundle:backIcon compatibleWithTraitCollection:nil];
@ -70,22 +72,18 @@
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
} }
NSString *iconPath = self.appIcons[indexPath.row]; NSString *iconName = self.appIcons[indexPath.row];
cell.textLabel.text = [iconPath.lastPathComponent stringByDeletingPathExtension]; cell.textLabel.text = iconName;
UIImage *iconImage = [UIImage imageWithContentsOfFile:iconPath]; UIImage *iconImage = [UIImage imageNamed:iconName];
cell.imageView.image = iconImage; cell.imageView.image = [self resizeImage:iconImage newSize:CGSizeMake(40, 40)];
cell.imageView.layer.cornerRadius = 10.0;
cell.imageView.clipsToBounds = YES;
cell.imageView.frame = CGRectMake(10, 10, 40, 40);
cell.textLabel.frame = CGRectMake(60, 10, self.view.frame.size.width - 70, 40);
if (indexPath.row == self.selectedIconIndex) { if (indexPath.row == self.selectedIconIndex) {
cell.accessoryType = UITableViewCellAccessoryCheckmark; cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else { } else {
cell.accessoryType = UITableViewCellAccessoryNone; cell.accessoryType = UITableViewCellAccessoryNone;
} }
return cell; return cell;
} }
@ -97,11 +95,6 @@
} }
- (void)resetIcon { - (void)resetIcon {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
[infoDict removeObjectForKey:@"ALTAppIcon"];
[infoDict writeToFile:plistPath atomically:YES];
[[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) { [[UIApplication sharedApplication] setAlternateIconName:nil completionHandler:^(NSError * _Nullable error) {
if (error) { if (error) {
NSLog(@"Error resetting icon: %@", error.localizedDescription); NSLog(@"Error resetting icon: %@", error.localizedDescription);
@ -109,9 +102,7 @@
} else { } else {
NSLog(@"Icon reset successfully"); NSLog(@"Icon reset successfully");
[self showAlertWithTitle:@"Success" message:@"Icon reset successfully"]; [self showAlertWithTitle:@"Success" message:@"Icon reset successfully"];
dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData];
[self.tableView reloadData];
});
} }
}]; }];
} }
@ -121,32 +112,19 @@
NSLog(@"Alternate icons are not supported on this device."); NSLog(@"Alternate icons are not supported on this device.");
return; return;
} }
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *selectedIcon = self.selectedIconIndex >= 0 ? self.appIcons[self.selectedIconIndex] : nil; NSString *iconName = self.appIcons[self.selectedIconIndex];
if (selectedIcon) {
NSString *iconName = [selectedIcon.lastPathComponent stringByDeletingPathExtension]; [[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
if (error) {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
NSMutableDictionary *infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath]; [self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
[infoDict setObject:iconName forKey:@"ALTAppIcon"];
[infoDict writeToFile:plistPath atomically:YES];
[[UIApplication sharedApplication] setAlternateIconName:iconName completionHandler:^(NSError * _Nullable error) {
if (error) {
NSLog(@"Error setting alternate icon: %@", error.localizedDescription);
[self showAlertWithTitle:@"Error" message:@"Failed to set alternate icon"];
} else {
NSLog(@"Alternate icon set successfully");
[self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
}
}];
} else { } else {
NSLog(@"Selected icon path is nil"); NSLog(@"Alternate icon set successfully");
[self showAlertWithTitle:@"Success" message:@"Alternate icon set successfully"];
[self.tableView reloadData];
} }
}); }];
} }
- (UIImage *)resizeImage:(UIImage *)image toSize:(CGSize)size { - (UIImage *)resizeImage:(UIImage *)image toSize:(CGSize)size {