New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: beforeinstallprompt #506
Changes from 1 commit
4af0719
58d8ba8
be3a60c
6217a17
1e8b410
366fd5b
8626382
7feafc2
0e51b64
0ac6715
d25fadf
128edcf
4517699
556e8de
0c5a224
9663d86
ea98a82
7802c95
b6e5043
38a2bab
561182b
5f65182
7e10680
8f89507
2f86eb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
/*globals DOMException*/ | ||
"use strict"; | ||
{ | ||
"use strict"; { | ||
const internalSlots = new WeakMap(); | ||
const installProcesses = []; | ||
const AppBannerPromptOutcome = new Set([ | ||
|
@@ -21,6 +20,16 @@ | |
internal.userChoiceResolver(promptOutcome); | ||
} | ||
|
||
function hasValidUserChoice({ userChoice }) { | ||
if (typeof userChoice === "undefined") { | ||
return true; | ||
} | ||
if (!AppBannerPromptOutcome.has(String(userChoice))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Implementation of BeforeInstallPromptEvent. | ||
* | ||
|
@@ -38,9 +47,9 @@ | |
} | ||
super(typeArg, Object.assign({ cancelable: true }, eventInit)); | ||
|
||
if (eventInit && typeof eventInit.userChoice !== "undefined" && !AppBannerPromptOutcome.has(String(eventInit.userChoice))) { | ||
if (eventInit && !hasValidUserChoice(eventInit)) { | ||
const msg = `The provided value '${eventInit.userChoice}' is not a valid` + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ` works for multiline |
||
"enum value of type AppBannerPromptOutcome."; | ||
" enum value of type AppBannerPromptOutcome."; | ||
throw new TypeError(msg); | ||
} | ||
// End WebIDL guard. | ||
|
@@ -83,8 +92,8 @@ | |
} | ||
|
||
async function notifyBeforeInstallPrompt(element) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about calling this (Since it is not part of the BIP API surface, it's just used by the buttons on the test page to simulate an action the UA normally takes.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is supposed to match "the steps to notify before an automated install" - which is why I named it as such (admittedly, not the best name). I'll add a |
||
if (document.readyState === "complete") { | ||
await trackReadyState(); | ||
if (document.readyState !== "complete") { | ||
await waitUntilReadyStateComplete(); | ||
} | ||
if (installProcesses.length) { | ||
return; | ||
|
@@ -96,8 +105,8 @@ | |
} | ||
} | ||
|
||
function trackReadyState() { | ||
return new Promise((resolve) => { | ||
function waitUntilReadyStateComplete() { | ||
return new Promise(resolve => { | ||
document.addEventListener("readystatechange", () => { | ||
if (document.readyState === "complete") { | ||
resolve(); | ||
|
@@ -125,7 +134,7 @@ | |
const p = new Promise((resolve) => { | ||
add.addEventListener("click", () => { | ||
resolve("accepted"); | ||
//emulate installation to home screen | ||
// Emulate installation to home screen | ||
setTimeout(() => { | ||
window.dispatchEvent(new Event("appinstalled")); | ||
}, 1000); | ||
|
@@ -143,7 +152,7 @@ | |
return p; | ||
} | ||
|
||
if(!window.BeforeInstallPromptEvent) { | ||
if (!window.BeforeInstallPromptEvent) { | ||
window.BeforeInstallPromptEvent = BeforeInstallPromptEvent; | ||
} else { | ||
console.warn("Using browser's implementation of BeforeInstallPromptEvent."); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this file be called *Polyfill.js or similar?