-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b319375
commit d1c3063
Showing
13 changed files
with
148 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// installPrompt.js | ||
|
||
let deferredPrompt; | ||
|
||
window.addEventListener('beforeinstallprompt', (e) => { | ||
// Prevent the mini-infobar from appearing on mobile | ||
e.preventDefault(); | ||
// Stash the event so it can be triggered later | ||
deferredPrompt = e; | ||
// Update UI notify the user they can install the PWA | ||
const installButton = document.getElementById('installButton'); | ||
installButton.style.display = 'block'; | ||
|
||
installButton.addEventListener('click', () => { | ||
// Hide the install button | ||
installButton.style.display = 'none'; | ||
// Show the install prompt | ||
deferredPrompt.prompt(); | ||
// Wait for the user to respond to the prompt | ||
deferredPrompt.userChoice.then((choiceResult) => { | ||
if (choiceResult.outcome === 'accepted') { | ||
console.log('User accepted the install prompt'); | ||
} else { | ||
console.log('User dismissed the install prompt'); | ||
} | ||
deferredPrompt = null; | ||
}); | ||
}); | ||
}); | ||
|
||
window.addEventListener('appinstalled', () => { | ||
// Log install to analytics | ||
console.log('PWA was installed'); | ||
}); |
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.