function awaitInstallPrompt(onPrompt) {
	if (!CACHE.installPromptListener) {
		let window = getWindow();
		if (!window || isStandalone()) return null;
		CACHE.installPromptListener = e => {
			e.preventDefault();
			let installPrompt = e;
			CACHE.prompt = () =>  new Promise(resolve => {
				CACHE.appInstalledListener = () => {
					resolve(true);
				};
				window.addEventListener('appinstalled', CACHE.appInstalledListener);
				installPrompt.prompt();
				installPrompt.userChoice.then(choiceResult => {
					choiceResult.outcome !== 'accepted' && resolve(false);
				});
			}).then(success => {
				installPrompt = null;
				CACHE.appInstalledListener && window.removeEventListener('appinstalled', CACHE.appInstalledListener);
				if (success) {
					CACHE.prompt = null;
					dispatchToOnPrompt();
				}
				return success;
			});
			dispatchToOnPrompt();
		};
		window.addEventListener('beforeinstallprompt', CACHE.installPromptListener);
	}
	if (onPrompt) {
		CACHE.onPrompts.push(onPrompt);
		CACHE.prompt && onPrompt(CACHE.prompt);
		return () => removeOnPrompt(onPrompt);
	}
	return () => reset();
}
/**
 * This function allows you to listen to the browser for the install prompt
 * that allows you to install the application standalone.
 *
 * Different browsers have different criteria for when this prompt is made available.
 * Currently Chrome requires that  the user "interact" with the content on your domain
 * for at least 30 seconds.
 *
 * More info can be found here:
 * https://developers.google.com/web/fundamentals/app-install-banners/
 *
 * awaitInstallPrompt offers the following capabilities:
 * * Listen to the browser for an install prompt.
 * * Stop listening at any time.
 * * Trigger the prompt to request app installation.
 *
 * @param {Function} onPrompt (prompt, cancel) => {} A function that will be called when
 * the browser delivers a prompt that we can present. The first argument prompt is a function
 * you can call at any time the triggers the install process. cancel is another function
 * that allows you to stop listening for prompts.
 *
 * @returns {Function} An function that when called, will stop listening for incoming prompts from the browser.
 *
 * @example
 * let cancel = awaitInstallPrompt((prompt) => {
 *      prompt().then(
 *          success => console.log(
 *              success && 'Successfully installed app as PWA.'
 *                      || 'User abandoned install.'
 *          )
 *      )
 * })
 */
This function allows you to listen to the browser for the install prompt
that allows you to install the application standalone.

Different browsers have different criteria for when this prompt is made available.
Currently Chrome requires that  the user "interact" with the content on your domain
for at least 30 seconds.



awaitInstallPrompt offers the following capabilities:
Listen to the browser for an install prompt.
Stop listening at any time.
Trigger the prompt to request app installation.

@param {Function} onPrompt (prompt, cancel) => {} A function that will be called when
the browser delivers a prompt that we can present. The first argument prompt is a function
you can call at any time the triggers the install process. cancel is another function
that allows you to stop listening for prompts.

@returns {Function} An function that when called, will stop listening for incoming prompts from the browser.

@example
let cancel = awaitInstallPrompt((prompt) => {
prompt().then(
success => console.log(
success && 'Successfully installed app as PWA.'
|| 'User abandoned install.'
)
)
})
This function allows you to listen to the browser for the install prompt that allows you to install the application standalone . Different browsers have different criteria for when this prompt is made available . Currently Chrome requires that the user " interact " with the content on your domain for at least 30 seconds . awaitInstallPrompt offers the following capabilities : Listen to the browser for an install prompt . Stop listening at any time . Trigger the prompt to request app installation . @param { Function } onPrompt ( prompt cancel ) = > {} A function that will be called when the browser delivers a prompt that we can present . The first argument prompt is a function you can call at any time the triggers the install process . cancel is another function that allows you to stop listening for prompts . @returns { Function } An function that when called will stop listening for incoming prompts from the browser . @example let cancel = awaitInstallPrompt (( prompt ) = > { prompt () . then ( success = > console . log ( success && ' Successfully installed app as PWA . ' || ' User abandoned install . ' ) ) } )
function awaitInstallPrompt(onPrompt) {
	if (!CACHE.installPromptListener) {
		let window = getWindow();
		if (!window || isStandalone()) return null;
		CACHE.installPromptListener = e => {
			e.preventDefault();
			let installPrompt = e;
			CACHE.prompt = () =>  new Promise(resolve => {
				CACHE.appInstalledListener = () => {
					resolve(true);
				};
				window.addEventListener('appinstalled', CACHE.appInstalledListener);
				installPrompt.prompt();
				installPrompt.userChoice.then(choiceResult => {
					choiceResult.outcome !== 'accepted' && resolve(false);
				});
			}).then(success => {
				installPrompt = null;
				CACHE.appInstalledListener && window.removeEventListener('appinstalled', CACHE.appInstalledListener);
				if (success) {
					CACHE.prompt = null;
					dispatchToOnPrompt();
				}
				return success;
			});
			dispatchToOnPrompt();
		};
		window.addEventListener('beforeinstallprompt', CACHE.installPromptListener);
	}
	if (onPrompt) {
		CACHE.onPrompts.push(onPrompt);
		CACHE.prompt && onPrompt(CACHE.prompt);
		return () => removeOnPrompt(onPrompt);
	}
	return () => reset();
}
function awaitInstallPrompt ( onPrompt ) { if ( ! CACHE . installPromptListener ) { let window = getWindow ( ) ; if ( ! window || isStandalone ( ) ) return null ; CACHE . installPromptListener = e => { e . preventDefault ( ) ; let installPrompt = e ; CACHE . prompt = ( ) => new Promise ( resolve => { CACHE . appInstalledListener = ( ) => { resolve ( true ) ; } ; window . addEventListener ( 'appinstalled' , CACHE . appInstalledListener ) ; installPrompt . prompt ( ) ; installPrompt . userChoice . then ( choiceResult => { choiceResult . outcome !== 'accepted' && resolve ( false ) ; } ) ; } ) . then ( success => { installPrompt = null ; CACHE . appInstalledListener && window . removeEventListener ( 'appinstalled' , CACHE . appInstalledListener ) ; if ( success ) { CACHE . prompt = null ; dispatchToOnPrompt ( ) ; } return success ; } ) ; dispatchToOnPrompt ( ) ; } ; window . addEventListener ( 'beforeinstallprompt' , CACHE . installPromptListener ) ; } if ( onPrompt ) { CACHE . onPrompts . push ( onPrompt ) ; CACHE . prompt && onPrompt ( CACHE . prompt ) ; return ( ) => removeOnPrompt ( onPrompt ) ; } return ( ) => reset ( ) ; }
This function allows you to listen to the browser for the install prompt
 that allows you to install the application standalone.
This function allows you to listen to the browser for the install prompt that allows you to install the application standalone .