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 @@
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