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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
@ -10,6 +11,12 @@ import (
|
|||||||
func init() {
|
func init() {
|
||||||
// Scripts
|
// Scripts
|
||||||
scripts := js.Bundle()
|
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 {
|
app.Get("/scripts", func(ctx *aero.Context) string {
|
||||||
ctx.SetResponseHeader("Content-Type", "application/javascript")
|
ctx.SetResponseHeader("Content-Type", "application/javascript")
|
||||||
@ -21,6 +28,11 @@ func init() {
|
|||||||
return scripts
|
return scripts
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.Get("/service-worker", func(ctx *aero.Context) string {
|
||||||
|
ctx.SetResponseHeader("Content-Type", "application/javascript")
|
||||||
|
return serviceWorker
|
||||||
|
})
|
||||||
|
|
||||||
// Web manifest
|
// Web manifest
|
||||||
app.Get("/manifest.json", func(ctx *aero.Context) string {
|
app.Get("/manifest.json", func(ctx *aero.Context) string {
|
||||||
return ctx.JSON(app.Config.Manifest)
|
return ctx.JSON(app.Config.Manifest)
|
||||||
|
@ -33,7 +33,7 @@ component Layout(app *aero.Application, ctx *aero.Context, user *arn.User, openG
|
|||||||
component StatusMessage
|
component StatusMessage
|
||||||
#status-message.fade.fade-out
|
#status-message.fade.fade-out
|
||||||
#status-message-text
|
#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")
|
RawIcon("close")
|
||||||
|
|
||||||
component LoadingAnimation
|
component LoadingAnimation
|
||||||
|
@ -97,7 +97,7 @@ export class AnimeNotifier {
|
|||||||
this.app.find("status-message-text")
|
this.app.find("status-message-text")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Let's start
|
// Let"s start
|
||||||
this.app.run()
|
this.app.run()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +123,21 @@ export class AnimeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onIdle() {
|
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) {
|
if(!this.user) {
|
||||||
return
|
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