-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
104 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace $ { | ||
export function $mol_service_ensure() { | ||
return typeof window === 'undefined' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace $ { | ||
export class $mol_service_registration_web extends $mol_object { | ||
constructor ( protected raw: ServiceWorkerRegistration ) { super() } | ||
|
||
@ $mol_mem | ||
native() { | ||
const reg = this.raw | ||
// https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/updatefound_event | ||
const worker_reset = () => this.worker(null) | ||
reg.addEventListener( 'updatefound', worker_reset) | ||
|
||
return $mol_wire_sync(Object.assign(reg, { | ||
destructor: () => { | ||
reg.removeEventListener( 'updatefound', worker_reset) | ||
} | ||
})) | ||
} | ||
|
||
preload() { return $mol_wire_sync(this.native().navigationPreload) } | ||
pushes() { return $mol_wire_sync(this.native().pushManager) } | ||
|
||
@ $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 state_reset = () => this.state(null) | ||
worker.addEventListener( 'statechange', state_reset) | ||
|
||
return $mol_wire_sync(Object.assign(worker, { | ||
destructor: () => worker.removeEventListener('statechange', state_reset) | ||
})) | ||
} | ||
|
||
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 } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters