Skip to content

Commit

Permalink
First shot at minimal APIs using Cocoa JavaScriptCore
Browse files Browse the repository at this point in the history
  • Loading branch information
pojala committed May 3, 2017
1 parent df36fd5 commit 1b8e1f8
Show file tree
Hide file tree
Showing 35 changed files with 2,135 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
# Mac desktop data
.DS_Store

# Compiled Object files
*.slo
*.lo
Expand Down
386 changes: 386 additions & 0 deletions Electrino/Electrino.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
type = "1"
version = "2.0">
</Bucket>
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5AA9DBAD1EB9F58A00EF7CC9"
BuildableName = "ElectrinoTest.app"
BlueprintName = "ElectrinoTest"
ReferencedContainer = "container:Electrino.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5AA9DBAD1EB9F58A00EF7CC9"
BuildableName = "ElectrinoTest.app"
BlueprintName = "ElectrinoTest"
ReferencedContainer = "container:Electrino.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5AA9DBAD1EB9F58A00EF7CC9"
BuildableName = "ElectrinoTest.app"
BlueprintName = "ElectrinoTest"
ReferencedContainer = "container:Electrino.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "5AA9DBAD1EB9F58A00EF7CC9"
BuildableName = "ElectrinoTest.app"
BlueprintName = "ElectrinoTest"
ReferencedContainer = "container:Electrino.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Electrino.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>5AA9DBAD1EB9F58A00EF7CC9</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
15 changes: 15 additions & 0 deletions Electrino/Electrino/AppDelegate.h
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// Electrino
//
// Created by Pauli Ojala on 03/05/17.
// Copyright © 2017 Lacquer. All rights reserved.
//

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>


@end

72 changes: 72 additions & 0 deletions Electrino/Electrino/AppDelegate.m
@@ -0,0 +1,72 @@
//
// AppDelegate.m
// Electrino
//
// Created by Pauli Ojala on 03/05/17.
// Copyright © 2017 Lacquer. All rights reserved.
//

#import "AppDelegate.h"
#import "ENOJavaScriptApp.h"


@interface AppDelegate ()

@end




@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *appDir = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"js-app"];
NSString *mainJSPath = [appDir stringByAppendingPathComponent:@"main.js"];

if ( ![[NSFileManager defaultManager] fileExistsAtPath:mainJSPath]) {
NSLog(@"** no main.js found in dir: %@", appDir);
[NSApp terminate:nil]; // --
}

NSString *mainJS = [NSString stringWithContentsOfFile:mainJSPath encoding:NSUTF8StringEncoding error:NULL];
ENOJavaScriptApp *jsApp = [ENOJavaScriptApp sharedApp];
NSError *error = nil;

// setup
jsApp.jsContext[@"__dirname"] = appDir;

// load code
if ( ![jsApp loadMainJS:mainJS error:&error]) {
NSLog(@"** could not load main.js: %@, path: %@", error, mainJSPath);

[self _presentJSError:error message:@"Main program execution failed."];

[NSApp terminate:nil]; // --
}

// start
if ( ![jsApp.jsAppGlobalObject emitReady:&error]) {
NSLog(@"** app.on('ready'): %@", error);

[self _presentJSError:error message:@"Exception in app.on('ready')"];
}
}

- (void)_presentJSError:(NSError *)error message:(NSString *)msg
{
NSAlert *alert = [[NSAlert alloc] init];
alert.alertStyle = NSCriticalAlertStyle;
alert.messageText = msg ?: @"JavaScript error";
alert.informativeText = [NSString stringWithFormat:@"\n%@\n\n(On line %@)", error.localizedDescription, error.userInfo[@"SourceLineNumber"]];

[alert runModal];
}

- (void)applicationWillTerminate:(NSNotification *)aNotification
{

}


@end
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "16x16",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "32x32",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "128x128",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "256x256",
"scale" : "2x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "1x"
},
{
"idiom" : "mac",
"size" : "512x512",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

0 comments on commit 1b8e1f8

Please sign in to comment.