-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10ef5ea
commit 935c85a
Showing
4 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Browter.app |
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
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> |
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
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 |
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
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); | ||
} |