Skip to content

Instantly share code, notes, and snippets.

@sherbondy
Last active January 6, 2024 07:22
Show Gist options
  • Save sherbondy/f196dedb71e14b5d11d2 to your computer and use it in GitHub Desktop.
Save sherbondy/f196dedb71e14b5d11d2 to your computer and use it in GitHub Desktop.
Ambly Apple TV
Pod::Spec.new do |s|
s.name = 'Ambly'
s.version = '0.6.1'
s.license = { :type => 'Eclipse Public License 1.0', :file => 'LICENSE' }
s.summary = 'ClojureScript REPL into embedded JavaScriptCore'
s.homepage = 'https://github.com/omcljs/ambly'
s.author = 'omcljs'
s.source = { :git => 'https://github.com/omcljs/ambly.git', :tag => '0.6.0' }
s.source_files = 'ObjectiveC/src/*.{h,m}'
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.0'
s.osx.deployment_target = '10.10'
s.requires_arc = true
s.dependency "GCDWebServer/WebDAV", ">=3.2.7"
end
#import "AppDelegate.h"
#import "EJJavaScriptView.h"
#import "ABYContextManager.h"
#import "ABYServer.h"
@interface AppDelegate ()
@property (strong, nonatomic) ABYContextManager* contextManager;
@property (strong, nonatomic) ABYServer* replServer;
@end
@implementation AppDelegate
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Optionally set the idle timer disabled, this prevents the device from sleep when
// not being interacted with by touch. ie. games with motion control.
application.idleTimerDisabled = YES;
window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
[self loadViewControllerWithScriptAtPath:@"resources/public/js/index.js"];
EJJavaScriptView* appView = (EJJavaScriptView*)window.rootViewController.view;
JSGlobalContextRef ctx = appView.jsGlobalContext;
NSURL* compilerOutputDirectory = [[self privateDocumentsDirectory] URLByAppendingPathComponent:@"cljs-out"];
[self createDirectoriesUpTo:compilerOutputDirectory];
// Set up our context
self.contextManager = [[ABYContextManager alloc] initWithContext:ctx
compilerOutputDirectory:compilerOutputDirectory];
[self.contextManager setupGlobalContext];
[self.contextManager setUpConsoleLog];
[self.contextManager setUpTimerFunctionality];
[self.contextManager setUpAmblyImportScript];
self.replServer = [[ABYServer alloc] initWithContext:self.contextManager.context
compilerOutputDirectory:compilerOutputDirectory];
BOOL successful = [self.replServer startListening];
if (!successful) {
NSLog(@"Failed to start REPL server.");
} else {
NSLog(@"Started REPL server.");
}
[window makeKeyAndVisible];
return YES;
}
- (void)loadViewControllerWithScriptAtPath:(NSString *)path {
// Release any previous ViewController
window.rootViewController = nil;
EJAppViewController *vc = [[EJAppViewController alloc] initWithScriptAtPath:path];
window.rootViewController = vc;
[vc release];
}
#pragma mark -
#pragma mark Ambly helper methods
- (NSURL *)privateDocumentsDirectory
{
NSSearchPathDirectory directory;
#ifdef TARGET_OS_TV
directory = NSCachesDirectory;
#else
directory = NSLibraryDirectory;
#endif
NSURL *userDirectory = [[[NSFileManager defaultManager] URLsForDirectory:directory inDomains:NSUserDomainMask] lastObject];
return [userDirectory URLByAppendingPathComponent:@"Private Documents"];
}
- (void)createDirectoriesUpTo:(NSURL*)directory
{
if (![[NSFileManager defaultManager] fileExistsAtPath:[directory path]]) {
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:[directory path]
withIntermediateDirectories:YES
attributes:nil
error:&error]) {
NSLog(@"Can't create directory %@ [%@]", [directory path], error);
abort();
}
}
}
#pragma mark -
#pragma mark Memory management
- (void)dealloc {
window.rootViewController = nil;
[window release];
[super dealloc];
}
@end
platform :ios, '9.0'
platform :tvos, '9.0'
link_with 'LetterComb', 'LetterComb-TV'
pod "GCDWebServer/WebDAV", :git => 'https://github.com/swisspol/GCDWebServer', :commit => 'c98941121a4b96a4fa4ad785790a4a3e119227a5'
pod "Ambly", :git => 'https://github.com/sherbondy/ambly.git'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment