Skip to content

Commit

Permalink
Fix opening the Battery System Preferences on macOS 11 instead of Ene…
Browse files Browse the repository at this point in the history
…rgy Saver in previous versions.
  • Loading branch information
mikepj committed May 24, 2021
1 parent 874c160 commit cf4f7ab
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Graph Views/XRGBatteryView.m
Original file line number Diff line number Diff line change
Expand Up @@ -544,17 +544,31 @@ - (NSMenu *)menuForEvent:(NSEvent *)theEvent {
NSMenu *myMenu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Battery View"];
NSMenuItem *tMI;

tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Energy Saver System Preferences..." action:@selector(openEnergySaverSystemPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];
if (@available(macOS 11, *)) {
tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Battery System Preferences..." action:@selector(openEnergySaverSystemPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];
}
else {
tMI = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Open Energy Saver System Preferences..." action:@selector(openEnergySaverSystemPreferences:) keyEquivalent:@""];
[myMenu addItem:tMI];
}

return myMenu;
}

- (void)openEnergySaverSystemPreferences:(NSEvent *)theEvent {
[NSTask
launchedTaskWithLaunchPath:@"/usr/bin/open"
arguments:@[@"/System/Library/PreferencePanes/EnergySaver.prefPane"]
];
if (@available(macOS 11, *)) {
[NSTask
launchedTaskWithLaunchPath:@"/usr/bin/open"
arguments:@[@"/System/Library/PreferencePanes/Battery.prefPane"]
];
}
else {
[NSTask
launchedTaskWithLaunchPath:@"/usr/bin/open"
arguments:@[@"/System/Library/PreferencePanes/EnergySaver.prefPane"]
];
}
}

- (BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
Expand Down

0 comments on commit cf4f7ab

Please sign in to comment.