Commit 545ef12 1 parent 6fea7ce commit 545ef12 Copy full SHA for 545ef12
File tree 3 files changed +35
-32
lines changed
3 files changed +35
-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
+
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
+ })
18
51
< / script>
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments