diff --git a/resources/ts/app.ts b/resources/ts/app.ts index b42f5d534..c3c69a6de 100644 --- a/resources/ts/app.ts +++ b/resources/ts/app.ts @@ -4,6 +4,7 @@ import {createInertiaApp} from '@maicol07/inertia-mithril'; import {showSnackbar} from '@osm/utils/misc'; import Mithril from 'mithril'; import Stream from 'mithril/stream'; +import {pwaInfo} from 'virtual:pwa-info'; import {registerSW} from 'virtual:pwa-register'; import {resolvePage} from '~inertia'; @@ -63,3 +64,15 @@ const updateSW = registerSW({ void showSnackbar(__('È ora possibile lavorare offline!'), false); } }) as (reloadPage?: boolean) => Promise; + +if (pwaInfo) { + const {href, useCredentials} = pwaInfo.webManifest; + /* Add link to head: href is the link */ + const linkElement = document.createElement('link'); + linkElement.setAttribute('rel', 'manifest'); + linkElement.setAttribute('href', href); + if (useCredentials) { + linkElement.setAttribute('crossorigin', 'use-credentials'); + } + document.head.append(linkElement); +} diff --git a/resources/ts/typings/global.d.ts b/resources/ts/typings/global.d.ts index c2581aed9..0cd5c87f9 100644 --- a/resources/ts/typings/global.d.ts +++ b/resources/ts/typings/global.d.ts @@ -2,6 +2,7 @@ // noinspection JSFileReferences,JSUnusedGlobalSymbols,LocalVariableNamingConventionJS import 'inertia-plugin/client'; import 'vite-plugin-pwa/client.d'; +import 'vite-plugin-pwa/info.d'; import 'vite/client'; import type Mithril from 'mithril'; diff --git a/vite.config.ts b/vite.config.ts index 7458b4f33..012f18e81 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -65,7 +65,12 @@ export default defineConfig(async () => { assetsInclude: '**/*.xml', build: { sourcemap: true, - target: 'esnext' + target: 'esnext', + rollupOptions: { + output: { + assetFileNames: '[name].[ext]' + } + } }, resolve: { alias: aliases @@ -102,15 +107,11 @@ export default defineConfig(async () => { // }), VitePWA({ registerType: 'autoUpdate', - outDir: 'public', - buildBase: '/', - scope: '/', - // TODO: Check options + buildBase: '/build/', includeAssets: [ - 'resources/images/favicon/favicon.ico', - '../robots.txt', - 'resources/images/favicon/apple-touch-icon.png', - 'resources/images/*.png' + 'build/assets/*.ico', + 'robots.txt', + 'build/assets/*.png' ], manifest: { name: 'OpenSTAManager', @@ -119,7 +120,6 @@ export default defineConfig(async () => { categories: ['business', 'productivity'], display: 'minimal-ui', theme_color: '#3f3f3f', - background_color: '#fffff', icons: [ { src: 'android-chrome-192x192.png', @@ -134,8 +134,7 @@ export default defineConfig(async () => { { src: 'android-chrome-512x512.png', sizes: '512x512', - type: 'image/png', - purpose: 'any maskable' + type: 'image/png' } ] },