Compare commits

...

14 Commits

Author SHA1 Message Date
Thanh Nguyen
24fa90c699
Merge 9740e5ee1209df17009c0012ca4959d90f0b1a58 into 5aec3b4dabe7430654eb2e3ad0847f7f0b71efb9 2023-09-24 08:28:43 +00:00
Thanh Nguyen
9740e5ee12 Add explanation for ./sw.js 2023-09-24 15:28:37 +07:00
Thanh Nguyen
4bc71acc67 Remove redundant embed manifest.json 2023-09-24 15:15:23 +07:00
Thanh Nguyen
183e7cecb0 Make service worker works 2023-09-24 15:11:42 +07:00
Thanh Nguyen
bd6b77bcc2 Add larger icon (144x144) to manifest.json 2023-09-24 15:11:31 +07:00
Thanh Nguyen
628bde1527 Fix absolute links of index.html 2023-09-24 15:08:35 +07:00
Thanh Nguyen
976bbfd245 Fix manifest.json in routes.go 2023-09-24 14:05:53 +07:00
Thanh Nguyen
b79a542ed7 Remove redundant static files 2023-09-24 14:05:40 +07:00
Thanh Nguyen
c32bd7e415 Revert "Remove handling /manifest.json"
This reverts commit dadadeb0662b9725604e2db07a66c86ca8d04c30.
2023-09-24 13:50:16 +07:00
Thanh Nguyen
e9676491ee Fix edge case where HTTP Auth is used 2023-09-23 03:01:36 +07:00
Thanh Nguyen
1a545bb2a1 Fix links in index.html 2023-09-23 02:58:53 +07:00
Thanh Nguyen
1e128a7cd8 Add manifest.json to static assets 2023-09-23 02:51:50 +07:00
Thanh Nguyen
5dbb6a710c Add manifest.json to index.html 2023-09-23 02:38:02 +07:00
Thanh Nguyen
dadadeb066 Remove handling /manifest.json 2023-09-23 02:37:31 +07:00
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(),