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 20let deferredInstallPrompt = null; 21//const installButton = document.getElementById('butInstall'); 22//const installButton = document.getElementById('butInstall'); 23//installButton.addEventListener('click', installPWA); 24 25// CODELAB: Add event listener for beforeinstallprompt event 26window.addEventListener('beforeinstallprompt', saveBeforeInstallPromptEvent); 27 28 29function saveBeforeInstallPromptEvent(evt) { 30 // CODELAB: Add code to save event & show the install button. 31 deferredInstallPrompt = evt; 32 //installButton.removeAttribute('hidden'); 33} 34 35 36 37function installPWA(evt) { 38 // CODELAB: Add code show install prompt & hide the install button. 39 deferredInstallPrompt.prompt(); 40 // Hide the install button, it can't be called twice. 41 evt.srcElement.setAttribute('hidden', true); 42 // CODELAB: Log user response to prompt. 43 deferredInstallPrompt.userChoice 44 .then((choice) => { 45 if (choice.outcome === 'accepted') { 46 console.log('User accepted the A2HS prompt', choice); 47 } else { 48 console.log('User dismissed the A2HS prompt', choice); 49 } 50 deferredInstallPrompt = null; 51 }); 52} 53 54// CODELAB: Add event listener for appinstalled event 55window.addEventListener('appinstalled', logAppInstalled); 56 57function logAppInstalled(evt) { 58 // CODELAB: Add code to log the event 59 console.log('Weather App was installed.', evt); 60}
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.