@@ -22,6 +22,8 @@ import { employeeResource } from "@/data/employee"
22
22
import dayjs from "@/utils/dayjs"
23
23
import getIonicConfig from "@/utils/ionicConfig"
24
24
25
+ import FrappePushNotification from "../public/frappe-push-notification"
26
+
25
27
/* Core CSS required for Ionic components to work properly */
26
28
import "@ionic/vue/css/core.css"
27
29
@@ -54,8 +56,46 @@ app.provide("$employee", employeeResource)
54
56
app . provide ( "$socket" , socket )
55
57
app . provide ( "$dayjs" , dayjs )
56
58
59
+ const registerServiceWorker = ( ) => {
60
+ window . frappePushNotification = new FrappePushNotification ( "hrms" )
61
+
62
+ if ( "serviceWorker" in navigator ) {
63
+ window . frappePushNotification
64
+ . appendConfigToServiceWorkerURL ( "/assets/hrms/frontend/sw.js" )
65
+ . then ( ( url ) => {
66
+ navigator . serviceWorker
67
+ . register ( url , {
68
+ type : "classic" ,
69
+ } )
70
+ . then ( ( registration ) => {
71
+ window . frappePushNotification . initialize ( registration ) . then ( ( ) => {
72
+ console . log ( "Frappe Push Notification initialized" )
73
+ } )
74
+ } )
75
+ } )
76
+ . catch ( ( err ) => {
77
+ console . error ( "Failed to register service worker" , err )
78
+ } )
79
+ } else {
80
+ console . error ( "Service worker not enabled/supported by browser" )
81
+ }
82
+ }
83
+
57
84
router . isReady ( ) . then ( ( ) => {
58
- app . mount ( "#app" )
85
+ if ( import . meta. env . DEV ) {
86
+ frappeRequest ( {
87
+ url : "/api/method/hrms.www.hrms.get_context_for_dev" ,
88
+ } ) . then ( ( values ) => {
89
+ for ( let key in values ) {
90
+ window [ key ] = values [ key ]
91
+ }
92
+ registerServiceWorker ( )
93
+ app . mount ( "#app" )
94
+ } )
95
+ } else {
96
+ registerServiceWorker ( )
97
+ app . mount ( "#app" )
98
+ }
59
99
} )
60
100
61
101
router . beforeEach ( async ( to , from , next ) => {
0 commit comments