cambio random del pwa
This commit is contained in:
@@ -8,6 +8,18 @@
|
||||
"display": "standalone",
|
||||
"background_color": "#111111",
|
||||
"theme_color": "#111111",
|
||||
"file_handlers": [
|
||||
{
|
||||
"action": "/open-snatchsave",
|
||||
"accept": {
|
||||
"application/x-snatchsave": [".snatchSave"]
|
||||
},
|
||||
"icons": [
|
||||
{ "src": "/pwa_icons/icon-48x48.png", "sizes": "48x48", "type": "image/png" },
|
||||
{ "src": "/pwa_icons/icon-128x128.png", "sizes": "128x128", "type": "image/png" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"icons": [
|
||||
{ "src": "/pwa_icons/icon-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
||||
{ "src": "/pwa_icons/icon-256x256.png", "sizes": "256x256", "type": "image/png", "purpose": "any" },
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { computed, ref, onMounted } from 'vue';
|
||||
|
||||
interface PlayerRow {
|
||||
sessionId: string;
|
||||
@@ -195,7 +195,7 @@ async function downloadNameManagerState() {
|
||||
const data = await response.json();
|
||||
const jsonString = JSON.stringify(data, null, 2);
|
||||
|
||||
const blob = new Blob([jsonString], { type: 'application/json;charset=utf-8;' });
|
||||
const blob = new Blob([jsonString], { type: 'application/x-snatchsave' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const now = new Date();
|
||||
const pad = (n: number) => String(n).padStart(2, '0');
|
||||
@@ -269,6 +269,36 @@ async function handleFileUpload(event: Event) {
|
||||
target.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
// Helper: import NameManager state from JSON text (used by PWA file handler)
|
||||
async function importNameManagerFromText(text: string) {
|
||||
try {
|
||||
const data = JSON.parse(text);
|
||||
const apiBase = (import.meta as any).env?.VITE_API_URL || `${window.location.protocol}//${window.location.host}/api`;
|
||||
const response = await fetch(`${apiBase}/admin/namemanager/import`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(data)
|
||||
});
|
||||
if (!response.ok) throw new Error(`Failed to upload nameManager state: ${response.status}`);
|
||||
const result = await response.json();
|
||||
const message = result.importedUuids
|
||||
? `Estado cargado exitosamente. ${result.importedUuids} UUIDs importados. ${result.message || ''}`
|
||||
: `Estado cargado exitosamente. ${result.message || 'NameManager actualizado.'}`;
|
||||
alert(message);
|
||||
} catch (e) {
|
||||
alert('Error al procesar el archivo .snatchSave');
|
||||
}
|
||||
}
|
||||
|
||||
// If PWA was launched with a .snatchSave file, auto-import here
|
||||
onMounted(async () => {
|
||||
const pending = localStorage.getItem('snatch.pendingSnatchSave');
|
||||
if (pending) {
|
||||
localStorage.removeItem('snatch.pendingSnatchSave');
|
||||
await importNameManagerFromText(pending);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -27,3 +27,26 @@ function setAppVhVar() {
|
||||
setAppVhVar();
|
||||
window.addEventListener('resize', setAppVhVar);
|
||||
window.addEventListener('orientationchange', setAppVhVar);
|
||||
|
||||
// Handle OS-level file open for .snatchSave via PWA File Handlers (Chromium desktop)
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const navAny = navigator as any;
|
||||
if (navAny.launchQueue && typeof navAny.launchQueue.setConsumer === 'function') {
|
||||
navAny.launchQueue.setConsumer(async (params: any) => {
|
||||
try {
|
||||
const files = (params && params.files) ? params.files : [];
|
||||
for (const fh of files) {
|
||||
const file: File = await fh.getFile();
|
||||
if (file && file.name.endsWith('.snatchSave')) {
|
||||
const text = await file.text();
|
||||
// Stash for Dashboard to import and navigate there.
|
||||
localStorage.setItem('snatch.pendingSnatchSave', text);
|
||||
router.push('/dashboard');
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ const router = createRouter({
|
||||
name: 'LobbyWithUuid',
|
||||
component: Lobby
|
||||
},
|
||||
{
|
||||
path: '/open-snatchsave',
|
||||
name: 'OpenSnatchSave',
|
||||
component: Dashboard
|
||||
},
|
||||
{
|
||||
path: '/:uuid/game',
|
||||
name: 'GameWithUuid',
|
||||
|
||||
Reference in New Issue
Block a user