Merge 9740e5ee1209df17009c0012ca4959d90f0b1a58 into 5f606b1c406c6b0d25cb4a6df7955fbb0059f59d

This commit is contained in:
Thanh Nguyen 2024-03-19 16:27:54 +03:00 committed by GitHub
commit 309c198450
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 60 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -3,16 +3,22 @@
<head>
<meta charset="UTF-8">
<title>yarr!</title>
<link rel="stylesheet" href="./static/stylesheets/bootstrap.min.css">
<link rel="stylesheet" href="./static/stylesheets/app.css">
<link rel="icon" href="./static/graphicarts/favicon.svg" type="image/svg+xml">
<link rel="alternate icon" href="./static/graphicarts/favicon.png" type="image/png">
<link rel="manifest" href="./manifest.json" />
<link rel="stylesheet" href="./static/stylesheets/bootstrap.min.css" crossorigin="use-credentials">
<link rel="stylesheet" href="./static/stylesheets/app.css" crossorigin="use-credentials">
<link rel="icon" href="./static/graphicarts/favicon.svg" type="image/svg+xml" crossorigin="use-credentials">
<link rel="alternate icon" href="./static/graphicarts/favicon.png" type="image/png" crossorigin="use-credentials">
<link rel="manifest" href="./manifest.json" crossorigin="use-credentials"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<script>
window.app = window.app || {}
window.app.settings = {% .settings %}
window.app.authenticated = {% .authenticated %}
if ("serviceWorker" in navigator) {
// we use `./sw.js` instead of `./static/javascripts/sw.js` since the latter would not work with
// `./manifest.json`, and it leads to uninstallable PWA
navigator.serviceWorker.register("./sw.js")
}
</script>
</head>
<body class="theme-{% .settings.theme_name %}">

View File

@ -0,0 +1,34 @@
const VERSION = "v2.4"
const APP_STATIC_RESOURCES = [
"/",
"/static/stylesheets/bootstrap.min.css",
"/static/stylesheets/app.css",
"/static/graphicarts/favicon.svg",
"/static/graphicarts/favicon.png",
]
const CACHE_NAME = `yarr-${VERSION}`;
self.addEventListener("install", (e) => {
e.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME)
await cache.addAll(APP_STATIC_RESOURCES)
})()
)
})
// delete old caches on activate
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
const names = await caches.keys()
await Promise.all(
names.map((name) => {
if (name !== CACHE_NAME) {
return caches.delete(name)
}
}),
)
await clients.claim()
})(),
)
})

View File

@ -41,6 +41,7 @@ func (s *Server) handler() http.Handler {
r.For("/", s.handleIndex)
r.For("/manifest.json", s.handleManifest)
r.For("/sw.js", s.handleServiceWorker)
r.For("/static/*path", s.handleStatic)
r.For("/api/status", s.handleStatus)
r.For("/api/folders", s.handleFolderList)
@ -93,10 +94,24 @@ func (s *Server) handleManifest(c *router.Context) {
"sizes": "64x64",
"type": "image/png",
},
{
"src": s.BasePath + "/static/graphicarts/favicon-144.png",
"sizes": "144x144",
"type": "image/png",
},
{
"src": s.BasePath + "/static/graphicarts/favicon.svg",
"sizes": "any",
"type": "image/svg",
},
},
})
}
func (s *Server) handleServiceWorker(c *router.Context) {
http.ServeFile(c.Out, c.Req, "src/assets/javascripts/sw.js")
}
func (s *Server) handleStatus(c *router.Context) {
c.JSON(http.StatusOK, map[string]interface{}{
"running": s.worker.FeedsPending(),