Skip to content

Commit

Permalink
addTrackers refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelficarra committed Mar 6, 2011
1 parent 094065b commit ea8c6e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

## TODO (before release)

* use proper node function signatures (first argument is `err`)
* handle errors by adding retry button (must be using node style callback signatures first)
* verify bug fix: add torrent successfully, change host, attempt to add torrent again; infinite loop (partially due to cached session id)
* test: only adds additional trackers if the option is enabled
* inspect [license of icon file](http://www.veryicon.com/icons/system/arcade-daze-apps-vol-1/transmission-2.html)
* set up automatic updates
* do rigorous hand testing
* bump version
* package the plugin
* write up installation/usage for README


## TODO (after release)

* use proper node function signatures (first argument is `err`)
* handle errors by adding retry button (must be using node style callback signatures first)
* don't make user type in password repeatedly (send request to background page to store password in closure for X seconds)
* don't require save button on options page
* find a way to test this thing
Expand Down
2 changes: 1 addition & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ <h3 id="rpc"></h3>

<p>
<button id="addTorrent" disabled="disabled">Add Torrent</button>
<button id="close" class="hidden">Close</button>
<button id="retry" class="hidden">Retry</button>
<button id="close" class="hidden">Close</button>
</p>

<script type="text/javascript" src="popup.js"></script>
Expand Down
27 changes: 18 additions & 9 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,11 @@

var addTrackers = function(torrent, callback){
if(!torrent || !torrent.id || !torrent.hashString)
return error('attempted to add trackers to an invalid torrent');
info('fetching tracker list');
getTrackers(torrent.hashString, function(trackers){
info('retrieved tracker list', trackers);
if(!trackers || !getOption('AddTrackers')) trackers = [];
var additionalTrackers = getOption('AdditionalTrackers');
info('adding supplementary trackers', trackers, additionalTrackers);
return error('attempted to add trackers to an invalid torrent', torrent);
var additionalTrackers = getOption('AdditionalTrackers');
var next = function(trackers){
if(additionalTrackers.length)
info('adding supplementary trackers', additionalTrackers);
trackers = trackers.concat(additionalTrackers);
if(!trackers.length)
return typeof callback=='function' ? callback([]) : null;
Expand All @@ -191,7 +189,16 @@
var basicAuth = 'Basic '+Base64.encode(authentication.username+':'+authentication.password);
if(authentication.enabled) xhr.setRequestHeader('Authorization', basicAuth);
xhr.send(JSON.stringify(postData));
});
}
if(getOption('AddTrackers')) {
info('fetching tracker list');
getTrackers(torrent.hashString, function(trackers){
info('retrieved tracker list', trackers);
return next(trackers || []);
});
} else {
next([]);
}
};


Expand Down Expand Up @@ -246,7 +253,9 @@
if(trackers)
info('added ' + trackers.length + ' additional trackers', trackers);
log('done')('done');
removeClass.call($(success ? 'close' : 'retry'), 'hidden');
if(!success) removeClass.call($('retry'), 'hidden');
removeClass.call($('close'), 'hidden');
$(success ? 'close' : 'retry').focus();
});
});
});
Expand Down

0 comments on commit ea8c6e6

Please sign in to comment.