From 319b68747ba8df4d217bb9da55d13eeb55cde2b1 Mon Sep 17 00:00:00 2001 From: Tsukasa OMOTO Date: Sun, 13 Jul 2014 14:51:02 +0900 Subject: [PATCH 1/2] decode fragment identifier --- Terminal Notifier/AppDelegate.m | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/Terminal Notifier/AppDelegate.m b/Terminal Notifier/AppDelegate.m index f260656..c17c768 100644 --- a/Terminal Notifier/AppDelegate.m +++ b/Terminal Notifier/AppDelegate.m @@ -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 @@ -214,6 +227,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 From 92fb03ee429721feb25899f1ef81585a4175f6d1 Mon Sep 17 00:00:00 2001 From: Tsukasa OMOTO Date: Sat, 12 Jul 2014 04:29:52 +0900 Subject: [PATCH 2/2] get imageURL with fileURLWithPath if no scheme This supports spaces and multibyte characters in file path. --- Terminal Notifier/AppDelegate.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Terminal Notifier/AppDelegate.m b/Terminal Notifier/AppDelegate.m index c17c768..9f593f5 100644 --- a/Terminal Notifier/AppDelegate.m +++ b/Terminal Notifier/AppDelegate.m @@ -221,8 +221,7 @@ - (NSImage*)getImageFromURL:(NSString *) url; NSURL *imageURL = [NSURL URLWithString:url]; if([[imageURL scheme] length] == 0){ // Prefix 'file://' if no scheme - url = [NSString stringWithFormat:@"%@%@", @"file://", url]; - imageURL = [NSURL URLWithString:url]; + imageURL = [NSURL fileURLWithPath:url]; } return [[NSImage alloc] initWithContentsOfURL:imageURL]; }