From ac1d82e1fff9039a5dabe1404d6f03faaad28ef5 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 2 Dec 2016 16:39:21 -0500 Subject: DaemonLauncher: Add `isRunning` method Says whether or not the daemon app is currently running. --- Low Battery Yup/DaemonLauncher.h | 1 + Low Battery Yup/DaemonLauncher.m | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/Low Battery Yup/DaemonLauncher.h b/Low Battery Yup/DaemonLauncher.h index a7c6ceb..586dbda 100644 --- a/Low Battery Yup/DaemonLauncher.h +++ b/Low Battery Yup/DaemonLauncher.h @@ -12,5 +12,6 @@ - (BOOL)launch; - (BOOL)quit; +- (BOOL)isRunning; @end diff --git a/Low Battery Yup/DaemonLauncher.m b/Low Battery Yup/DaemonLauncher.m index 78b7844..355e9fd 100644 --- a/Low Battery Yup/DaemonLauncher.m +++ b/Low Battery Yup/DaemonLauncher.m @@ -42,4 +42,18 @@ return NO; } +- (BOOL)isRunning +{ + NSArray *runningApplications = [[NSWorkspace sharedWorkspace] runningApplications]; + + for (int i = 0; i < [runningApplications count]; i++) { + if ([[[runningApplications objectAtIndex:i] bundleIdentifier] + isEqualToString:@"com.teddywing.Low-Battery-Yup-d"]) { + return YES; + } + } + + return NO; +} + @end -- cgit v1.2.3