Skip to content

Commit

Permalink
Register ourselves as a file handler for text/html files
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorror committed Jan 11, 2017
1 parent 0d179d8 commit d106a62
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
46 changes: 29 additions & 17 deletions Objektiv/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,6 @@ - (void) showNotification:(NSString *)browserIdentifier
[center deliverNotification:notification];
}

- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
// Get the URL
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
stringValue];
NSArray *urls = [NSArray arrayWithObject:[NSURL URLWithString:urlStr]];

int options = NSWorkspaceLaunchAsync;

[[NSWorkspace sharedWorkspace] openURLs: urls
withAppBundleIdentifier: [[Browsers sharedInstance] defaultBrowserIdentifier]
options: options
additionalEventParamDescriptor: nil
launchIdentifiers: nil];
}

- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
{
return YES;
Expand Down Expand Up @@ -300,4 +283,33 @@ -(void)displayAreWeDefaultMsg
}
}

#pragma mark - File Handlers

- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
{
[self openWithBrowser:[NSString stringWithFormat:kLocalFileUri, filename]];
return YES;
}

- (void)getUrl:(NSAppleEventDescriptor *)event
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
[self openWithBrowser:[[event paramDescriptorForKeyword:keyDirectObject]
stringValue]];
}

- (void)openWithBrowser:(NSString*)location
{

NSArray *urls = [NSArray arrayWithObject:[NSURL URLWithString:location]];

int options = NSWorkspaceLaunchAsync;

[[NSWorkspace sharedWorkspace] openURLs: urls
withAppBundleIdentifier: [[Browsers sharedInstance] defaultBrowserIdentifier]
options: options
additionalEventParamDescriptor: nil
launchIdentifiers: nil];
}

@end
2 changes: 2 additions & 0 deletions Objektiv/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define NotificationTitle NSLocalizedString(@"%@ selected", @"Title of the notification")
#define NotificationText NSLocalizedString(@"You selected %@ as your default browser using %@.", @"Notification text")

#define kLocalFileUri @"file://locahost%@"

#define StatusBarIconSize 16

// Via https://gist.github.com/1057420
Expand Down
15 changes: 14 additions & 1 deletion Objektiv/Objektiv-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>TEXT</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.text</string>
</array>
</dict>
</array>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
Expand All @@ -17,7 +30,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>0.6.2</string>
<string>0.6.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down

0 comments on commit d106a62

Please sign in to comment.