Skip to content

Commit

Permalink
Merge pull request #4266 from alexgibson/bug-1274207-only-show-refres…
Browse files Browse the repository at this point in the history
…h-button-if-supported

[fix bug 1274207] Download page should only show 'Refresh Firefox' button if reset is supported
  • Loading branch information
jpetto committed Aug 18, 2016
2 parents 97d9f5d + cf99193 commit 83795e0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
19 changes: 18 additions & 1 deletion docs/uitour.rst
Expand Up @@ -285,6 +285,7 @@ Available ``type`` values:
* ``'selectedSearchEngine'``
* ``'search'``
* ``'loop'``
* ``'canReset'``

Other parameters:

Expand Down Expand Up @@ -380,6 +381,20 @@ If ``'loop'`` is queried the object returns the boolean value for the ``'loop.ge

``loop`` is only available in Firefox 36 onward.

**canReset**

If ``'canReset'`` is queried the callback returns a boolean value to indicate if a user can refresh their Firefox profile via ``resetFirefox()``

.. code-block:: javascript
Mozilla.UITour.getConfiguration('canReset', function (canReset) {
console.log(canReset); // true
});
.. Important::

``canReset`` is only available in Firefox 48 onward.

setConfiguration(name, value);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -467,7 +482,9 @@ Opens the Firefox reset panel, allowing users to choose to reomve add-ons and cu
.. Important::

``showFirefoxAccounts()`` is only available in Firefox 35 onward.
``resetFirefox()`` should be called only in Firefox 48 onwards, and only after
first calling ``getConfiguration('canReset')`` to determine if the user profile
is eligible.

addNavBarWidget(target, callback);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
37 changes: 33 additions & 4 deletions media/js/firefox/new/scene1.js
Expand Up @@ -21,6 +21,35 @@
document.dispatchEvent(event);
};

var uiTourWaitForCallback = function(callback) {
var id = Math.random().toString(36).replace(/[^a-z]+/g, '');

function listener(event) {
if (typeof event.detail != 'object') {
return;
}
if (event.detail.callbackID !== id) {
return;
}

document.removeEventListener('mozUITourResponse', listener);
callback(event.detail.data);
}
document.addEventListener('mozUITourResponse', listener);

return id;
};

var showRefreshButton = function(canReset) {
if (canReset) {
$html.addClass('show-refresh');

$('#refresh-firefox').on('click', function() {
uiTourSendEvent('resetFirefox');
});
}
};

if (client.isFirefoxDesktop ||client.isFirefoxAndroid) {
// Detect whether the Firefox is up-to-date in a non-strict way. The minor version and channel are not
// considered. This can/should be strict, once the UX especially for ESR users is decided. (Bug 939470)
Expand All @@ -32,10 +61,10 @@
client.getFirefoxDetails(function(data) {
// data.accurate will only be true if UITour API is working.
if (data.channel === 'release' && data.isUpToDate && data.accurate) {
$html.addClass('show-refresh');

$('#refresh-firefox').on('click', function() {
uiTourSendEvent('resetFirefox');
// Bug 1274207 only show reset button if user profile supports it.
uiTourSendEvent('getConfiguration', {
callbackID: uiTourWaitForCallback(showRefreshButton),
configuration: 'canReset'
});
}
});
Expand Down

0 comments on commit 83795e0

Please sign in to comment.