2025-04-30 17:34:46 +12:00
|
|
|
<script>
|
2025-06-20 23:26:06 +12:00
|
|
|
import { mailbox } from "../stores/mailbox.js";
|
2025-04-30 17:34:46 +12:00
|
|
|
|
|
|
|
export default {
|
2025-06-20 23:26:06 +12:00
|
|
|
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);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2025-04-30 17:34:46 +12:00
|
|
|
</script>
|