import React from 'react' import PropTypes from 'prop-types' import Button from '../button' import Text from '../text' class PWAInjection extends React.PureComponent { deferredPrompt=null componentDidMount() { window.addEventListener('beforeinstallprompt',(e) => { console.log("e:",e) // Prevent the mini-infobar from appearing on mobile e.preventDefault() // Stash the event so it can be triggered later. this.deferredPrompt=e // Update UI notify the user they can install the PWA // showInstallPromotion() }) window.addEventListener('appinstalled',(evt) => { // Log install to analytics console.log('INSTALL: Success') }) window.addEventListener('DOMContentLoaded',() => { let displayMode='browser tab' if(navigator.standalone) { displayMode='standalone-ios' } if(window.matchMedia('(display-mode: standalone)').matches) { displayMode='standalone' } // Log launch display mode to analytics console.log('DISPLAY_MODE_LAUNCH:',displayMode) window.matchMedia('(display-mode: standalone)').addListener((evt) => { let displayMode='browser tab'; if(evt.matches) { displayMode='standalone'; } // Log display mode change to analytics console.log('DISPLAY_MODE_CHANGED',displayMode); }); }) } handleOnClick=() => { // Hide the app provided install promotion // hideMyInstallPromotion() // Show the install prompt this.deferredPrompt.prompt() // Wait for the user to respond to the prompt this.deferredPrompt.userChoice.then((choiceResult) => { if(choiceResult.outcome==='accepted') { console.log('User accepted the install prompt') } else { console.log('User dismissed the install prompt') } }) } render() { // : todo : return
return (
We’re not on the app stores, but you can still get the Gab app on your phone. Click install to learn how.
) } } PWAInjection.propTypes = { injectionId: PropTypes.string, isXS: PropTypes.string, } export default PWAInjection