Skip to content

Commit

Permalink
$mol_service_worker fix start
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 4, 2024
1 parent 9dafc68 commit 7778411
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion service/plugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace $ {
$mol_service_worker.init()
$mol_service_worker.start()

export namespace $mol_service_plugin {
let _
Expand Down
4 changes: 3 additions & 1 deletion service/registration/registration.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ namespace $ {
@ $mol_mem
worker(reset?: null) {
const reg = this.native()
const worker = reg.installing ?? reg.waiting ?? reg.active ?? $mol_fail(new Error('No worker in registration'))
const worker = reg.installing ?? reg.waiting ?? reg.active
?? (self as unknown as ServiceWorkerGlobalScope).serviceWorker
?? $mol_fail(new Error('No worker in registration'))

const state_reset = () => this.state(null)
worker.addEventListener( 'statechange', state_reset)
Expand Down
6 changes: 6 additions & 0 deletions service/worker/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ namespace $ {
static send(data: {}) { return null as unknown }

static init() {}

static async start() {
await Promise.resolve()
await $mol_wire_async(this).init()
}

static claim() {}

static blocked_response() {
Expand Down
12 changes: 2 additions & 10 deletions service/worker/worker.web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@
namespace $ {

export class $mol_service_worker_web extends $mol_service_worker {
static plugins_add_wait() { return Promise.resolve() }

@ $mol_mem
static init() {
$mol_wire_solid()
try {
if ( this.$.$mol_service_ensure() ) {
$mol_wire_sync(this).plugins_add_wait()
this.plugins()
}
this.registration().worker()
} catch (error) {
this.$.$mol_fail_log(error)
}
if ( this.$.$mol_service_ensure() ) this.plugins()
this.registration().worker()
return null
}

Expand Down

0 comments on commit 7778411

Please sign in to comment.