Last active
December 30, 2015 12:59
-
-
Save digitarald/7832718 to your computer and use it in GitHub Desktop.
Move existing installations for Facebook from HTTP to HTTPS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function verifyMozAppsInstallation() { | |
| if (!navigator.mozApps || window.locationbar.visible) { | |
| // Not running as Firefox app | |
| return; | |
| } | |
| // Prevent multiple checks per day | |
| // FIXME: Use a time-limited cookie | |
| if (localStorage.mozAppsChecked) { | |
| console.log('Skipped verifyMozAppsInstallation'); | |
| return; | |
| } | |
| localStorage.mozAppsChecked = true; | |
| var showHint = function() { | |
| // FIXME: Make a better UX and wordsmith this | |
| var confirmed = window.prompt('A Facebook update is available. Do you want to install it now?'); | |
| if (!confirmed) { | |
| return; | |
| } | |
| // Option A - Open Marketplace | |
| new MozActivity({ | |
| name: 'marketplace-app', | |
| data: { | |
| slug: 'facebook-1' | |
| } | |
| }); | |
| // xor Option B - Install from FB | |
| var request = navigator.mozApps.install('https://m.facebook.com/openwebapp/manifest.webapp'); | |
| request.onsuccess = function() { | |
| if (!request.result) { | |
| return; | |
| } | |
| // FIXME: Tell user to delete the old icon | |
| request.result.launch(); | |
| }; | |
| }; | |
| // Check if current origin is installed | |
| var request = navigator.mozApps.getSelf(); | |
| request.onsuccess = function() { | |
| // Not installed | |
| if (!request.result) { | |
| showHint(); | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment