Skip to content

Commit

Permalink
fix dat timer, add service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephShepin committed Apr 17, 2022
1 parent efc7416 commit 7424369
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
27 changes: 27 additions & 0 deletions public/service-workers/service-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint-disable no-restricted-globals */
/* eslint-disable no-undef */
/* eslint-disable consistent-return */

self.addEventListener('install', () => {
self.skipWaiting();
});

// Handle notification clicks (using a service worker because android requires use of service workers for notifications)
// Modified from https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event
self.addEventListener('notificationclick', (event) => {
if (event.notification.tag === 'timer') {
event.notification.close();

// This looks to see if the current is already open and focuses if it is
event.waitUntil(clients.matchAll({ type: 'window' }).then((clientList) => {
for (let i = 0; i < clientList.length; i++) {
const client = clientList[i];
if (new URL(client.url).pathname === '/tools' && 'focus' in client) {
client.postMessage('stop-timer-done-audio');
return client.focus();
}
}
if (clients.openWindow) return clients.openWindow('/tools');
}));
}
});
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import App from './App.vue';
import router from './router';
import store from './store';

if (navigator.serviceWorker) {
navigator.serviceWorker.register('/service-workers/service-worker.js');
}

createApp(App).component('font-awesome-icon', FontAwesomeIcon)
.use(store)
.use(router)
Expand Down
2 changes: 1 addition & 1 deletion src/views/Calendar/Calendar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<!-- <div // FIX
<!-- <div // FIX?
v-hammer:swipe.horizontal="onSwipe"
v-focus
tabindex="-1"
Expand Down
2 changes: 1 addition & 1 deletion src/views/Tools/TimerCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="slash" :class="{ hide: shouldMakeSound }" />
</div>
<div class="title">Timer</div>
<div @click="isFullscreen ? exitFullscreen : makeFullscreen" class="icon-button">
<div @click="isFullscreen ? exitFullscreen() : makeFullscreen()" class="icon-button">
<font-awesome-icon class="icon" :icon="isFullscreen ? icons.faCompress : icons.faExpand" fixed-width />
</div>
</div>
Expand Down

0 comments on commit 7424369

Please sign in to comment.