Skip to content

Instantly share code, notes, and snippets.

View Kureev's full-sized avatar
:octocat:
Taking a break from OSS

Alexey Kureev Kureev

:octocat:
Taking a break from OSS
View GitHub Profile
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
_jsvmThread = [[NSThread alloc] initWithTarget:self
selector:@selector(runJSVMThread)
object:nil];
[_jsvmThread start];
}
- (void)runJSVMThread {
[[[ChakraProxy alloc] init] run];
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
while (true) {
[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}
}
@Kureev
Kureev / ChakraProxy.h
Last active September 28, 2016 14:13
ChakraProxy
#import <Foundation/Foundation.h>
@interface ChakraProxy : NSObject
-(void)run;
@end
@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) {
JsErrorCode SetupGlobalEnvironment() {
JsValueRef globalObject;
JsGetGlobalObject(&globalObject);
JsValueRef bridgeObject;
JsCreateObject(&bridgeObject);
ChakraUtils::setObjectProperty(globalObject, 'bridge', bridgeObject);
ChakraUtils::setObjectFunctionProperty(bridgeObject, 'render', render);
function SetupGlobalEnvironment() {
var globalObject = JsGetGlobalObject();
var bridge = {
render: render,
};
globalObject.bridge = bridge;
return 0;
}
@Kureev
Kureev / render.cpp
Last active October 19, 2016 18:57
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)];
});
- (void)renderElementOfType:(NSString *)name size:(NSSize)size {
GGWindow *window = [[GGWindow alloc] init];
[window openWithSize:NSMakeSize((CGFloat)size.width, (CGFloat)size.height)];
}
#import <Foundation/Foundation.h>
@interface EBUIManager : NSObject
+ (instancetype)sharedInstance;
- (void)addValue:(id)value forKey:(NSString *)key;
@end
- (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];
}