aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkoekeishiya <aasvi93@hotmail.com>2020-05-02 23:42:37 +0200
committerkoekeishiya <aasvi93@hotmail.com>2020-05-02 23:43:39 +0200
commit1fbce35a78563f915f3699724623295020f66167 (patch)
tree54a875804bfa4992a03a7bafdc8189e33d9597a6
parent5f4761acaae0443f293b3f95c4bd3bda171ec3fb (diff)
downloadskhd-1fbce35a78563f915f3699724623295020f66167.tar.gz
skhd-1fbce35a78563f915f3699724623295020f66167.zip
send notification from C
-rw-r--r--src/notify.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/notify.c b/src/notify.c
new file mode 100644
index 0000000..a276854
--- /dev/null
+++ b/src/notify.c
@@ -0,0 +1,23 @@
+void notify_init(void)
+{
+ class_replaceMethod(objc_getClass("NSBundle"),
+ sel_registerName("bundleIdentifier"),
+ method_getImplementation((void *)^{return CFSTR("com.koekeishiya.skhd");}),
+ NULL);
+}
+
+void notify(char *title, char *message)
+{
+ CFStringRef title_ref = CFStringCreateWithCString(NULL, title, kCFStringEncodingUTF8);
+ CFStringRef message_ref = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8);
+
+ void *center = objc_msgSend((void *) objc_getClass("NSUserNotificationCenter"), sel_registerName("defaultUserNotificationCenter"));
+ void *notification = objc_msgSend((void *) objc_getClass("NSUserNotification"), sel_registerName("alloc"), sel_registerName("init"));
+
+ objc_msgSend(notification, sel_registerName("setTitle:"), title_ref);
+ objc_msgSend(notification, sel_registerName("setInformativeText:"), message_ref);
+ objc_msgSend(center, sel_registerName("deliverNotification:"), notification);
+
+ CFRelease(message_ref);
+ CFRelease(title_ref);
+}