From 7983809e7ce0c7ba907d81dedd00f5a462c77896 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 18:01:53 +0000 Subject: [PATCH 1/8] Changed OK button text to Install addresses #230 --- App/BitBar/AppDelegate.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/BitBar/AppDelegate.m b/App/BitBar/AppDelegate.m index 3fa054f20..44ad17906 100644 --- a/App/BitBar/AppDelegate.m +++ b/App/BitBar/AppDelegate.m @@ -96,7 +96,7 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppl plugin = URLString.lastPathComponent; NSAlert *alert = [[NSAlert alloc] init]; - [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"Install"]; [alert addButtonWithTitle:@"Cancel"]; alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", plugin ?: [NSString stringWithFormat:@"at %@", URLString]]; alert.informativeText = @"Only install plugins from trusted sources."; From 555363dce3b5805fcde9362721e9faeb61c6f980 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 18:07:17 +0000 Subject: [PATCH 2/8] added alternative trusted text --- App/BitBar/AppDelegate.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/App/BitBar/AppDelegate.m b/App/BitBar/AppDelegate.m index 44ad17906..20b21f92b 100644 --- a/App/BitBar/AppDelegate.m +++ b/App/BitBar/AppDelegate.m @@ -90,17 +90,25 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppl URLString = [URLString substringFromIndex:prefix.length]; NSString *plugin = nil; + BOOL trusted = NO; // if the plugin is at our repository, only display the filename - if ([URLString hasPrefix:@"https://github.com/matryer/bitbar-plugins/raw/master/"]) + if ([URLString hasPrefix:@"https://github.com/matryer/bitbar-plugins/raw/master/"]) { plugin = URLString.lastPathComponent; + trusted = YES; + } NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"Install"]; [alert addButtonWithTitle:@"Cancel"]; alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", plugin ?: [NSString stringWithFormat:@"at %@", URLString]]; - alert.informativeText = @"Only install plugins from trusted sources."; - + + if (trusted) { + alert.informativeText = @"Only install plugins from trusted sources."; + } else { + alert.informativeText = @"CAUTION: This plugin is not from the official BitBar repository. We recommend that you only install plugins from trusted sources."; + } + if ([alert runModal] != NSAlertFirstButtonReturn) { // cancel clicked return; From 7606a4a49afebb632ec759c5fca4de0de76e0bd9 Mon Sep 17 00:00:00 2001 From: iosdeveloper Date: Tue, 16 Feb 2016 19:50:46 +0100 Subject: [PATCH 3/8] added optional title parameter --- App/BitBar/AppDelegate.m | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/App/BitBar/AppDelegate.m b/App/BitBar/AppDelegate.m index 20b21f92b..b8229e2c6 100644 --- a/App/BitBar/AppDelegate.m +++ b/App/BitBar/AppDelegate.m @@ -81,27 +81,47 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppl // extract the url from the event and handle it NSString *URLString = [event paramDescriptorForKeyword:keyDirectObject].stringValue; - NSString *prefix = @"bitbar://openPlugin?src="; + URLString = [URLString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *prefix = @"bitbar://openPlugin?"; // skip urls that don't begin with our prefix + if (![URLString hasPrefix:prefix]) + return; + + URLString = [URLString substringFromIndex:prefix.length]; + prefix = @"title="; + + NSString *title = nil; + + if ([URLString hasPrefix:prefix]) { + URLString = [URLString substringFromIndex:prefix.length]; + NSArray *components = [URLString componentsSeparatedByString:@"&"]; + + if (components.count < 2) + return; + + title = components.firstObject; + URLString = [[components subarrayWithRange:NSMakeRange(1, components.count - 1)] componentsJoinedByString:@"&"]; + } + + prefix = @"src="; + if (![URLString hasPrefix:prefix]) return; URLString = [URLString substringFromIndex:prefix.length]; - NSString *plugin = nil; BOOL trusted = NO; // if the plugin is at our repository, only display the filename if ([URLString hasPrefix:@"https://github.com/matryer/bitbar-plugins/raw/master/"]) { - plugin = URLString.lastPathComponent; trusted = YES; } NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"Install"]; [alert addButtonWithTitle:@"Cancel"]; - alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", plugin ?: [NSString stringWithFormat:@"at %@", URLString]]; + alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", trusted ? (title ?: URLString.lastPathComponent) : [NSString stringWithFormat:@"at %@", URLString]]; if (trusted) { alert.informativeText = @"Only install plugins from trusted sources."; From 0d0bea4407e7653125dc147bf6bc5ad1bf33218c Mon Sep 17 00:00:00 2001 From: iosdeveloper Date: Tue, 16 Feb 2016 22:25:36 +0100 Subject: [PATCH 4/8] fixed empty title --- App/BitBar/AppDelegate.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/App/BitBar/AppDelegate.m b/App/BitBar/AppDelegate.m index b8229e2c6..9174b72a4 100644 --- a/App/BitBar/AppDelegate.m +++ b/App/BitBar/AppDelegate.m @@ -121,7 +121,7 @@ - (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppl NSAlert *alert = [[NSAlert alloc] init]; [alert addButtonWithTitle:@"Install"]; [alert addButtonWithTitle:@"Cancel"]; - alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", trusted ? (title ?: URLString.lastPathComponent) : [NSString stringWithFormat:@"at %@", URLString]]; + alert.messageText = [NSString stringWithFormat:@"Download and install the plugin %@?", trusted ? (title.length > 0 ? title : URLString.lastPathComponent) : [NSString stringWithFormat:@"at %@", URLString]]; if (trusted) { alert.informativeText = @"Only install plugins from trusted sources."; From c07abf78e2e377bd8b324227e967c20516225421 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 21:41:08 +0000 Subject: [PATCH 5/8] added test page --- App/BitBar/incoming-url-tests.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 App/BitBar/incoming-url-tests.html diff --git a/App/BitBar/incoming-url-tests.html b/App/BitBar/incoming-url-tests.html new file mode 100644 index 000000000..490acc00d --- /dev/null +++ b/App/BitBar/incoming-url-tests.html @@ -0,0 +1,30 @@ + + + + Incoming URL tests + + + +

BitBar - Incoming URL tests

+ + + + + + + + + + + + +
LinkDescription
+ + Click me + + + Should open and install 'Cycle Text and Detail' plugin +
+ + + \ No newline at end of file From aadb533de60de27945391fdcdeb7a5862ea19748 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 21:42:38 +0000 Subject: [PATCH 6/8] added missing title test --- App/BitBar/incoming-url-tests.html | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/App/BitBar/incoming-url-tests.html b/App/BitBar/incoming-url-tests.html index 490acc00d..a20451d20 100644 --- a/App/BitBar/incoming-url-tests.html +++ b/App/BitBar/incoming-url-tests.html @@ -11,19 +11,29 @@

BitBar - Incoming URL tests

Link - Description + Expectation - Click me + Normal Should open and install 'Cycle Text and Detail' plugin + + + + Missing title + + + + Should open and install 'Cycle Text and Detail' plugin but use cycle_text_and_detail.sh as title + + From fd46eeb54f3aac09bba8f6ff584534740a8d0568 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 21:44:14 +0000 Subject: [PATCH 7/8] added more tests --- App/BitBar/incoming-url-tests.html | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/App/BitBar/incoming-url-tests.html b/App/BitBar/incoming-url-tests.html index a20451d20..3701667c0 100644 --- a/App/BitBar/incoming-url-tests.html +++ b/App/BitBar/incoming-url-tests.html @@ -34,6 +34,36 @@

BitBar - Incoming URL tests

Should open and install 'Cycle Text and Detail' plugin but use cycle_text_and_detail.sh as title + + + + Empty title + + + + Should open and install 'Cycle Text and Detail' plugin but use cycle_text_and_detail.sh as title + + + + + + Empty title + + + + Should open and install 'Cycle Text and Detail' plugin but use cycle_text_and_detail.sh as title + + + + + + Unofficial repo + + + + Should open and install test plugin but have additional warnings. + + From 941084e4e980f52a77ab1b1fcc2d21318aa1c3d8 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Tue, 16 Feb 2016 21:45:24 +0000 Subject: [PATCH 8/8] updated tests --- App/BitBar/incoming-url-tests.html | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/App/BitBar/incoming-url-tests.html b/App/BitBar/incoming-url-tests.html index 3701667c0..a58ae3583 100644 --- a/App/BitBar/incoming-url-tests.html +++ b/App/BitBar/incoming-url-tests.html @@ -46,22 +46,12 @@

BitBar - Incoming URL tests

- - Empty title - - - - Should open and install 'Cycle Text and Detail' plugin but use cycle_text_and_detail.sh as title - - - - - + Unofficial repo - Should open and install test plugin but have additional warnings. + Should open and install test plugin but have additional warnings - and use full URL (not title)