fix: Fix manifest PWA non registrato correttamente

This commit is contained in:
Maicol Battistini 2023-07-26 18:55:05 +02:00
parent 83d1c1ddd4
commit e894086b4c
No known key found for this signature in database
3 changed files with 25 additions and 12 deletions

View File

@ -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<void>;
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);
}

View File

@ -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';

View File

@ -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'
}
]
},