working jni lib :)
This commit is contained in:
2
build.sh
2
build.sh
@ -49,7 +49,7 @@ jar -cf launcher.jar net
|
||||
cd ..
|
||||
|
||||
echo "compiling native lib"
|
||||
cc -mmacosx-version-min=10.9 -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/darwin" -Ic -o build/libMacLauncher.jnilib -shared c/net_i2p_router_MacLauncher.c
|
||||
cc -v -Wl,-lobjc -mmacosx-version-min=10.9 -I"$JAVA_HOME/include" -I"$JAVA_HOME/include/darwin" -Ic -o build/libMacLauncher.jnilib -shared c/net_i2p_router_MacLauncher.c
|
||||
|
||||
echo "signing jbigi libs"
|
||||
mkdir jbigi
|
||||
|
@ -1,8 +1,57 @@
|
||||
#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1050
|
||||
# include <objc/runtime.h>
|
||||
# include <objc/message.h>
|
||||
#else
|
||||
# include <objc/objc-runtime.h>
|
||||
#endif
|
||||
|
||||
#include "net_i2p_router_MacLauncher.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// function aliases for the objc_msgSend prototype
|
||||
// see https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.html
|
||||
// and https://indiestack.com/2019/10/casting-objective-c-message-sends/
|
||||
|
||||
id (*IdFromIdAndSelector)(id, SEL) = (id (*)(id, SEL)) objc_msgSend;
|
||||
id (*IdFromClassAndSel)(Class, SEL) = (id (*)(Class, SEL)) objc_msgSend;
|
||||
id (*IdFromSelIdChar)(id, SEL, char*) = (id (*)(id, SEL, char*)) objc_msgSend;
|
||||
id (*IdFromIdSelLongId)(id, SEL, long, id) = (id (*)(id, SEL, long, id)) objc_msgSend;
|
||||
|
||||
static int osx_latencycritical_count = 0;
|
||||
static id osx_latencycritical_activity = nil;
|
||||
|
||||
JNIEXPORT void JNICALL Java_net_i2p_router_MacLauncher_disableAppNap
|
||||
(JNIEnv *jnienv, jclass c)
|
||||
{
|
||||
printf("worked!\n");
|
||||
Class pic; /* Process info class */
|
||||
SEL pisl; /* Process info selector */
|
||||
SEL bawo; /* Begin Activity With Options selector */
|
||||
id pi; /* Process info */
|
||||
id str; /* Reason string */
|
||||
|
||||
if (osx_latencycritical_count++ != 0)
|
||||
return;
|
||||
|
||||
/* Avoid triggering an exception when run on older OS X */
|
||||
if ((pic = (Class)objc_getClass("NSProcessInfo")) == nil)
|
||||
return;
|
||||
|
||||
if (class_getClassMethod(pic, (pisl = sel_getUid("processInfo"))) == NULL)
|
||||
return;
|
||||
|
||||
if (class_getInstanceMethod(pic,
|
||||
(bawo = sel_getUid("beginActivityWithOptions:reason:"))) == NULL)
|
||||
return;
|
||||
|
||||
/* Get the process instance */
|
||||
if ((pi = IdFromIdAndSelector((id)pic, pisl)) == nil)
|
||||
return;
|
||||
|
||||
/* Create a reason string */
|
||||
str = IdFromClassAndSel(objc_getClass("NSString"), sel_getUid("alloc"));
|
||||
str = IdFromSelIdChar(str, sel_getUid("initWithUTF8String:"), "Timing Critical");
|
||||
|
||||
/* Start activity that tells App Nap to mind its own business: */
|
||||
/* NSActivityUserInitiatedAllowingIdleSystemSleep */
|
||||
/* | NSActivityLatencyCritical */
|
||||
osx_latencycritical_activity = IdFromIdSelLongId(pi, bawo, 0x00FFFFFFULL | 0xFF00000000ULL, str);
|
||||
}
|
||||
|
Reference in New Issue
Block a user