use of com.sun.jna.CallbackThreadInitializer in project dukescript-presenters by dukescript.
the class Cocoa method show.
@Override
public void show(URI page) {
this.page = page.toASCIIString();
Native.loadLibrary("WebKit", WebKit.class);
appDidStart = new AppDidStart();
contextCreated = new ContextCreated();
ready = new Ready();
if (appDelPtr == null) {
ObjC objC = ObjC.INSTANCE;
Pointer appDelClass = objC.objc_allocateClassPair(objC.objc_getClass("NSObject"), "AppDelegate", 0);
objC.class_addMethod(appDelClass, objC.sel_getUid("applicationDidFinishLaunching:"), appDidStart, "i@:@");
doMainSelector = objC.sel_getUid("doMain");
Native.setCallbackThreadInitializer(this, new CallbackThreadInitializer(false, false, "Cocoa Dispatch Thread"));
objC.class_addMethod(appDelClass, doMainSelector, this, "i@");
objC.class_addMethod(appDelClass, objC.sel_getUid("webView:didCreateJavaScriptContext:forFrame:"), contextCreated, "v@:@:@");
objC.class_addMethod(appDelClass, objC.sel_getUid("webView:didFinishLoadForFrame:"), ready, "v@:@");
objC.objc_registerClassPair(appDelClass);
long appDelObj = send(objC.objc_getClass("AppDelegate"), "alloc");
appDelPtr = new Pointer(appDelObj);
send(appDelPtr, "init");
send(appDelPtr, "performSelectorOnMainThread:withObject:waitUntilDone:", doMainSelector, null, 1);
} else {
execute(new Runnable() {
@Override
public void run() {
appDidStart.callback(appDelPtr);
}
});
}
}
Aggregations