1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-07-17 01:32:33 +02:00

Feature: Display unread count in app badge (#485)

* Display unread count in app badge

* Rate limit app badge updates
This commit is contained in:
Matt Currie
2025-04-30 17:34:46 +12:00
committed by GitHub
parent 87c67e1b1f
commit 05375fed7a
2 changed files with 62 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<script> <script>
import CommonMixins from './mixins/CommonMixins' import CommonMixins from './mixins/CommonMixins'
import Favicon from './components/Favicon.vue' import Favicon from './components/Favicon.vue'
import AppBadge from './components/AppBadge.vue'
import Notifications from './components/Notifications.vue' import Notifications from './components/Notifications.vue'
import EditTags from './components/EditTags.vue' import EditTags from './components/EditTags.vue'
import { mailbox } from "./stores/mailbox" import { mailbox } from "./stores/mailbox"
@ -10,6 +11,7 @@ export default {
components: { components: {
Favicon, Favicon,
AppBadge,
Notifications, Notifications,
EditTags EditTags
}, },
@ -40,6 +42,7 @@ export default {
<template> <template>
<RouterView /> <RouterView />
<Favicon /> <Favicon />
<AppBadge />
<Notifications /> <Notifications />
<EditTags /> <EditTags />
</template> </template>

View File

@ -0,0 +1,59 @@
<script>
import { mailbox } from '../stores/mailbox.js'
export default {
data() {
return {
updating: false,
needsUpdate: false,
timeout: 500,
}
},
computed: {
mailboxUnread() {
return mailbox.unread
}
},
watch: {
mailboxUnread: {
handler() {
if (this.updating) {
this.needsUpdate = true
return
}
this.scheduleUpdate()
},
immediate: true
}
},
methods: {
scheduleUpdate() {
this.updating = true
this.needsUpdate = false
window.setTimeout(() => {
this.updateAppBadge()
this.updating = false
if (this.needsUpdate) {
this.scheduleUpdate()
}
}, this.timeout)
},
updateAppBadge() {
if (!('setAppBadge' in navigator)) {
return
}
navigator.setAppBadge(this.mailboxUnread)
}
}
}
</script>
<template></template>