Skip to content

Commit ed95e2c

Browse files
authored
Update helloworld-pwa.html
1 parent 2ec6b39 commit ed95e2c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

1.hello-world/10.read-video-pwa/helloworld-pwa.html

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,21 @@ <h1 style="font-size: 1.5em;">Hello World for PWA</h1>
3030

3131
let pScanner = null;
3232
let latestResult = null;
33-
window.onload = async function() {
33+
34+
function startNotificationLoop() {
35+
if (latestResult != null) {
36+
const title = "New Barcode Found!";
37+
const notifBody = `Barcode Text: ${latestResult}.`;
38+
const options = {
39+
body: notifBody,
40+
};
41+
new Notification(title, options);
42+
latestResult = null;
43+
}
44+
setTimeout(startNotificationLoop, 100);
45+
}
46+
47+
(async function() {
3448
Notification.requestPermission().then((result) => {
3549
if (result === 'granted') {
3650
startNotificationLoop();
@@ -52,24 +66,12 @@ <h1 style="font-size: 1.5em;">Hello World for PWA</h1>
5266
alert(ex.message);
5367
throw ex;
5468
}
55-
};
56-
57-
function startNotificationLoop() {
58-
if (latestResult != null) {
59-
const title = "New Barcode Found!";
60-
const notifBody = `Barcode Text: ${latestResult}.`;
61-
const options = {
62-
body: notifBody,
63-
};
64-
new Notification(title, options);
65-
latestResult = null;
66-
}
67-
setTimeout(startNotificationLoop, 100);
68-
}
69+
})();
70+
6971
if ('serviceWorker' in navigator) {
7072
navigator.serviceWorker.register('./service-worker.js');
7173
};
7274
</script>
7375
</body>
7476

75-
</html>
77+
</html>

0 commit comments

Comments
 (0)