Commit 339097b 1 parent 6fea7ce commit 339097b Copy full SHA for 339097b
File tree 4 files changed +36
-32
lines changed
4 files changed +36
-32
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,6 @@ class FrappePushNotification {
122
122
* )} callback - Callback function to handle message
123
123
*/
124
124
onMessage ( callback ) {
125
- console . log ( "onMessage" )
126
125
if ( callback == null ) return
127
126
this . onMessageHandler = callback
128
127
if ( this . messaging == null ) return
Original file line number Diff line number Diff line change 4
4
<Toasts />
5
5
6
6
<InstallPrompt />
7
- <FrappeNotification />
8
7
</ion-app >
9
8
</template >
10
9
11
10
<script setup>
11
+ import { onMounted } from " vue"
12
12
import { IonApp , IonRouterOutlet } from " @ionic/vue"
13
13
14
14
import { Toasts } from " frappe-ui"
15
15
16
16
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
+ })
18
24
< / script>
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments