File tree 1 file changed +24
-1
lines changed
1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -91,10 +91,33 @@ document.addEventListener("DOMContentLoaded", () => {
91
91
return outputArray ;
92
92
}
93
93
94
+ function checkNotificationPermission ( ) {
95
+ return new Promise ( ( resolve , reject ) => {
96
+ if ( Notification . permission === 'denied' ) {
97
+ return reject ( new Error ( 'Push messages are blocked.' ) ) ;
98
+ }
99
+
100
+ if ( Notification . permission === 'granted' ) {
101
+ return resolve ( ) ;
102
+ }
103
+
104
+ if ( Notification . permission === 'default' ) {
105
+ return Notification . requestPermission ( ) . then ( result => {
106
+ if ( result !== 'granted' ) {
107
+ reject ( new Error ( 'Bad permission result' ) ) ;
108
+ }
109
+
110
+ resolve ( ) ;
111
+ } ) ;
112
+ }
113
+ } ) ;
114
+ }
115
+
94
116
function push_subscribe ( ) {
95
117
changePushButtonState ( 'computing' ) ;
96
118
97
- navigator . serviceWorker . ready
119
+ return checkNotificationPermission ( )
120
+ . then ( ( ) => navigator . serviceWorker . ready )
98
121
. then ( serviceWorkerRegistration => serviceWorkerRegistration . pushManager . subscribe ( {
99
122
userVisibleOnly : true ,
100
123
applicationServerKey : urlBase64ToUint8Array ( applicationServerKey ) ,
You can’t perform that action at this time.
0 commit comments