61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import {createInertiaApp} from '@maicol07/inertia-mithril';
|
|
import Mithril from 'mithril';
|
|
import {registerSW} from 'virtual:pwa-register';
|
|
import '~/../scss/app.scss';
|
|
|
|
import {showSnackbar} from '~/utils/misc';
|
|
import {resolvePage} from '~inertia';
|
|
|
|
import {OpenSTAManager} from './typings/modules';
|
|
import {
|
|
__ as stringTranslator,
|
|
_v as vnodeTranslator,
|
|
tr as translator
|
|
} from './utils/i18n';
|
|
|
|
// Let vite process assets
|
|
import.meta.glob([
|
|
'../images/**',
|
|
'../fonts/**'
|
|
]);
|
|
|
|
// Variabili globali
|
|
window.m = Mithril;
|
|
window.tr = translator;
|
|
window._v = vnodeTranslator;
|
|
window.__ = stringTranslator;
|
|
|
|
// Load modules bootstrap
|
|
import.meta.glob('../../vendor/**/**/resources/{js,ts}/bootstrap.{tsx,ts,js,jsx}', {eager: true});
|
|
|
|
await createInertiaApp({
|
|
title: ((title) => `${title} - OpenSTAManager`),
|
|
// This rule is disabled to avoid a bug in Inertia plugin
|
|
// eslint-disable-next-line arrow-body-style
|
|
resolve: resolvePage((page) => {
|
|
return import.meta.glob<OpenSTAManager.ImportedModule>('./Views/**/*.tsx');
|
|
}),
|
|
setup({el, App, props}) {
|
|
if (!el) {
|
|
throw new Error('No mounting HTMLElement found');
|
|
}
|
|
|
|
m.mount(el, {
|
|
view: (vnode) => m(App, props)
|
|
});
|
|
}
|
|
});
|
|
|
|
// PWA
|
|
const updateSW = registerSW({
|
|
async onNeedRefresh() {
|
|
const action = await showSnackbar(__('Aggiornamento del frontend disponibile!'), false, __('Ricarica'), __('Annulla'));
|
|
if (action === 'action') {
|
|
await updateSW();
|
|
}
|
|
},
|
|
onOfflineReady() {
|
|
void showSnackbar(__('È ora possibile lavorare offline!'), false);
|
|
}
|
|
}) as (reloadPage?: boolean) => Promise<void>;
|