Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions KeepingYouAwake/KYAAppController/KYAAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,27 @@ - (void)showSettingsWindow:(id)sender
[settingsWindow makeKeyAndOrderFront:sender];
}

#pragma mark - Menu Actions

- (void)toggleAllowDisplaySleep:(id)sender
{
Auto defaults = NSUserDefaults.standardUserDefaults;
BOOL currentValue = [defaults kya_shouldAllowDisplaySleep];
[defaults setKya_allowDisplaySleep:!currentValue];
[defaults synchronize];
}

- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
{
if(menuItem.action == @selector(toggleAllowDisplaySleep:))
{
Auto defaults = NSUserDefaults.standardUserDefaults;
BOOL allowDisplaySleep = [defaults kya_shouldAllowDisplaySleep];
menuItem.state = allowDisplaySleep ? NSControlStateValueOn : NSControlStateValueOff;
return YES;
}

return YES;
}

@end
10 changes: 9 additions & 1 deletion KeepingYouAwake/KYAMainMenu/KYAMainMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
}
activateForDuration.submenu = activationDurationsSubMenu;
[mainMenu addItem:activateForDuration];


[mainMenu addItem:NSMenuItem.separatorItem];

Auto allowDisplaySleep = [[NSMenuItem alloc] initWithTitle:KYA_L10N_ALLOW_DISPLAY_SLEEP
action:@selector(toggleAllowDisplaySleep:)
keyEquivalent:@""];
allowDisplaySleep.target = NSApplication.sharedApplication.delegate;
[mainMenu addItem:allowDisplaySleep];

[mainMenu addItem:NSMenuItem.separatorItem];

Auto settings = [[NSMenuItem alloc] initWithTitle:KYA_L10N_SETTINGS_ELLIPSIS
Expand Down