Skip to content

Commit

Permalink
Merge branch 'issue-230'
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Feb 16, 2016
2 parents 3db3f00 + 941084e commit eeafcd2
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 8 deletions.
44 changes: 36 additions & 8 deletions App/BitBar/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,54 @@ - (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 *plugin = nil;
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];

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;
if ([URLString hasPrefix:@"https://github.com/matryer/bitbar-plugins/raw/master/"]) {
trusted = YES;
}

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.";

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.";
} 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;
Expand Down
60 changes: 60 additions & 0 deletions App/BitBar/incoming-url-tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<title>Incoming URL tests</title>
</head>
<body>

<h1>BitBar - Incoming URL tests</h1>

<table>
<thead>
<tr>
<th>Link</th>
<th>Expectation</th>
</tr>
</thead>
<tr>
<td>
<a href="bitbar://openPlugin?title=Cycle%20text%20and%20detail%20text&amp;src=https://github.com/matryer/bitbar-plugins/raw/master/Tutorial%2fcycle_text_and_detail.sh">
Normal
</a>
</td>
<td>
Should open and install 'Cycle Text and Detail' plugin
</td>
</tr>
<tr>
<td>
<a href="bitbar://openPlugin?src=https://github.com/matryer/bitbar-plugins/raw/master/Tutorial%2fcycle_text_and_detail.sh">
Missing title
</a>
</td>
<td>
Should open and install 'Cycle Text and Detail' plugin but use <code>cycle_text_and_detail.sh</code> as title
</td>
</tr>
<tr>
<td>
<a href="bitbar://openPlugin?title=&amp;src=https://github.com/matryer/bitbar-plugins/raw/master/Tutorial%2fcycle_text_and_detail.sh">
Empty title
</a>
</td>
<td>
Should open and install 'Cycle Text and Detail' plugin but use <code>cycle_text_and_detail.sh</code> as title
</td>
</tr>
<tr>
<td>
<a href="bitbar://openPlugin?title=Test+plugin&amp;src=https://github.com/matryer/bitbar/raw/master/App/BitBarTests/TestPlugins/one.10s.sh">
Unofficial repo
</a>
</td>
<td>
Should open and install test plugin but have additional warnings - and use full URL (not title)
</td>
</tr>
</table>

</body>
</html>

0 comments on commit eeafcd2

Please sign in to comment.