Skip to content

Commit 339097b

Browse files
committed
feat: use showNotification for in-app notifications
1 parent 6fea7ce commit 339097b

File tree

4 files changed

+36
-32
lines changed

4 files changed

+36
-32
lines changed

frontend/public/frappe-push-notification.js

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class FrappePushNotification {
122122
* )} callback - Callback function to handle message
123123
*/
124124
onMessage(callback) {
125-
console.log("onMessage")
126125
if (callback == null) return
127126
this.onMessageHandler = callback
128127
if (this.messaging == null) return

frontend/src/App.vue

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44
<Toasts />
55

66
<InstallPrompt />
7-
<FrappeNotification />
87
</ion-app>
98
</template>
109

1110
<script setup>
11+
import { onMounted } from "vue"
1212
import { IonApp, IonRouterOutlet } from "@ionic/vue"
1313
1414
import { Toasts } from "frappe-ui"
1515
1616
import InstallPrompt from "@/components/InstallPrompt.vue"
17-
import FrappeNotification from "@/components/FrappeNotification.vue"
17+
import { showNotification } from "@/utils/pushNotifications"
18+
19+
onMounted(() => {
20+
window?.frappePushNotification?.onMessage((payload) => {
21+
showNotification(payload)
22+
})
23+
})
1824
</script>

frontend/src/components/FrappeNotification.vue

-29
This file was deleted.
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const isChrome = () =>
2+
navigator.userAgent.toLowerCase().includes("chrome")
3+
4+
export const showNotification = (payload) => {
5+
const registration = window.frappePushNotification.serviceWorkerRegistration
6+
if (!registration) return
7+
8+
const notificationTitle = payload?.data?.title
9+
const notificationOptions = {
10+
body: payload?.data?.body || "",
11+
}
12+
if (isChrome()) {
13+
notificationOptions["data"] = {
14+
url: payload?.data?.click_action,
15+
}
16+
} else {
17+
if (payload?.data?.click_action) {
18+
notificationOptions["actions"] = [
19+
{
20+
action: payload.data.click_action,
21+
title: "View Details",
22+
},
23+
]
24+
}
25+
}
26+
27+
registration.showNotification(notificationTitle, notificationOptions)
28+
}

0 commit comments

Comments
 (0)