Skip to content

Commit

Permalink
feat: use showNotification for in-app notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Feb 27, 2024
1 parent 6fea7ce commit 545ef12
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
1 change: 0 additions & 1 deletion frontend/public/frappe-push-notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class FrappePushNotification {
* )} callback - Callback function to handle message
*/
onMessage(callback) {
console.log("onMessage")
if (callback == null) return
this.onMessageHandler = callback
if (this.messaging == null) return
Expand Down
37 changes: 35 additions & 2 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,48 @@
<Toasts />

<InstallPrompt />
<FrappeNotification />
</ion-app>
</template>

<script setup>
import { onMounted } from "vue"
import { IonApp, IonRouterOutlet } from "@ionic/vue"
import { Toasts } from "frappe-ui"
import InstallPrompt from "@/components/InstallPrompt.vue"
import FrappeNotification from "@/components/FrappeNotification.vue"
const isChrome = () => navigator.userAgent.toLowerCase().includes("chrome")
const showNotification = (payload) => {
const registration = window.frappePushNotification.serviceWorkerRegistration
if (!registration) return
const notificationTitle = payload?.data?.title
const notificationOptions = {
body: payload?.data?.body || "",
}
if (isChrome()) {
notificationOptions["data"] = {
url: payload?.data?.click_action,
}
} else {
if (payload?.data?.click_action) {
notificationOptions["actions"] = [
{
action: payload.data.click_action,
title: "View Details",
},
]
}
}
registration.showNotification(notificationTitle, notificationOptions)
}
onMounted(() => {
window.frappePushNotification.onMessage((payload) => {
showNotification(payload)
})
})
</script>
29 changes: 0 additions & 29 deletions frontend/src/components/FrappeNotification.vue

This file was deleted.

0 comments on commit 545ef12

Please sign in to comment.