Skip to content

Commit

Permalink
Initial working boilerplate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Schoonology committed May 5, 2016
1 parent 10ef5ea commit 935c85a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Browter.app
49 changes: 49 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?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>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>main</string>
<key>CFBundleIconFile</key>
<string>Calculator.icns</string>
<key>CFBundleIdentifier</key>
<string>com.schoonology.Browter</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleName</key>
<string>Browter</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Shell</string>
<key>CFBundleURLName</key>
<string>com.schoonology.browter</string>
<key>CFBundleURLSchemes</key>
<array>
<string>file</string>
<string>http</string>
<string>https</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>0.1</string>
<key>LSHasLocalizedDisplayName</key>
<true/>
<key>LSMinimumSystemVersion</key>
<string>10.7</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>NSSupportsSuddenTermination</key>
<false/>
</dict>
</plist>
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: app

clean:
rm -rf Browter.app

app:
mkdir -p Browter.app/Contents/MacOS
clang -lobjc -fobjc-arc -framework Foundation -framework AppKit main.m -o Browter.app/Contents/MacOS/main
cp Info.plist Browter.app/Contents/.
rm -rf Browter.app/Contents/MacOS/main.dSYM
57 changes: 57 additions & 0 deletions main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

/**
* Top-level object to give NSAppleEventManager something to call, as it cannot
* call arbitrary functions.
*/
@interface URLHandler : NSObject {}
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent;
@end

@implementation URLHandler
/**
* Initializes the URLHandler, wiring up the one and only event we care about.
*/
- (id)init
{
self = [super init];

if (self) {
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}

return self;
}

/**
* Event handler fired whenever any http://, https://, or file:// URL is opened
* system-wide (as defined in Info.plist).
*/
- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString* url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSString* app = @"Firefox";

NSLog(@"Opening %@ with %@...", url, app);

[NSTask launchedTaskWithLaunchPath:@"/usr/bin/open" arguments:@[url, @"-a", app]];
}

@end

/**
* Initializes the process and creates our top-level object, which will handle
* the actual URL routing.
*/
int main(int argc, const char * argv[]) {
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToBackgroundApplication);

URLHandler *handler = [[URLHandler alloc] init];

return NSApplicationMain(argc, argv);
}

0 comments on commit 935c85a

Please sign in to comment.