Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
ABH is asynchronous
Browse files Browse the repository at this point in the history
Before we will push it live we need to have ABH 1.4 downloadable on AMO

* display a warning if ABH is not responding with an object containing `then`
* set the desired ABH number to 1.4
  • Loading branch information
zalun committed Jan 13, 2012
1 parent fd15809 commit eefd0c7
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 52 deletions.
3 changes: 1 addition & 2 deletions apps/base/templates/base.html
Expand Up @@ -31,8 +31,7 @@
{% block app_settings %}{% endblock %}{% block page_settings %}{% endblock %}
addons_helper: '{{ settings.ADDONS_HELPER_URL }}',
{% if waffle.switch('checkAddonsHelperVersion') %}
addons_helper_version: '{{
settings.ADDONS_HELPER_VERSION }}',
addons_helper_version: '{{ settings.ADDONS_HELPER_VERSION }}',
{% endif %}
person_login_url: '{{ login_url }}',
jp_addon_create_url: '{{ url('jp_addon_create') }}',
Expand Down
1 change: 1 addition & 0 deletions apps/jetpack/management/commands/fix_packages.py
Expand Up @@ -36,6 +36,7 @@ def handle(self, *args, **kwargs):
fixed_latest_count += 1
else:
# package is deleted
self.stdout.write('[%s] Package deleted\n' % package.id_number)
deleted_packages_count += 1
if not latest or isinstance(latest, PackageRevision):
# otherwise the package is deleted anyway
Expand Down
120 changes: 71 additions & 49 deletions media/base/js/flightdeck/FlightDeck.js
Expand Up @@ -71,7 +71,6 @@ module.exports = new Class({
this.addListener('xpi_downloaded', this.whenXpiDownloaded);
this.addListener('xpi_installed', this.whenXpiInstalled);
this.addListener('xpi_uninstalled', this.whenXpiUninstalled);
//if (!this.isAddonInstalled()) $log('FD: No Addon Builder Helper')

dom.$('app-body').delegate('.truncate', 'click', function(e) {
var tmp = this.get('data-text');
Expand All @@ -81,17 +80,18 @@ module.exports = new Class({
},

whenXpiInstalled: function(name) {
this.parseTestButtons();
this.message.alert('Add-on Builder', 'Add-on installed');
this.parseTestButtons();
log.info('Add-on installed');
},

whenXpiDownloaded: function(hashtag) {
},

whenXpiUninstalled: function() {
this.parseTestButtons();
log.info('Add-on uninstalled');
this.message.alert('Add-on Builder', 'Add-on uninstalled');
this.parseTestButtons();
},

/*
Expand All @@ -101,7 +101,7 @@ module.exports = new Class({
whenAddonInstalled: function(callback) {
var handle = dom.document.body.addListener('addonbuilderhelperstart', callback);
setTimeout(function() {
log.warning('not listening to addonbuilderhelperstart, is Helper installed?');
log.warn('not listening to addonbuilderhelperstart, is Helper installed?');
handle.detach();
}, 1000 * 100);
},
Expand All @@ -121,16 +121,19 @@ module.exports = new Class({
},

parseTestButtons: function() {
var installed = (this.isAddonInstalled()) ? this.isXpiInstalled() : false;
if (installed) {
dom.$$(string.substitute('.{try_in_browser_class} a', this.options)).forEach(function(test_button){
if (installed && installed.installedID === test_button.get('data-jetpackid')) {
test_button.getParent('li').addClass('pressed');
} else {
test_button.getParent('li').removeClass('pressed');
}
}, this);
}
if (!this.isAddonInstalled()) return;
ABH().send('isInstalled').then(function(response) {
if (response.success) {
dom.$$(string.substitute('.{try_in_browser_class} a', this.options))
.forEach(function(test_button){
if (response.installedID === test_button.get('data-jetpackid')) {
test_button.getParent('li').addClass('pressed');
} else {
test_button.getParent('li').removeClass('pressed');
}
}, this);
}
}.bind(this));
},

/*
Expand All @@ -156,14 +159,14 @@ module.exports = new Class({
* Try to download XPI
* if finished - stop periodical, stop spinner
*/
tryDownloadXPI: function(hashtag, filename) {
tryDownloadXPI: function (hashtag, filename) {
var fd = this;
var test_request = this.tests[hashtag];
if (!test_request.download_xpi_request || (
test_request.download_xpi_request &&
!test_request.download_xpi_request.isRunning())) {
test_request.download_request_number++;
var url = '/xpi/check_download/'+hashtag+'/';
var url = '/xpi/check_download/' + hashtag + '/';
log.debug('checking if ' + url + ' is prepared (attempt ' +
test_request.download_request_number + '/50)');
var r = test_request.download_xpi_request = new Request({
Expand Down Expand Up @@ -217,10 +220,6 @@ module.exports = new Class({
}, this.options.request_interval);
},

isXpiInstalled: function() {
return ABH().send({cmd:'isInstalled'});
},

/*
* Method: tryInstallXPI
*
Expand Down Expand Up @@ -254,24 +253,26 @@ module.exports = new Class({
if (fd.item) {
this.fireEvent('xpi_downloaded', hashtag);
}
var result = ABH().send({
cmd: "install", contents: responseText
});
if (result && result.success) {
this.fireEvent('xpi_installed', '');
} else {
if (result) {
log.debug('Unsucessful result:', result);
}
this.warning.alert(
'Add-on Builder',
'Wrong response from Add-on Builder Helper. Please <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=573778">let us know</a>'
);
}
var result = ABH().send("install", responseText).then(function(response) {
if (response && response.success) {
this.fireEvent('xpi_installed', '');
} else {
if (response) {
log.debug('Unsuccessful response:', response);
}
this.warning.alert(
'Add-on Builder',
'Wrong response from Add-on Builder Helper. ' +
'Please <a href="https://bugzilla.mozilla.org/' +
'show_bug.cgi?id=573778">let us know</a>'
);
}
}.bind(this));
} else if (test_request.request_number > 50) {
this.warning.alert(
'Add-on Builder',
'The add-on was not successfully built (attempts timed out). Please try again.'
'The add-on was not successfully built ' +
'(attempts timed out). Please try again.'
);
}
}.bind(this),
Expand All @@ -294,12 +295,15 @@ module.exports = new Class({
*
* Remove Add-on from Browser
*/
uninstallXPI: function(jid) {
log.info('uninstalling ' + jid);
var result = ABH().send({cmd:'uninstall'});
if (result.success) {
this.fireEvent('xpi_uninstalled');
}
uninstallXPI: function() {
log.debug('uninstalling add-on');
ABH().send('uninstall').then(function(response){
if (response.success) {
// XXX: no idea why it's not working without this line
log.debug('');
this.fireEvent('xpi_uninstalled');
}
}.bind(this));
},
/*
* Method: enableMenuButtons
Expand All @@ -325,14 +329,30 @@ module.exports = new Class({
* Show a warning if old add-on builder helper is installed
*/
alertIfOldHelper: function() {
var response;
// run this only once per request
var that = this;
if (this.old_helper_checked) return;
if (settings.addons_helper_version && ABH()) {
response = ABH().send({cmd: 'version'});
if (!response.success || response.msg < settings.addons_helper_version) {
this.warning.alert(
'Upgrade Add-on Builder Helper',
string.substitute('There is a newer version ({addons_helper_version}) available.<br/> Please install <a href="{addons_helper}">the current one</a>.', settings));
if (!ABH().send({cmd: 'version'}).then) {
that.warning.alert(
'Upgrade Add-on Builder Helper',
string.substitute('Your version is not compatible with' +
' the Builder. <br/>There is a newer one ' +
'({addons_helper_version}) available.<br/> ' +
'Please install <a href="{addons_helper}">' +
'the current one</a>.<br/>', settings));
}
ABH().send('version').then(function (response){
that.old_helper_checked = true;
if (!response.success || response.msg < settings.addons_helper_version) {
that.warning.alert(
'Upgrade Add-on Builder Helper',
string.substitute('There is a newer version ' +
'({addons_helper_version}) available.<br/> ' +
'Please install <a href="{addons_helper}">' +
'the current one</a>.', settings));
}
});
}
},

Expand All @@ -347,8 +367,10 @@ module.exports = new Class({
return true;
}
text = text ||
string.substitute("To test this add-on, please install the <a id='install_addon_helper' href='{addons_helper}'>Add-on Builder Helper add-on</a>", settings);
title = title || "Install Add-on Builder Helper";
string.substitute('To test this add-on, please install the '+
'<a id="install_addon_helper" href="{addons_helper}">'+
'Add-on Builder Helper add-on</a>', settings);
title = title || 'Install Add-on Builder Helper';
this.warning.alert(title, text);
return false;
},
Expand Down
5 changes: 4 additions & 1 deletion settings.py
Expand Up @@ -130,6 +130,7 @@
# amo defaults
XPI_AMO_PREFIX = "ftp://ftp.mozilla.org/pub/mozilla.org/addons/"

# The lowest approved SDK available for add-ons
LOWEST_APPROVED_SDK = "1.3"
TEST_SDK = 'addon-sdk-1.3'
TEST_AMO_USERNAME = None
Expand Down Expand Up @@ -267,7 +268,9 @@ def JINJA_CONFIG():

ADDONS_HELPER_URL = ('https://addons.mozilla.org/firefox/downloads/latest/'
'182410?src=external-builder')
ADDONS_HELPER_VERSION = '1.2.2'
# desired ABH version
# Builder will display a warning if the version is lower than this number
ADDONS_HELPER_VERSION = '1.4'

TEMPLATE_DIRS = ()

Expand Down

0 comments on commit eefd0c7

Please sign in to comment.