Skip to content

Commit 545ef12

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

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-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

+35-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,48 @@
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+
18+
const isChrome = () => navigator.userAgent.toLowerCase().includes("chrome")
19+
20+
const showNotification = (payload) => {
21+
const registration = window.frappePushNotification.serviceWorkerRegistration
22+
if (!registration) return
23+
24+
const notificationTitle = payload?.data?.title
25+
const notificationOptions = {
26+
body: payload?.data?.body || "",
27+
}
28+
if (isChrome()) {
29+
notificationOptions["data"] = {
30+
url: payload?.data?.click_action,
31+
}
32+
} else {
33+
if (payload?.data?.click_action) {
34+
notificationOptions["actions"] = [
35+
{
36+
action: payload.data.click_action,
37+
title: "View Details",
38+
},
39+
]
40+
}
41+
}
42+
43+
registration.showNotification(notificationTitle, notificationOptions)
44+
}
45+
46+
onMounted(() => {
47+
window.frappePushNotification.onMessage((payload) => {
48+
showNotification(payload)
49+
})
50+
})
1851
</script>

frontend/src/components/FrappeNotification.vue

-29
This file was deleted.

0 commit comments

Comments
 (0)