Skip to content

Commit

Permalink
$mol_service_worker simple notify
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 3, 2024
1 parent 7f008e6 commit 2169769
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 0 additions & 4 deletions service/registration/registration.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ namespace $ {
}))
}

protected container() {
return this.$.$mol_dom_context.navigator?.serviceWorker ?? $mol_fail(new Error('Service worker not found'))
}

@ $mol_mem
state(reset?: null) { return this.worker().state ?? null }

Expand Down
10 changes: 5 additions & 5 deletions service/worker/worker.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ namespace $ {
scope.addEventListener( 'message', this.handle(this.message.bind(this)))
scope.addEventListener( 'messageerror', this.message_error.bind(this))

scope.addEventListener( 'notificationclick', this.handle(this.notify.bind(this, false)))
scope.addEventListener( 'notificationclose', this.handle(this.notify.bind(this, true)))
scope.addEventListener( 'notificationclick', this.handle(this.notify.bind(this, 'notification')))
scope.addEventListener( 'notificationclose', this.handle(this.notify.bind(this, 'notification_close')))

scope.addEventListener( 'push', this.handle(this.push.bind(this)))
scope.addEventListener( 'fetch', event => {
Expand Down Expand Up @@ -220,13 +220,13 @@ namespace $ {
}
}

static notify(closing: boolean, event: NotificationEvent) {
static notify(method: 'notification' | 'notification_close', event: NotificationEvent) {
for (const plugin of this.plugins_notify()) {
try {
closing ? plugin.notification_close(event.notification) : plugin.notification(event.notification)
plugin[method](event.notification)
} catch (error) {
if ( ! $mol_fail_catch(error) ) continue
this.plugin_error(error, `${plugin}.${closing ? 'notification_close' : 'notification'}()`)
this.plugin_error(error, `${plugin}.${method}()`)
}
}
}
Expand Down

0 comments on commit 2169769

Please sign in to comment.