Skip to content

Commit

Permalink
Merge pull request #22 from castdrian/fix-loader-config
Browse files Browse the repository at this point in the history
fix: loader config oversight
  • Loading branch information
pylixonly authored Nov 15, 2024
2 parents 2f8999c + 2fd7b27 commit 9b645f8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Headers/LoaderConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
@property (nonatomic, strong) NSURL *customLoadUrl;
+ (instancetype)defaultConfig;
+ (instancetype)getLoaderConfig;
- (instancetype)init;
- (BOOL)loadConfig;
@end
44 changes: 44 additions & 0 deletions Sources/LoaderConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Sources/Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ static LoaderConfig *loaderConfig;
BunnyLog(@"Bundle contents: %@", bundleContents);
}

pyoncordDirectory = getPyoncordDirectory();
pyoncordDirectory = getPyoncordDirectory();
loaderConfig = [[LoaderConfig alloc] init];
[loaderConfig loadConfig];

%init;
}
Expand Down

0 comments on commit 9b645f8

Please sign in to comment.