Exec user action via shell
...this supports binaries and scripts
This commit is contained in:
parent
c5ae162dcd
commit
fd2d903328
|
@ -1339,7 +1339,7 @@ bail:
|
||||||
result = NOTIFICATION_SKIPPED;
|
result = NOTIFICATION_SKIPPED;
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
os_log_debug(logHandle, "%{public}@ is allowed to access %d, so no notification will be shown", event.client.path, event.deviceType);
|
os_log_debug(logHandle, "%{public}@ is allowed to access %d, so no notification will not be shown", event.client.path, event.deviceType);
|
||||||
|
|
||||||
//done
|
//done
|
||||||
goto bail;
|
goto bail;
|
||||||
|
@ -1363,7 +1363,7 @@ bail:
|
||||||
-(void)handleEvent:(Event*)event
|
-(void)handleEvent:(Event*)event
|
||||||
{
|
{
|
||||||
//result
|
//result
|
||||||
__block NSUInteger result = NOTIFICATION_ERROR;
|
NSInteger result = NOTIFICATION_ERROR;
|
||||||
|
|
||||||
//should show?
|
//should show?
|
||||||
@synchronized (self) {
|
@synchronized (self) {
|
||||||
|
@ -1372,23 +1372,23 @@ bail:
|
||||||
result = [self shouldShowNotification:event];
|
result = [self shouldShowNotification:event];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//dbg msg
|
||||||
|
os_log_debug(logHandle, "'shouldShowNotification:' method returned %ld", (long)result);
|
||||||
|
|
||||||
//deliver/show user?
|
//deliver/show user?
|
||||||
if(NOTIFICATION_DELIVER == result)
|
if(NOTIFICATION_DELIVER == result)
|
||||||
{
|
{
|
||||||
//deliver
|
//deliver
|
||||||
[self showNotification:event];
|
[self showNotification:event];
|
||||||
|
|
||||||
|
//execute user-specified action?
|
||||||
|
if(YES == [NSUserDefaults.standardUserDefaults boolForKey:PREF_EXECUTE_ACTION])
|
||||||
|
{
|
||||||
|
//exec
|
||||||
|
[self executeUserAction:event];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//should (also) exec user action?
|
|
||||||
if( (NOTIFICATION_ERROR != result) &&
|
|
||||||
(NOTIFICATION_SPURIOUS != result) )
|
|
||||||
{
|
|
||||||
//exec
|
|
||||||
[self executeUserAction:event];
|
|
||||||
}
|
|
||||||
|
|
||||||
bail:
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1469,6 +1469,7 @@ bail:
|
||||||
}
|
}
|
||||||
|
|
||||||
//execute user action
|
//execute user action
|
||||||
|
// via the shell to handle binaries and scripts
|
||||||
-(BOOL)executeUserAction:(Event*)event
|
-(BOOL)executeUserAction:(Event*)event
|
||||||
{
|
{
|
||||||
//flag
|
//flag
|
||||||
|
@ -1478,18 +1479,14 @@ bail:
|
||||||
NSString* action = nil;
|
NSString* action = nil;
|
||||||
|
|
||||||
//args
|
//args
|
||||||
NSMutableArray* args = nil;
|
NSMutableString* args = nil;
|
||||||
|
|
||||||
//execute user-specified action?
|
|
||||||
if(YES != [NSUserDefaults.standardUserDefaults boolForKey:PREF_EXECUTE_ACTION])
|
|
||||||
{
|
|
||||||
//bail
|
|
||||||
goto bail;
|
|
||||||
}
|
|
||||||
|
|
||||||
//dbg msg
|
//dbg msg
|
||||||
os_log_debug(logHandle, "executing user action");
|
os_log_debug(logHandle, "executing user action");
|
||||||
|
|
||||||
|
//alloc
|
||||||
|
args = [NSMutableString string];
|
||||||
|
|
||||||
//grab action
|
//grab action
|
||||||
action = [NSUserDefaults.standardUserDefaults objectForKey:PREF_EXECUTE_PATH];
|
action = [NSUserDefaults.standardUserDefaults objectForKey:PREF_EXECUTE_PATH];
|
||||||
if(YES != [NSFileManager.defaultManager fileExistsAtPath:action])
|
if(YES != [NSFileManager.defaultManager fileExistsAtPath:action])
|
||||||
|
@ -1504,32 +1501,29 @@ bail:
|
||||||
//pass args?
|
//pass args?
|
||||||
if(YES == [NSUserDefaults.standardUserDefaults boolForKey:PREF_EXECUTE_ACTION_ARGS])
|
if(YES == [NSUserDefaults.standardUserDefaults boolForKey:PREF_EXECUTE_ACTION_ARGS])
|
||||||
{
|
{
|
||||||
//alloc
|
|
||||||
args = [NSMutableArray array];
|
|
||||||
|
|
||||||
//add device
|
//add device
|
||||||
[args addObject:@"-device"];
|
[args appendString:@"-device "];
|
||||||
(Device_Camera == event.deviceType) ? [args addObject:@"camera"] : [args addObject:@"microphone"];
|
(Device_Camera == event.deviceType) ? [args appendString:@"camera"] : [args appendString:@"microphone"];
|
||||||
|
|
||||||
//add event
|
//add event
|
||||||
[args addObject:@"-event"];
|
[args appendString:@" -event "];
|
||||||
(NSControlStateValueOn == event.state) ? [args addObject:@"on"] : [args addObject:@"off"];
|
(NSControlStateValueOn == event.state) ? [args appendString:@"on"] : [args appendString:@"off"];
|
||||||
|
|
||||||
//add process
|
//add process
|
||||||
if(nil != event.client)
|
if(nil != event.client)
|
||||||
{
|
{
|
||||||
//add
|
//add
|
||||||
[args addObject:@"-process"];
|
[args appendString:@" -process "];
|
||||||
[args addObject:event.client.pid.stringValue];
|
[args appendString:event.client.pid.stringValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
//add active device count
|
//add active device count
|
||||||
[args addObject:@"-activeCount"];
|
[args appendString:@" -activeCount "];
|
||||||
[args addObject:[NSString stringWithFormat:@"%lu", [self enumerateActiveDevices].count]];
|
[args appendFormat:@"%lu", [self enumerateActiveDevices].count];
|
||||||
}
|
}
|
||||||
|
|
||||||
//exec user specified action
|
//exec user specified action
|
||||||
execTask(action, args, NO, NO);
|
execTask(SHELL, @[@"-c", [NSString stringWithFormat:@"\"%@\" %@", action, args]], NO, NO);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
|
|
||||||
|
|
|
@ -222,6 +222,9 @@
|
||||||
//path to kill all
|
//path to kill all
|
||||||
#define KILL_ALL @"/usr/bin/killall"
|
#define KILL_ALL @"/usr/bin/killall"
|
||||||
|
|
||||||
|
//path to shell
|
||||||
|
#define SHELL @"/bin/bash"
|
||||||
|
|
||||||
//path to facetime
|
//path to facetime
|
||||||
#define FACE_TIME @"/System/Applications/FaceTime.app/Contents/MacOS/FaceTime"
|
#define FACE_TIME @"/System/Applications/FaceTime.app/Contents/MacOS/FaceTime"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue