commit 78a2552c3d7197d9ae8962abec2102a94567ce3a
parent 59355e5b918b3ae4005351e95bf6522900292373
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 20 Mar 2022 18:04:58 +0100
parent 59355e5b918b3ae4005351e95bf6522900292373
Author: Leah (ctucx) <leah@ctu.cx>
Date: Sun, 20 Mar 2022 18:04:58 +0100
pkgs: add XPCEEventHandler
2 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/pkgs/XPCEventStreamHandler/default.nix b/pkgs/XPCEventStreamHandler/default.nix @@ -0,0 +1,27 @@ +{stdenv, runCommand, ...}: + +let + buildSymlinks = runCommand "macvim-build-symlinks" {} '' + mkdir -p $out/bin + ln -s /usr/bin/gcc $out/bin + ''; + +in stdenv.mkDerivation { + name = "XPCEventStreamHandler"; + src = ./.; + + nativeBuildInputs = [ buildSymlinks ]; + + sandboxProfile = '' + (allow file-read* file-write* process-exec mach-lookup) + ; block homebrew dependencies + (deny file-read* file-write* process-exec mach-lookup (subpath "/usr/local") (with no-log)) + ''; + + buildPhase = "gcc -framework Foundation -o xpc_set_event_stream_handler xpc_set_event_stream_handler.m"; + + installPhase = '' + mkdir -p $out/bin + cp xpc_set_event_stream_handler $out/bin/ + ''; +}
diff --git a/pkgs/XPCEventStreamHandler/xpc_set_event_stream_handler.m b/pkgs/XPCEventStreamHandler/xpc_set_event_stream_handler.m @@ -0,0 +1,25 @@ +// +// main.m +// xpc_set_event_stream_handler +// +// Created by Ford Parsons on 10/23/17. +// Copyright © 2017 Ford Parsons. All rights reserved. +// + +#import <Foundation/Foundation.h> +#include <xpc/xpc.h> + +int main(int argc, const char * argv[]) { + @autoreleasepool { + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + xpc_set_event_stream_handler("com.apple.iokit.matching", NULL, ^(xpc_object_t _Nonnull object) { + const char *event = xpc_dictionary_get_string(object, XPC_EVENT_KEY_NAME); + NSLog(@"%s", event); + dispatch_semaphore_signal(semaphore); + }); + dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); + if(argc >= 2) { + execv(argv[1], (char **)argv+1); + } + } +}