mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-06 20:43:46 +08:00
fab3ec9aeb
Add Galaxy web assets and client settings interfaces with their bundled vendor notices. Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
self.addEventListener("push", event => {
|
|
event.waitUntil((async () => {
|
|
let value
|
|
try { value = event.data.json() } catch { value = {} }
|
|
const id = typeof value?.eventId === "string" && /^[0-9a-f]{32}$/.test(value.eventId) ? value.eventId : "sentry"
|
|
const body = typeof value?.body === "string" ? value.body.slice(0, 256) : "Parked motion detected."
|
|
await self.registration.showNotification("StarPilot Sentry Mode", { body, tag: id,
|
|
data: { url: new URL("./#/cameras/events", self.registration.scope).href } })
|
|
})())
|
|
})
|
|
self.addEventListener("notificationclick", event => {
|
|
event.notification.close()
|
|
event.waitUntil((async () => {
|
|
const url = new URL("./#/cameras/events", self.registration.scope).href
|
|
const windows = await self.clients.matchAll({ type: "window", includeUncontrolled: true })
|
|
const existing = windows.find(client => client.url.startsWith(self.registration.scope))
|
|
if (existing) { await existing.navigate(url); return existing.focus() }
|
|
return self.clients.openWindow(url)
|
|
})())
|
|
})
|
|
|
|
// Migrate away from the legacy downloaded app shell without unregistering push.
|
|
self.addEventListener("install", () => self.skipWaiting())
|
|
self.addEventListener("activate", event => event.waitUntil((async () => {
|
|
await caches.delete("galaxy-offline-v1")
|
|
await self.clients.claim()
|
|
})()))
|