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:
@ -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>
|
||||||
|
59
server/ui-src/components/AppBadge.vue
Normal file
59
server/ui-src/components/AppBadge.vue
Normal 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>
|
Reference in New Issue
Block a user