Skip to content

Commit 0c369b8

Browse files
tomayacPaulKinlan
authored andcommitted
Add a badge that counts honks (#50)
* Add a badge that counts honks * Calculate isInstalled inline * Remove "is installed" tests Following @mgiuca's advice (*"if it works it works, if not it doesn't?"*).
1 parent 8aa08f6 commit 0c369b8

File tree

4 files changed

+166
-11
lines changed

4 files changed

+166
-11
lines changed

app/scripts/main.min.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const Horn = function() {
5353
callback(buffer);
5454
return;
5555
}
56-
56+
5757
const xhr = new XMLHttpRequest();
5858

5959
xhr.onload = function() {
@@ -129,7 +129,7 @@ const Installer = function(root) {
129129
promptEvent.userChoice
130130
.then(function(choiceResult) {
131131
// The user actioned the prompt (good or bad).
132-
// good is handled in
132+
// good is handled in
133133
promptEvent = null;
134134
ga('send', 'event', 'install', choiceResult);
135135
root.classList.remove('available');
@@ -171,6 +171,13 @@ const AirHorn = function(root) {
171171
const airhornImage = root.querySelector('.horn');
172172
const horn = new Horn();
173173

174+
// Reset badge upon each relaunch
175+
const badge = window.Badge || window.ExperimentalBadge;
176+
if (badge) {
177+
badge.clear();
178+
}
179+
let counter = 0;
180+
174181
const start = function(e) {
175182
if (!!e == true) {
176183
if(supportsPassive == false) e.preventDefault();
@@ -195,6 +202,14 @@ const AirHorn = function(root) {
195202
airhornImage.setAttribute('aria-pressed', 'true');
196203
horn.start(opts);
197204

205+
// Counter counts honks up until 99, then resets to 0
206+
if (badge) {
207+
if (counter === 99) {
208+
counter = 0;
209+
}
210+
badge.set(++counter);
211+
}
212+
198213
horn.onstopped = function() {
199214
airhornImage.classList.remove('horning');
200215
airhornImage.setAttribute('aria-pressed', 'false');

app/sw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
*/
1919

20-
const version = "0.6.16";
20+
const version = "0.6.17";
2121
const cacheName = `airhorner-${version}`;
2222
self.addEventListener('install', e => {
2323
e.waitUntil(

package-lock.json

Lines changed: 145 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dependencies": {
3030
"comlink": "^3.2.0",
3131
"gulp-rollup": "^2.16.2",
32+
"http-server": "^0.11.1",
3233
"rollup": "^1.9.0",
3334
"rollup-plugin-terser": "^4.0.4",
3435
"serve": "^10.1.2"
@@ -39,7 +40,8 @@
3940
]
4041
},
4142
"scripts": {
42-
"build": "gulp"
43+
"build": "gulp",
44+
"start": "npm run build && http-server dist/"
4345
},
4446
"repository": {
4547
"type": "git",

0 commit comments

Comments
 (0)