This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { | |
_jsvmThread = [[NSThread alloc] initWithTarget:self | |
selector:@selector(runJSVMThread) | |
object:nil]; | |
[_jsvmThread start]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)runJSVMThread { | |
[[[ChakraProxy alloc] init] run]; | |
NSRunLoop *runloop = [NSRunLoop currentRunLoop]; | |
while (true) { | |
[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface ChakraProxy : NSObject | |
-(void)run; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JsErrorCode SetupGlobalEnvironment() { | |
JsValueRef globalObject; | |
JsGetGlobalObject(&globalObject); | |
JsValueRef bridgeObject; | |
JsCreateObject(&bridgeObject); | |
ChakraUtils::setObjectProperty(globalObject, 'bridge', bridgeObject); | |
ChakraUtils::setObjectFunctionProperty(bridgeObject, 'render', render); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SetupGlobalEnvironment() { | |
var globalObject = JsGetGlobalObject(); | |
var bridge = { | |
render: render, | |
}; | |
globalObject.bridge = bridge; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)renderElementOfType:(NSString *)name size:(NSSize)size { | |
GGWindow *window = [[GGWindow alloc] init]; | |
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface EBUIManager : NSObject | |
+ (instancetype)sharedInstance; | |
- (void)addValue:(id)value forKey:(NSString *)key; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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