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

Fix #75: Implement web app installing #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed app-icon.png
Binary file not shown.
Binary file removed favicon.ico
Binary file not shown.
Binary file added icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon-512x512.png
Copy link
Collaborator

Choose a reason for hiding this comment

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<!-- Origin trial token needed for Web USB -->
<meta http-equiv="origin-trial" content="AsxscPRBb7U1KJIlQrsFrZ3ea0LHwRhNkbqBKsSuLP5y3sqIqnanjKbGk4oe5+/HkownaJhI2wP6m1S70Y8xkQsAAABUeyJvcmlnaW4iOiAiaHR0cHM6Ly9wZXJtaXNzaW9uLnNpdGU6NDQzIiwgImZlYXR1cmUiOiAiV2ViVVNCIiwgImV4cGlyeSI6IDE0NjUzODkxOTd9">
<title>permission.site</title>
<link rel="shortcut icon" href="favicon.ico">
<link rel="apple-touch-icon" href="app-icon.png"/>
<link rel="shortcut icon" href="icon-512x512.png">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why replace favicon.ico? The existing favicon is sized specifically arranged for low resolution.

<link rel="apple-touch-icon" href="icon-512x512.png">
<link rel="manifest" href="manifest.json">
<link rel="stylesheet" href="style.css">
<script src="index.js"></script>
</head>
Expand All @@ -32,6 +33,7 @@
</a>
</div>

<button id="install">Install</button>
<button id="notifications">Notifications</button>
<button id="location">Location</button>
<button id="camera">Camera</button>
Expand Down Expand Up @@ -98,7 +100,7 @@
<tr>
<td>Async Clipboard</td>
<td>
These buttons test the new <a href="https://w3c.github.io/clipboard-apis/">Async Clipboard API</a>.
These buttons test the new <a href="https://w3c.github.io/clipboard-apis/" target="_blank">Async Clipboard API</a>.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change is not related to the rest of the PR. I'd suggest making a separate PR for this.

<br>
Note that these tests are different from the "Copy" button on this page, which uses the old
(synchronous) <code>execCommand</code> method to write to the clipboard.
Expand All @@ -123,6 +125,15 @@
May succeed without permission request depending on the implementation.
</td>
</tr>
<tr>
<td>Notifications</td>
<td>
On iOS and iPadOS, to request notification permission, web apps must first be added to the Home Screen.
<br>
In Meta Quest Browser, to request notification permission, web apps must be
<a href="https://web.dev/pwas-on-oculus-2/#packaging-pwas-with-pwabuilder" target="_blank">packaged</a>.
</td>
</tr>
</table>

</div>
Expand Down
30 changes: 30 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
// - Indicate if permissions are already granted, if the relevant API allows it.

window.addEventListener("load", function() {
var deferredInstallEvent;

window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
deferredInstallEvent = event;
});

window.addEventListener("appinstalled", (event) => {
displayOutcome("install", "success")();
});

var toggle = document.querySelector("#toggle");
toggle.classList.add("instant");
Expand Down Expand Up @@ -93,6 +103,26 @@ window.addEventListener("load", function() {
);

var register = {
"install": function() {
if ("BeforeInstallPromptEvent" in window) {
if (deferredInstallEvent) {
deferredInstallEvent.prompt();
deferredInstallEvent.userChoice
.then((choiceResult) => {
if (choiceResult.outcome === "accepted") {
displayOutcome("install", "success")();
}
// If install prompt is dismissed, closed or ignored, it can be requested again.
})
.catch((error) => {
displayOutcome("install", "error")(error);
});
deferredInstallEvent = null;
}
} else {
displayOutcome("install", "error")("Install is not supported");
}
},
"notifications": function () {
Notification.requestPermission(
displayOutcomeForNotifications
Expand Down
81 changes: 81 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "permission.site",
"short_name": "permission.site",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should be a real description. I think the GitHub project description would be good:

A site to test the interaction of web APIs and browser permissions.

"start_url": "./?utm_source=web_app_manifest",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason we need to use URLs with web tracking parameters?

Suggested change
"start_url": "./?utm_source=web_app_manifest",
"start_url": "./",

(If there is a good reason, that should probably be documented.)

"scope": "./",
"display": "standalone",
"theme_color": "#eeeeee",
"background_color": "#eeeeee",
"icons": [
{
"src": "./icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "./icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "./icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "./icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"screenshots": [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please move the screenshots into their own folder to avoid having too many files in the root directory?

{
"src": "./screenshot-1.png",
"type": "image/png",
"sizes": "1080x1920",
"form_factor": "narrow"
},
{
"src": "./screenshot-2.png",
"type": "image/png",
"sizes": "1080x1920",
"form_factor": "narrow"
},
{
"src": "./screenshot-3.png",
"type": "image/png",
"sizes": "1080x1920",
"form_factor": "narrow"
},
{
"src": "./screenshot-4.png",
"type": "image/png",
"sizes": "1920x1080",
"form_factor": "wide"
},
{
"src": "./screenshot-5.png",
"type": "image/png",
"sizes": "1920x1080",
"form_factor": "wide"
},
{
"src": "./screenshot-6.png",
"type": "image/png",
"sizes": "1920x1080",
"form_factor": "wide"
}
],
"prefer_related_applications": false,
"related_applications": [
{
"platform": "webapp",
"url": "./manifest.json"
}
]
}
4 changes: 2 additions & 2 deletions one-time.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<title>permission.site (one-time)</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="apple-touch-icon" href="app-icon.png" />
<link rel="shortcut icon" href="icon-512x512.png">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as the main page shortcut icon.

<link rel="apple-touch-icon" href="icon-512x512.png">
<link rel="stylesheet" href="style.css" />
<script src="one-time.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions other-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=0.6" />
<title>permission.site</title>
<link rel="shortcut icon" href="favicon.ico" />
<link rel="apple-touch-icon" href="app-icon.png" />
<link rel="shortcut icon" href="icon-512x512.png">
Copy link
Collaborator

@lgarron lgarron Jul 28, 2023

Choose a reason for hiding this comment

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

Also same as the main page shortcut icon.

<link rel="apple-touch-icon" href="icon-512x512.png">
<link rel="stylesheet" href="style.css" />
</head>
<body>
Expand Down
Binary file added screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshot-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.