fix: fix loader config

This commit is contained in:
Adrian Castro 2024-11-15 15:29:51 +01:00 • committed by Cristiandis
parent e5fdfbf00c
commit 3d86fe0f75
4 changed files with 50 additions and 2 deletions

@ -0,0 +1 @@
Subproject commit a7b21ac17fb52c2b795e445da762008f88a44d35

View file

@ -5,4 +5,6 @@
@property (nonatomic, strong) NSURL *customLoadUrl;
+ (instancetype)defaultConfig;
+ (instancetype)getLoaderConfig;
- (instancetype)init;
- (BOOL)loadConfig;
@end

View file

@ -4,6 +4,50 @@
@implementation LoaderConfig
- (instancetype)init {
self = [super init];
if (self) {
self.customLoadUrlEnabled = NO;
self.customLoadUrl = [NSURL URLWithString:@"http://localhost:4040/bunny.js"];
}
return self;
}
- (BOOL)loadConfig {
NSURL *loaderConfigUrl = [getPyoncordDirectory() URLByAppendingPathComponent:@"loader.json"];
BunnyLog(@"Attempting to load config from: %@", loaderConfigUrl.path);
if ([[NSFileManager defaultManager] fileExistsAtPath:loaderConfigUrl.path]) {
NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:loaderConfigUrl];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if (error) {
BunnyLog(@"Error parsing loader config: %@", error);
return NO;
}
if (json) {
NSDictionary *customLoadUrl = json[@"customLoadUrl"];
if (customLoadUrl) {
self.customLoadUrlEnabled = [customLoadUrl[@"enabled"] boolValue];
NSString *urlString = customLoadUrl[@"url"];
if (urlString) {
self.customLoadUrl = [NSURL URLWithString:urlString];
}
}
BunnyLog(@"Loader config loaded - Custom URL %@: %@",
self.customLoadUrlEnabled ? @"enabled" : @"disabled",
self.customLoadUrl.absoluteString);
return YES;
}
}
BunnyLog(@"Using default loader config: %@", self.customLoadUrl.absoluteString);
return NO;
}
+ (instancetype)defaultConfig {
LoaderConfig *config = [[LoaderConfig alloc] init];
config.customLoadUrlEnabled = NO;

View file

@ -162,9 +162,10 @@ static LoaderConfig *loaderConfig;
RevengeLog(@"Bundle contents: %@", bundleContents);
}
pyoncordDirectory = getPyoncordDirectory();
pyoncordDirectory = getPyoncordDirectory();
loaderConfig = [[LoaderConfig alloc] init];
[loaderConfig loadConfig];
%init;
}
}