Skip to content

Commit

Permalink
Fix loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kuglee committed May 28, 2017
1 parent c354b14 commit 3529b46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
9 changes: 2 additions & 7 deletions BatteryExtra/loader.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,8 @@ + (void)load {
else
NSLog(@"%@: Could not swizzle SystemUIServer!", bundleName);

if (didSwizzle && !didSwizzleMenuItem) {
if ([BatterySUISStartupObject reloadMenuExtra] == 0) {
NSLog(@"%@: MenuExtra was reloaded successfully!", bundleName);
[BatterySUISStartupObject
swizzleMenuExtra:[menuExtraMainBundle principalClass]];
}
}
if (didSwizzle && [BatterySUISStartupObject reloadMenuExtra] == 0)
NSLog(@"%@: SystemUIServer was reloaded successfully!", bundleName);
}

- (id)loadMenuExtra:(id)arg1 withData:(id)arg2 atPosition:(long long)arg3 {
Expand Down
39 changes: 21 additions & 18 deletions Reloader/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,39 @@ int CoreMenuExtraAddMenuExtra(CFURLRef path, int position, int arg2, int arg3,
int main(int argc, const char *argv[]) {
@autoreleasepool {

NSBundle *bundle = [NSBundle
bundleWithPath:@"/System/Library/CoreServices/SystemUIServer.app"];
NSArray *extras =
[NSArray arrayWithContentsOfFile:[bundle pathForResource:@"Extras.plist"
ofType:nil]];

NSString *ID = @"";
for (NSDictionary *extra in extras) {
if ([extra[@"path"]
isEqualToString:[NSString stringWithUTF8String:argv[1]]]) {
ID = extra[@"id"];
}
}

NSURL *menu =
[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];

void *menuExtra = NULL;
if ((CoreMenuExtraGetMenuExtra(
(__bridge CFStringRef)[NSString stringWithUTF8String:argv[2]],
&menuExtra) == 0) &&
menuExtra) {

CoreMenuExtraRemoveMenuExtra(menuExtra, 0);

// Can't reload menuExtra nicely (rdar://32445578)
system("killall -KILL SystemUIServer");

NSBundle *bundle = [NSBundle
bundleWithPath:@"/System/Library/CoreServices/SystemUIServer.app"];
NSArray *extras = [NSArray
arrayWithContentsOfFile:[bundle pathForResource:@"Extras.plist"
ofType:nil]];

NSString *ID = @"";
for (NSDictionary *extra in extras) {
if ([extra[@"path"]
isEqualToString:[NSString stringWithUTF8String:argv[1]]]) {
ID = extra[@"id"];
}
}

NSURL *menu =
[NSURL fileURLWithPath:[NSString stringWithUTF8String:argv[1]]];

CoreMenuExtraAddMenuExtra((__bridge CFURLRef)menu, [ID intValue], 0, 0, 0,
0);

return 0;
}

}

return 1;
Expand Down

0 comments on commit 3529b46

Please sign in to comment.