@things-factory/shell 8.0.93 → 8.0.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -114,13 +114,14 @@ if (production) {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
/* for push notification */
|
|
117
|
-
addEventListener('push',
|
|
117
|
+
addEventListener('push', event => {
|
|
118
118
|
if (!event.data) {
|
|
119
119
|
return
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
+
let notification, data
|
|
122
123
|
try {
|
|
123
|
-
|
|
124
|
+
;({ notification, data } = event.data.json())
|
|
124
125
|
} catch (e) {
|
|
125
126
|
notification = {
|
|
126
127
|
body: event.data.text()
|
|
@@ -136,22 +137,31 @@ addEventListener('push', async event => {
|
|
|
136
137
|
data
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
/**
|
|
141
|
+
* event.waitUntil로 showNotification까지 감싸야 한다.
|
|
142
|
+
* 안 감싸면 Chrome이 "푸시 왔는데 알림 미표시"로 판단해
|
|
143
|
+
* "이 사이트는 백그라운드에서 업데이트되었습니다" 대체 알림을 추가로 띄운다(중복).
|
|
144
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification
|
|
145
|
+
*/
|
|
146
|
+
event.waitUntil(
|
|
147
|
+
(async () => {
|
|
148
|
+
await notificationStore.add({
|
|
149
|
+
timestamp: Date.now(),
|
|
150
|
+
...notification,
|
|
151
|
+
...data
|
|
152
|
+
})
|
|
144
153
|
|
|
145
|
-
|
|
154
|
+
await notificationStore.limit()
|
|
146
155
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
channel.postMessage({
|
|
157
|
+
type: 'notification',
|
|
158
|
+
notification,
|
|
159
|
+
data
|
|
160
|
+
})
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
|
|
162
|
+
await registration.showNotification(title, options)
|
|
163
|
+
})()
|
|
164
|
+
)
|
|
155
165
|
})
|
|
156
166
|
|
|
157
167
|
addEventListener('notificationclick', async event => {
|