1/* 2 * @license 3 * Your First PWA Codelab (https://g.co/codelabs/pwa) 4 * Copyright 2019 Google Inc. All rights reserved. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License 17 */ 18'use strict'; 19 20//let deferredInstallPrompt = null; 21//const installButton = document.getElementById('butInstall'); 22//installButton.addEventListener('click', installPWA); 23 24const divHeader = document.getElementById('headerx'); 25const divInstall = document.getElementById('installContainer'); 26//const divInstall = document.getElementById('btnAdd'); 27const divInstall_iOS = document.getElementById('installContainer_iOS'); 28//const butInstall = document.getElementById('butInstall'); 29 30//alert('clicou !'); 31// CODELAB: Add event listener for beforeinstallprompt event 32 33 34/** 35 * Event handler for beforeinstallprompt event. 36 * Saves the event & shows install button. 37 * 38 * @param {Event} evt 39 */ 40//function saveBeforeInstallPromptEvent(evt) { 41 // CODELAB: Add code to save event & show the install button. 42//} 43 44 45/** 46 * Event handler for butInstall - Does the PWA installation. 47 * 48 * @param {Event} evt 49 */ 50//function installPWA(evt) { 51 // CODELAB: Add code show install prompt & hide the install button. 52 53 // CODELAB: Log user response to prompt. 54//} 55 56// CODELAB: Add event listener for appinstalled event 57 58/** 59 * Event handler for appinstalled event. 60 * Log the installation to analytics or save the event somehow. 61 * 62 * @param {Event} evt 63 */ 64//function logAppInstalled(evt) { 65 // CODELAB: Add code to log the event 66 67//} 68 69let deferredPrompt; 70 71if("onbeforeinstallprompt" in window){ 72 73 window.addEventListener( "beforeinstallprompt", deferredPrompt ); 74 //console.log('ð', 'Vamos Instalar o APP?', deferredPrompt); 75} 76 77window.addEventListener('beforeinstallprompt', (e) => { 78 // Prevent Chrome 67 and earlier from automatically showing the prompt 79 e.preventDefault(); 80 // Stash the event so it can be triggered later. 81 deferredPrompt = e; 82 // Update UI notify the user they can add to home screen 83 //btnAdd.style.display = 'block'; 84 divHeader.style.display = 'block'; 85 divInstall.style.display = 'block'; 86 console.log('ð', 'Plataforma:',e.platforms); 87 gtag('event', 'view_promotion', {'event_category' : 'WEB','event_label' : 'OuvindoViaWeb'}); 88 //console.log('ð', 'Vamos Instalar o APP?', deferredPrompt); 89}); 90 91 92btnAdd.addEventListener('click', (e) => { 93 // hide our user interface that shows our A2HS button 94 btnAdd.style.display = 'none'; 95 headerx.style.display = 'none'; 96 installContainer.style.display = 'none'; 97 // Show the prompt 98 deferredPrompt.prompt(); 99 // Wait for the user to respond to the prompt 100 deferredPrompt.userChoice 101 .then((choiceResult) => { 102 if (choiceResult.outcome === 'accepted') { 103 console.log('ð', 'O Usuário Instalou o App !'); 104 divHeader.style.display = 'none'; 105 divInstall.style.display = 'none'; 106 btnAdd.style.display = 'none'; 107 headerx.style.display = 'none'; 108 installContainer.style.display = 'none'; 109 gtag('event', 'view_promotion', {'event_category' : 'APP','event_label' : 'InstalouAPP'}); 110 } else { 111 console.log('ð·', 'O Usuário NÃO Instalou o App !'); 112 btnAdd.style.display = 'block'; 113 divHeader.style.display = 'block'; 114 divInstall.style.display = 'block'; 115 } 116 deferredPrompt = null; 117 }) 118 119 .catch( function ( err ) { 120 121 if ( err.message.indexOf( "user gesture" ) > -1 ) { 122 //recycle, but make sure there is a user gesture involved 123 } else if ( err.message.indexOf( "The app is already installed" ) > -1 ) { 124 //the app is installed, no need to prompt, but you may
124need to log or update state values 125 console.log('ð', 'APP já Instalado nesse Dispositivo!', e); 126 divHeader.style.display = 'none'; 127 divInstall.style.display = 'none'; 128 btnAdd.style.display = 'none'; 129 headerx.style.display = 'none'; 130 installContainer.style.display = 'none'; 131 } else { 132 return err; 133 console.log('ð', 'Ocorreu um erro ao instalar o APP!', err); 134 } 135 136 }); 137}); 138 139window.addEventListener('appinstalled', (e) => { 140 console.log('ð', 'APP foi Instalado nesse Dispositivo!', e); 141 gtag('event', 'view_promotion', {'event_category' : 'APP','event_label' : 'AppInstalado'}); 142 divHeader.style.display = 'none'; 143 divInstall.style.display = 'none'; 144 145 //btnAdd.style.display = 'none'; 146 /* 147 //Google Analytics 148 gtag('config', 'UA-3585587-75', {'page_title' : 'APP','page_path': '/app'}); 149 var metricValue = '1'; 150 ga('set', 'metric1', metricValue); 151 ga('set', 'app', metricValue); 152 */ 153}); 154 155//Detecting with JavaScript if you app is launched from the home screen 156if (window.matchMedia('(display-mode: standalone)').matches) { 157 //console.log('display-mode is standalone'); 158 console.log('ð', 'OPA ! APP já Instalado nesse Dispositivo!'); 159 gtag('event', 'view_promotion', {'event_category' : 'APP','event_label' : 'AppInstalado'}); 160 divHeader.style.display = 'none'; 161 divInstall.style.display = 'none'; 162} 163////Detecting with JavaScript if you app is launched from the home screen - Safari 164if (window.navigator.standalone === true) { 165 //console.log('display-mode is standalone'); 166 console.log('ð', 'OPA ! APP já Instalado nesse Dispositivo!'); 167 gtag('event', 'view_promotion', {'event_category' : 'APP','event_label' : 'AppInstalado'}); 168 divHeader.style.display = 'none'; 169 divInstall.style.display = 'none'; 170} 171 172 173//Detecta se é IOS 174// Detecta se o dispositivo está no iOS 175const isIos = () => { 176 const userAgent = window.navigator.userAgent.toLowerCase(); 177 return /iphone|ipad|ipod/.test( userAgent ); 178} 179// Detects if device is in standalone mode 180const isInStandaloneMode = () => ('standalone' in window.navigator) && (window.navigator.standalone); 181// Verifica se deve exibir notificação popup de instalação: 182if (isIos() && !isInStandaloneMode()) { 183 //this.setState({ showInstallMessage: true }); 184 divHeader.style.display = 'block'; 185 divInstall.style.display = 'none'; 186 divInstall_iOS.style.display = 'block'; 187} 188 189//verifica se esta usando o celular no modo app 190if (isInStandaloneMode()) { 191 //this.setState({ showInstallMessage: true }); 192 divInstall.style.display = 'none'; 193 divInstall_iOS.style.display = 'none'; 194 gtag('event', 'view_promotion', {'event_category' : 'APP','event_label' : 'AppInstalado'}); 195} 196 197/*Scripts que não funcionaram 198//How to determine if the app was installed 199window.addEventListener('appinstalled', (event) => { 200 console.log('installed'); 201}); 202 203 const installed = function(e) { 204 promptEvent = null; 205 console.log('ð', 'OPA ! APP já Instalado nesse Dispositivo!', event); 206 divInstall.style.display = 'none'; 207 }; 208 209window.addEventListener('appinstalled', (installed) => { 210 console.log('ð', 'APP já Instalado nesse Dispositivo!', event); 211 divInstall.style.display = 'none'; 212 //btnAdd.style.display = 'none'; 213}); 214 215 216*/ 217 218 219 220 221 222 223
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.