From 0c796e9e499db506c142b6b0e3ae6ef8b20d9ec8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Dec 2016 17:02:10 -0500 Subject: Add a button to launch & quit the daemon Add a new button to the UI that either launches or quits the daemon depending on whether it's currently running. The button is set as a "Toggle" type that will cycle between "Launch Application" and "Quit Application" labels when clicked. Depending on the button's state (0 or 1), it will either launch or quit the daemon. The button's initial state is set on the UI application's launch to determine how it should read & what it should do. --- Low Battery Yup/AppDelegate.h | 2 + Low Battery Yup/AppDelegate.m | 11 +++- Low Battery Yup/en.lproj/MainMenu.xib | 99 +++++++++++++++++++++++++++++------ 3 files changed, 94 insertions(+), 18 deletions(-) diff --git a/Low Battery Yup/AppDelegate.h b/Low Battery Yup/AppDelegate.h index b120b65..0504102 100644 --- a/Low Battery Yup/AppDelegate.h +++ b/Low Battery Yup/AppDelegate.h @@ -16,6 +16,7 @@ IBOutlet NSWindow *window; IBOutlet ShortcutView *_shortcut_view; IBOutlet NSButton *_start_at_login; + IBOutlet NSButton *_launch_app; LaunchAgentManager *_launchagent; DaemonLauncher *_daemon_launcher; @@ -23,5 +24,6 @@ - (void)initializeShortcutView; - (IBAction)performStartAtLogin:(id)sender; +- (IBAction)launchOrQuitDaemon:(id)sender; @end diff --git a/Low Battery Yup/AppDelegate.m b/Low Battery Yup/AppDelegate.m index 9cbfade..69081ca 100644 --- a/Low Battery Yup/AppDelegate.m +++ b/Low Battery Yup/AppDelegate.m @@ -32,6 +32,7 @@ { [self initializeShortcutView]; [self performStartAtLogin:self]; + [_launch_app setState:[_daemon_launcher isRunning]]; } - (void)initializeShortcutView @@ -50,10 +51,18 @@ { if ([_start_at_login state] == NSOnState) { [_launchagent install]; - [_daemon_launcher launch]; } else { [_launchagent uninstall]; + } +} + +- (IBAction)launchOrQuitDaemon:(id)sender +{ + if ([_launch_app state]) { + [_daemon_launcher launch]; + } + else { [_daemon_launcher quit]; } } diff --git a/Low Battery Yup/en.lproj/MainMenu.xib b/Low Battery Yup/en.lproj/MainMenu.xib index 54cde7c..f8f0d64 100644 --- a/Low Battery Yup/en.lproj/MainMenu.xib +++ b/Low Battery Yup/en.lproj/MainMenu.xib @@ -1311,7 +1311,7 @@ 268 - {{84, 83}, {313, 19}} + {{84, 100}, {313, 19}} @@ -1324,14 +1324,14 @@ {{82, 32}, {104, 18}} - + _NS:9 YES -2080374784 268435456 Start at login - + LucidaGrande 13 1044 @@ -1354,6 +1354,31 @@ NO + + + 268 + {{242, 24}, {161, 32}} + + + + _NS:9 + YES + + 67108864 + 134217728 + Launch Application + + _NS:9 + + -930988032 + 129 + Quit Application + + 200 + 25 + + NO + {480, 185} @@ -1371,7 +1396,7 @@ NSFontManager - + YES @@ -2081,14 +2106,30 @@ 545 + + + launchOrQuitDaemon: + + + + 555 + + + + _launch_app + + + + 556 + value: values.StartAtLogin - + - + value: values.StartAtLogin value values.StartAtLogin @@ -2622,8 +2663,9 @@ 372 - + + @@ -3120,9 +3162,22 @@ 546 - + + + 553 + + + + + + + + 554 + + + @@ -3272,6 +3327,8 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3291,25 +3348,29 @@ - 552 + 559 AppDelegate NSObject - - performStartAtLogin: - id - - - performStartAtLogin: - + + id + id + + + + launchOrQuitDaemon: + id + + performStartAtLogin: id - + + NSButton ShortcutView NSButton MASShortcutView @@ -3317,6 +3378,10 @@ NSWindow + + _launch_app + NSButton + _shortcut_view ShortcutView -- cgit v1.2.3