1. notification via SW 2.manifest json for home screen app 3. icons for mobile/desktop shortcut app
This commit is contained in:
parent
44dd4e9562
commit
2087c2897f
19 changed files with 217 additions and 51 deletions
45
src/App.vue
45
src/App.vue
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
<script>
|
||||
import stickers from "./plugins/stickers";
|
||||
import logoMixin from "./components/logoMixin";
|
||||
import { notificationCount } from "./plugins/notificationAndServiceWorker.js"
|
||||
|
||||
export default {
|
||||
name: "App",
|
||||
|
|
@ -42,7 +42,6 @@ export default {
|
|||
availableJsonTranslation: null
|
||||
}
|
||||
},
|
||||
mixins: [logoMixin],
|
||||
beforeMount() {
|
||||
this.setDefaultLanguage();
|
||||
},
|
||||
|
|
@ -113,43 +112,10 @@ export default {
|
|||
|
||||
// Set language
|
||||
this.$i18n.locale = this.$store.state.language || "en";
|
||||
},
|
||||
showNotification() {
|
||||
if(document.visibilityState === "visible") {
|
||||
return;
|
||||
}
|
||||
const title = this.$t('notification.title');
|
||||
const notification = new Notification(title, {icon: this.logotype});
|
||||
notification.onclick = () => {
|
||||
notification.close();
|
||||
window.parent.focus();
|
||||
}
|
||||
},
|
||||
requestAndShowPermission(notificationCount) {
|
||||
Notification.requestPermission(function (permission) {
|
||||
if(notificationCount > 0 && permission === "granted") {
|
||||
this.showNotification();
|
||||
}
|
||||
});
|
||||
},
|
||||
requestNotificationPermission(notificationCount) {
|
||||
if ('Notification' in window) {
|
||||
Notification.requestPermission().then((permission) => {
|
||||
if(notificationCount > 0 && permission === 'granted') {
|
||||
this.showNotification();
|
||||
} else if(permission === "default") {
|
||||
this.requestAndShowPermission(notificationCount);
|
||||
} else {
|
||||
this.requestAndShowPermission(notificationCount);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
notificationCount() {
|
||||
return this.$matrix.notificationCount
|
||||
},
|
||||
notificationCount,
|
||||
currentUser() {
|
||||
return this.$store.state.auth.user;
|
||||
},
|
||||
|
|
@ -217,13 +183,8 @@ export default {
|
|||
document.getElementById("favicon").setAttribute('href', favicon);
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
notificationCount: {
|
||||
handler(nCount) {
|
||||
this.requestNotificationPermission(nCount)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue