Skip to content
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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4af0719
WIP: beforeinstallprompt
marcoscaceres Oct 13, 2016
58d8ba8
Add BIP JS implementation
marcoscaceres Oct 19, 2016
be3a60c
Using Matt's suggested var names
marcoscaceres Oct 19, 2016
6217a17
Make spec match ref implementation
marcoscaceres Oct 20, 2016
1e8b410
Add example
marcoscaceres Oct 20, 2016
366fd5b
Add example
marcoscaceres Oct 20, 2016
8626382
Dont await prompt
marcoscaceres Oct 20, 2016
7feafc2
move onbeforeinstallprompt to match IDL
marcoscaceres Oct 20, 2016
0e51b64
Add rejection of userChoice on error
marcoscaceres Oct 20, 2016
0ac6715
Add completely loaded from HTML5
marcoscaceres Oct 20, 2016
d25fadf
Markup fixes
marcoscaceres Oct 20, 2016
128edcf
Fix if/else error behavior
marcoscaceres Oct 20, 2016
4517699
Fixes based on discussion
marcoscaceres Oct 20, 2016
556e8de
Fixup implementations and tests based on mgiuca feedback
marcoscaceres Oct 20, 2016
0c5a224
fixes based on @mgiuca's feedback
marcoscaceres Oct 21, 2016
9663d86
Fixup based on feedback
marcoscaceres Oct 23, 2016
ea98a82
Linking and cleanup
marcoscaceres Oct 23, 2016
7802c95
Fixed heading, as suggeted by @kenchris
marcoscaceres Oct 23, 2016
b6e5043
cross ref construct a BeforeInstallPromptEvent
marcoscaceres Oct 23, 2016
38a2bab
MUST instead of SHOULD
marcoscaceres Oct 23, 2016
561182b
MUST instead of SHOULD
marcoscaceres Oct 23, 2016
5f65182
Fixed typo
marcoscaceres Oct 23, 2016
7e10680
Fixup based on recent comments
marcoscaceres Oct 24, 2016
8f89507
fixes(bip implementation): based on feedback
marcoscaceres Oct 24, 2016
2f86eb6
nits from @kenchris
marcoscaceres Oct 24, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 19 additions & 10 deletions implementation/BeforeInstallPromptEvent.js
@@ -1,6 +1,5 @@
/*globals DOMException*/
Copy link
Collaborator

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?

"use strict";
{
"use strict"; {
const internalSlots = new WeakMap();
const installProcesses = [];
const AppBannerPromptOutcome = new Set([
Expand All @@ -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.
*
Expand All @@ -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` +
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.
Expand Down Expand Up @@ -83,8 +92,8 @@
}

async function notifyBeforeInstallPrompt(element) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about calling this simulateBeforeInstallPrompt?

(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.)

Copy link
Member Author

Choose a reason for hiding this comment

The 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 @see link to the code.

if (document.readyState === "complete") {
await trackReadyState();
if (document.readyState !== "complete") {
await waitUntilReadyStateComplete();
}
if (installProcesses.length) {
return;
Expand All @@ -96,8 +105,8 @@
}
}

function trackReadyState() {
return new Promise((resolve) => {
function waitUntilReadyStateComplete() {
return new Promise(resolve => {
document.addEventListener("readystatechange", () => {
if (document.readyState === "complete") {
resolve();
Expand Down Expand Up @@ -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);
Expand All @@ -143,7 +152,7 @@
return p;
}

if(!window.BeforeInstallPromptEvent) {
if (!window.BeforeInstallPromptEvent) {
window.BeforeInstallPromptEvent = BeforeInstallPromptEvent;
} else {
console.warn("Using browser's implementation of BeforeInstallPromptEvent.");
Expand Down