View AppDelegate+applicationDidFinishLaunching.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
_jsvmThread = [[NSThread alloc] initWithTarget:self | |
selector:@selector(runJSVMThread) | |
object:nil]; | |
[_jsvmThread start]; | |
} |
View AppDelegate+runChakraThread.m
- (void)runJSVMThread { | |
[[[ChakraProxy alloc] init] run]; | |
NSRunLoop *runloop = [NSRunLoop currentRunLoop]; | |
while (true) { | |
[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; | |
} | |
} |
View ChakraProxy.h
#import <Foundation/Foundation.h> | |
@interface ChakraProxy : NSObject | |
-(void)run; | |
@end |
View SetupGlobalEnvironment.cpp
JsErrorCode SetupGlobalEnvironment() { | |
JsValueRef globalObject; | |
JsGetGlobalObject(&globalObject); | |
JsValueRef bridgeObject; | |
JsCreateObject(&bridgeObject); | |
ChakraUtils::setObjectProperty(globalObject, 'bridge', bridgeObject); | |
ChakraUtils::setObjectFunctionProperty(bridgeObject, 'render', render); | |
View SetupGlobalEnvironment.js
function SetupGlobalEnvironment() { | |
var globalObject = JsGetGlobalObject(); | |
var bridge = { | |
render: render, | |
}; | |
globalObject.bridge = bridge; | |
return 0; | |
} |
View renderElementOfType.m
- (void)renderElementOfType:(NSString *)name size:(NSSize)size { | |
GGWindow *window = [[GGWindow alloc] init]; | |
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)]; | |
} |
View ChakraProxy+run.m
@implementation ChakraProxy | |
-(void)run { | |
unsigned currentSourceContext = 0; | |
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"main" ofType:@"js"]; | |
NSError *error; | |
NSString *fileContents = [NSString stringWithContentsOfFile:filepath encoding:NSUTF8StringEncoding error:&error]; | |
if (error) { |
View render.cpp
JsValueRef render(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState) { | |
NSString *type = [NSString stringWithUTF8String:ChakraUtils::toString(arguments[1])]; | |
float w {ChakraUtils::toFloat(arguments[2])}; | |
float h {ChakraUtils::toFloat(arguments[3])}; | |
dispatch_async(dispatch_get_main_queue(), ^{ | |
id delegate = [[NSApplication sharedApplication] delegate]; | |
[delegate renderElementOfType:type size:NSMakeSize((CGFloat)w, (CGFloat)h)]; | |
}); |
View EBUIManager.h
#import <Foundation/Foundation.h> | |
@interface EBUIManager : NSObject | |
+ (instancetype)sharedInstance; | |
- (void)addValue:(id)value forKey:(NSString *)key; | |
@end |
View renderElementOfType2.m
- (void)renderElementOfType:(NSString *)name size:(NSSize)size { | |
EBWindow *window = [[EBWindow alloc] init]; | |
EBUIManager *manager = [EBUIManager sharedInstance]; | |
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)]; | |
NSString *uuid = [[NSUUID UUID] UUIDString]; | |
[manager addValue:window forKey:uuid]; | |
} |
OlderNewer