desktop page supports service worker

This commit is contained in:
MaysWind
2023-07-09 13:20:24 +08:00
parent b555af0df7
commit 475ec24528
2 changed files with 16 additions and 1 deletions
+7 -1
View File
@@ -74,6 +74,8 @@ func startWebServer(c *cli.Context) error {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
} }
workboxFileNames := utils.ListFileNamesWithPrefixAndSuffix(config.StaticRootPath, "workbox-", ".js")
router := gin.New() router := gin.New()
router.Use(bindMiddleware(middlewares.Recovery)) router.Use(bindMiddleware(middlewares.Recovery))
@@ -119,7 +121,6 @@ func startWebServer(c *cli.Context) error {
router.StaticFile("/mobile/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json")) router.StaticFile("/mobile/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json"))
router.StaticFile("/mobile/sw.js", filepath.Join(config.StaticRootPath, "sw.js")) router.StaticFile("/mobile/sw.js", filepath.Join(config.StaticRootPath, "sw.js"))
workboxFileNames := utils.ListFileNamesWithPrefixAndSuffix(config.StaticRootPath, "workbox-", ".js")
for i := 0; i < len(workboxFileNames); i++ { for i := 0; i < len(workboxFileNames); i++ {
router.StaticFile("/mobile/"+workboxFileNames[i], filepath.Join(config.StaticRootPath, workboxFileNames[i])) router.StaticFile("/mobile/"+workboxFileNames[i], filepath.Join(config.StaticRootPath, workboxFileNames[i]))
} }
@@ -137,6 +138,11 @@ func startWebServer(c *cli.Context) error {
router.StaticFile("/desktop/favicon.png", filepath.Join(config.StaticRootPath, "favicon.png")) router.StaticFile("/desktop/favicon.png", filepath.Join(config.StaticRootPath, "favicon.png"))
router.StaticFile("/desktop/touchicon.png", filepath.Join(config.StaticRootPath, "touchicon.png")) router.StaticFile("/desktop/touchicon.png", filepath.Join(config.StaticRootPath, "touchicon.png"))
router.StaticFile("/desktop/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json")) router.StaticFile("/desktop/manifest.json", filepath.Join(config.StaticRootPath, "manifest.json"))
router.StaticFile("/desktop/sw.js", filepath.Join(config.StaticRootPath, "sw.js"))
for i := 0; i < len(workboxFileNames); i++ {
router.StaticFile("/desktop/"+workboxFileNames[i], filepath.Join(config.StaticRootPath, workboxFileNames[i]))
}
router.GET("/healthz.json", bindApi(api.Healths.HealthStatusHandler)) router.GET("/healthz.json", bindApi(api.Healths.HealthStatusHandler))
+9
View File
@@ -7,6 +7,7 @@
<script> <script>
import { useTheme } from 'vuetify'; import { useTheme } from 'vuetify';
import { register } from 'register-service-worker';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/setting.js'; import { useSettingsStore } from '@/stores/setting.js';
@@ -69,6 +70,14 @@ export default {
} }
} }
} }
if (isProduction()) {
register('./sw.js', {
registrationOptions: {
scope: './'
}
});
}
}, },
mounted() { mounted() {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {