Browser notification
This commit is contained in:
parent
fce65d1a3b
commit
ecf86661fe
2 changed files with 46 additions and 2 deletions
45
src/App.vue
45
src/App.vue
|
|
@ -111,9 +111,45 @@ export default {
|
||||||
|
|
||||||
// Set language
|
// Set language
|
||||||
this.$i18n.locale = this.$store.state.language || "en";
|
this.$i18n.locale = this.$store.state.language || "en";
|
||||||
|
},
|
||||||
|
|
||||||
|
// Request notification permission
|
||||||
|
showNotification() {
|
||||||
|
if(document.visibilityState === "visible") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const title = this.$t('notification.title');
|
||||||
|
const notification = new Notification(title);
|
||||||
|
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: {
|
computed: {
|
||||||
|
notificationCount() {
|
||||||
|
return this.$matrix.notificationCount
|
||||||
|
},
|
||||||
currentUser() {
|
currentUser() {
|
||||||
return this.$store.state.auth.user;
|
return this.$store.state.auth.user;
|
||||||
},
|
},
|
||||||
|
|
@ -126,8 +162,8 @@ export default {
|
||||||
},
|
},
|
||||||
title() {
|
title() {
|
||||||
var title = this.appName;
|
var title = this.appName;
|
||||||
if (this.$matrix.notificationCount > 0) {
|
if (this.notificationCount > 0) {
|
||||||
title += " [" + this.$matrix.notificationCount + "]";
|
title += " [" + this.notificationCount + "]";
|
||||||
}
|
}
|
||||||
if (this.$route.meta.title) {
|
if (this.$route.meta.title) {
|
||||||
title += " - " + this.$route.meta.title;
|
title += " - " + this.$route.meta.title;
|
||||||
|
|
@ -182,6 +218,11 @@ export default {
|
||||||
},
|
},
|
||||||
immediate: true,
|
immediate: true,
|
||||||
},
|
},
|
||||||
|
notificationCount: {
|
||||||
|
handler(nCount) {
|
||||||
|
this.requestNotificationPermission(nCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -329,5 +329,8 @@
|
||||||
"fetched_n_of_total_events": "Fetched {count} of {total} events",
|
"fetched_n_of_total_events": "Fetched {count} of {total} events",
|
||||||
"processed_n_of_total_events": "Processed media for {count} of {total} events",
|
"processed_n_of_total_events": "Processed media for {count} of {total} events",
|
||||||
"export_filename": "Exported chat {date}"
|
"export_filename": "Exported chat {date}"
|
||||||
|
},
|
||||||
|
"notification": {
|
||||||
|
"title": "New messages in Convene"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue