From 827760f9c9146f466da332382bd0ab4ccecdaba5 Mon Sep 17 00:00:00 2001 From: herteleo Date: Sat, 20 Apr 2019 20:02:44 +0200 Subject: [PATCH] feat(navigation): show notification badge on tab if it has news --- src/components/TabMain.vue | 6 ++++++ src/components/TabWebview.vue | 33 +++++++++++++++++++++++++++++++++ src/components/TabsNavItem.vue | 9 +++++++++ src/store/modules/Pages.js | 8 +++++++- 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/components/TabMain.vue b/src/components/TabMain.vue index 05ed66f..1fa3658 100644 --- a/src/components/TabMain.vue +++ b/src/components/TabMain.vue @@ -14,6 +14,7 @@ @@ -44,6 +45,11 @@ export default { watch: { isActive(isActive) { if (isActive) { + this.$store.commit('Pages/setState', { + tabId: this.item.id, + data: { hasNotificationBadge: false }, + }); + this.webview.focus(); } }, diff --git a/src/components/TabWebview.vue b/src/components/TabWebview.vue index f565b2c..43b48fe 100644 --- a/src/components/TabWebview.vue +++ b/src/components/TabWebview.vue @@ -19,6 +19,15 @@ export default { type: Object, default: () => ({}), }, + isActive: { + type: Boolean, + required: true, + }, + }, + data() { + return { + isLoaded: false, + }; }, computed: { muteOnWindowBlur() { @@ -44,6 +53,14 @@ export default { }, }, mounted() { + this.webview.addEventListener('did-stop-loading', () => { + this.isLoaded = true; + }); + + this.webview.addEventListener('did-start-loading', () => { + this.isLoaded = false; + }); + this.webview.addEventListener('ipc-message', (event) => { if (event.channel !== 'notification') return; @@ -54,6 +71,8 @@ export default { tabId: this.item.id, }); + this.evaluateIfHasNotifications(); + if (!this.notificationsPreventOnBlur || this.windowHasFocus) { new Notification(notification.title, notification.options); // eslint-disable-line no-new } @@ -64,6 +83,8 @@ export default { tabId: this.item.id, data: { title }, }); + + this.evaluateIfHasNotifications(); }); this.webview.addEventListener('page-favicon-updated', ({ favicons }) => { @@ -73,6 +94,8 @@ export default { tabId: this.item.id, data: { favicon }, }); + + this.evaluateIfHasNotifications(); }); this.webview.addEventListener('dom-ready', (view) => { @@ -92,6 +115,16 @@ export default { } }); }, + methods: { + evaluateIfHasNotifications() { + this.$store.commit('Pages/setState', { + tabId: this.item.id, + data: { + hasNotificationBadge: this.isLoaded && !this.isActive, + }, + }); + }, + }, }; diff --git a/src/components/TabsNavItem.vue b/src/components/TabsNavItem.vue index 2b06240..41a38a5 100644 --- a/src/components/TabsNavItem.vue +++ b/src/components/TabsNavItem.vue @@ -5,6 +5,10 @@ :active-class="$style.active" tag="button" > +