Started working on service worker
This commit is contained in:
parent
0f59969f0d
commit
4f7c2e95f0
12
assets.go
12
assets.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
@ -10,6 +11,12 @@ import (
|
||||
func init() {
|
||||
// Scripts
|
||||
scripts := js.Bundle()
|
||||
serviceWorkerBytes, err := ioutil.ReadFile("sw/service-worker.js")
|
||||
serviceWorker := string(serviceWorkerBytes)
|
||||
|
||||
if err != nil {
|
||||
panic("Couldn't load service worker")
|
||||
}
|
||||
|
||||
app.Get("/scripts", func(ctx *aero.Context) string {
|
||||
ctx.SetResponseHeader("Content-Type", "application/javascript")
|
||||
@ -21,6 +28,11 @@ func init() {
|
||||
return scripts
|
||||
})
|
||||
|
||||
app.Get("/service-worker", func(ctx *aero.Context) string {
|
||||
ctx.SetResponseHeader("Content-Type", "application/javascript")
|
||||
return serviceWorker
|
||||
})
|
||||
|
||||
// Web manifest
|
||||
app.Get("/manifest.json", func(ctx *aero.Context) string {
|
||||
return ctx.JSON(app.Config.Manifest)
|
||||
|
@ -33,7 +33,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
|
||||
component StatusMessage
|
||||
#status-message.fade.fade-out
|
||||
#status-message-text
|
||||
a.status-message-action.action(href="#", data-trigger="click", data-action="closeStatusMessage")
|
||||
a.status-message-action.action(href="#", data-trigger="click", data-action="closeStatusMessage", aria-label="Close status message")
|
||||
RawIcon("close")
|
||||
|
||||
component LoadingAnimation
|
||||
|
@ -97,7 +97,7 @@ export class AnimeNotifier {
|
||||
this.app.find("status-message-text")
|
||||
)
|
||||
|
||||
// Let's start
|
||||
// Let"s start
|
||||
this.app.run()
|
||||
}
|
||||
|
||||
@ -123,6 +123,21 @@ export class AnimeNotifier {
|
||||
}
|
||||
|
||||
onIdle() {
|
||||
this.registerServiceWorker()
|
||||
this.pushAnalytics()
|
||||
}
|
||||
|
||||
registerServiceWorker() {
|
||||
navigator.serviceWorker.register("service-worker", {
|
||||
scope: "/"
|
||||
})
|
||||
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log("Service worker registered.")
|
||||
})
|
||||
}
|
||||
|
||||
pushAnalytics() {
|
||||
if(!this.user) {
|
||||
return
|
||||
}
|
||||
|
5
sw/service-worker.ts
Normal file
5
sw/service-worker.ts
Normal file
@ -0,0 +1,5 @@
|
||||
// pack:ignore
|
||||
|
||||
self.addEventListener("install", evt => {
|
||||
console.log("The service worker is being installed.")
|
||||
})
|
Loading…
Reference in New Issue
Block a user