Skip to content

Commit

Permalink
Merge branch 'henry0312-fix_open'
Browse files Browse the repository at this point in the history
  • Loading branch information
julienXX committed Jul 25, 2014
2 parents a1f2c7c + 92fb03e commit 5f8bb95
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Terminal Notifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,22 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
if (defaults[@"activate"]) options[@"bundleID"] = defaults[@"activate"];
if (defaults[@"group"]) options[@"groupID"] = defaults[@"group"];
if (defaults[@"execute"]) options[@"command"] = defaults[@"execute"];
if (defaults[@"open"]) options[@"open"] = [defaults[@"open"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (defaults[@"appIcon"]) options[@"appIcon"] = defaults[@"appIcon"];
if (defaults[@"contentImage"]) options[@"contentImage"] = defaults[@"contentImage"];
if (defaults[@"open"]) {
/*
* it may be better to use stringByAddingPercentEncodingWithAllowedCharacters instead of stringByAddingPercentEscapesUsingEncoding,
* but stringByAddingPercentEncodingWithAllowedCharacters is only available on OS X 10.9 or higher.
*/
NSString *encodedURL = [defaults[@"open"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:defaults[@"open"]];
NSString *fragment = [url fragment];
if (fragment) {
options[@"open"] = [self decodeFragmentInURL:encodedURL fragment:fragment];
} else {
options[@"open"] = encodedURL;
}
}

[self deliverNotificationWithTitle:defaults[@"title"] ?: @"Terminal"
subtitle:subtitle
Expand All @@ -213,6 +226,20 @@ - (NSImage*)getImageFromURL:(NSString *) url;
return [[NSImage alloc] initWithContentsOfURL:imageURL];
}

/**
* Decode fragment identifier
*
* @see http://tools.ietf.org/html/rfc3986#section-2.1
* @see http://en.wikipedia.org/wiki/URI_scheme
*/
- (NSString*)decodeFragmentInURL:(NSString *) encodedURL fragment:(NSString *) framgent
{
NSString *beforeStr = [@"%23" stringByAppendingString:framgent];
NSString *afterStr = [@"#" stringByAppendingString:framgent];
NSString *decodedURL = [encodedURL stringByReplacingOccurrencesOfString:beforeStr withString:afterStr];
return decodedURL;
}

- (void)deliverNotificationWithTitle:(NSString *)title
subtitle:(NSString *)subtitle
message:(NSString *)message
Expand Down

0 comments on commit 5f8bb95

Please sign in to comment.