Skip to content

Instantly share code, notes, and snippets.

@donato-fiore
Last active April 6, 2025 00:39
Show Gist options
  • Save donato-fiore/fa7a2ac47c25d6c8a17b273322a50ae1 to your computer and use it in GitHub Desktop.
Save donato-fiore/fa7a2ac47c25d6c8a17b273322a50ae1 to your computer and use it in GitHub Desktop.
Allow ControlCenter modules to load when running in a simulator.
#import <Foundation/Foundation.h>
@interface NSObject (Private)
- (id)safeValueForKey:(NSString *)key;
@end
@interface NSArray (BaseBoard)
- (id)bs_mapNoNulls:(id (^)(id))arg1;
- (id)bs_flatten;
- (id)bs_filter:(BOOL (^)(id))arg1;
@end
@interface CCSModuleMetadata : NSObject
+ (id)metadataForBundleAtURL:(id)arg1;
- (id)moduleIdentifier;
- (id)supportedDeviceFamilies;
@end
@interface CCSModuleRepository : NSObject
+ (id)_deviceFamily;
@end
%hook CCSModuleRepository
/*
* This method returns an empty when ran simulator, so this
* is a reimplementation of the original method from a real device.
* NOTE: This only loads the metadata of the modules, most, if not all,
* of the modules have limited functionality when ran on the simulator,
* but at least this is a start.
*/
- (NSArray *)_queue_loadAllModuleMetadata {
dispatch_assert_queue((dispatch_queue_t)[self safeValueForKey:@"_queue"]);
NSArray *dirs = [self safeValueForKey:@"_directoryURLs"];
NSArray *mappedURLS = [dirs bs_mapNoNulls:^id(NSURL *path) {
NSFileManager *fileManager = [NSFileManager defaultManager];
return [fileManager contentsOfDirectoryAtURL:path includingPropertiesForKeys:nil options:1 error:nil];
}];
NSArray *flattenedURLS = [mappedURLS bs_flatten];
NSArray *filteredURLS = [flattenedURLS bs_filter:^BOOL(NSURL *path) {
return [path.pathExtension caseInsensitiveCompare:@"bundle"] == NSOrderedSame;
}];
NSArray *metadataArray = [filteredURLS bs_mapNoNulls:^id(NSString *path) {
CCSModuleMetadata *metadata = [NSClassFromString(@"CCSModuleMetadata") metadataForBundleAtURL:path];
NSLog(@"Found module metadata at URL: %@", path);
NSArray *allowedIdentifiers = [self safeValueForKey:@"_allowedModuleIdentifiers"];
if ([allowedIdentifiers containsObject:[metadata moduleIdentifier]]) {
NSSet *supportedDevices = [metadata supportedDeviceFamilies];
if ([supportedDevices containsObject:[NSClassFromString(@"CCSModuleRepository") _deviceFamily]]) {
return metadata;
}
NSLog(@"Ignoring unsupported module at URL: %@", path);
} else {
NSLog(@"Ignoring disallowed module at URL: %@", path);
}
return metadata;
}];
return metadataArray;
}
%end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment