Skip to content

Commit d106a62

Browse files
committed
Register ourselves as a file handler for text/html files
1 parent 0d179d8 commit d106a62

File tree

3 files changed

+45
-18
lines changed

3 files changed

+45
-18
lines changed

Objektiv/AppDelegate.m

+29-17
Original file line numberDiff line numberDiff line change
@@ -253,23 +253,6 @@ - (void) showNotification:(NSString *)browserIdentifier
253253
[center deliverNotification:notification];
254254
}
255255

256-
- (void)getUrl:(NSAppleEventDescriptor *)event
257-
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
258-
{
259-
// Get the URL
260-
NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject]
261-
stringValue];
262-
NSArray *urls = [NSArray arrayWithObject:[NSURL URLWithString:urlStr]];
263-
264-
int options = NSWorkspaceLaunchAsync;
265-
266-
[[NSWorkspace sharedWorkspace] openURLs: urls
267-
withAppBundleIdentifier: [[Browsers sharedInstance] defaultBrowserIdentifier]
268-
options: options
269-
additionalEventParamDescriptor: nil
270-
launchIdentifiers: nil];
271-
}
272-
273256
- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification
274257
{
275258
return YES;
@@ -300,4 +283,33 @@ -(void)displayAreWeDefaultMsg
300283
}
301284
}
302285

286+
#pragma mark - File Handlers
287+
288+
- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
289+
{
290+
[self openWithBrowser:[NSString stringWithFormat:kLocalFileUri, filename]];
291+
return YES;
292+
}
293+
294+
- (void)getUrl:(NSAppleEventDescriptor *)event
295+
withReplyEvent:(NSAppleEventDescriptor *)replyEvent
296+
{
297+
[self openWithBrowser:[[event paramDescriptorForKeyword:keyDirectObject]
298+
stringValue]];
299+
}
300+
301+
- (void)openWithBrowser:(NSString*)location
302+
{
303+
304+
NSArray *urls = [NSArray arrayWithObject:[NSURL URLWithString:location]];
305+
306+
int options = NSWorkspaceLaunchAsync;
307+
308+
[[NSWorkspace sharedWorkspace] openURLs: urls
309+
withAppBundleIdentifier: [[Browsers sharedInstance] defaultBrowserIdentifier]
310+
options: options
311+
additionalEventParamDescriptor: nil
312+
launchIdentifiers: nil];
313+
}
314+
303315
@end

Objektiv/Constants.h

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define NotificationTitle NSLocalizedString(@"%@ selected", @"Title of the notification")
2727
#define NotificationText NSLocalizedString(@"You selected %@ as your default browser using %@.", @"Notification text")
2828

29+
#define kLocalFileUri @"file://locahost%@"
30+
2931
#define StatusBarIconSize 16
3032

3133
// Via https://gist.github.com/1057420

Objektiv/Objektiv-Info.plist

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
66
<string>en</string>
7+
<key>CFBundleDocumentTypes</key>
8+
<array>
9+
<dict>
10+
<key>CFBundleTypeName</key>
11+
<string>TEXT</string>
12+
<key>LSHandlerRank</key>
13+
<string>Alternate</string>
14+
<key>LSItemContentTypes</key>
15+
<array>
16+
<string>public.text</string>
17+
</array>
18+
</dict>
19+
</array>
720
<key>CFBundleExecutable</key>
821
<string>${EXECUTABLE_NAME}</string>
922
<key>CFBundleIconFile</key>
@@ -17,7 +30,7 @@
1730
<key>CFBundlePackageType</key>
1831
<string>APPL</string>
1932
<key>CFBundleShortVersionString</key>
20-
<string>0.6.2</string>
33+
<string>0.6.3</string>
2134
<key>CFBundleSignature</key>
2235
<string>????</string>
2336
<key>CFBundleURLTypes</key>

0 commit comments

Comments
 (0)