cambio random del pwa
This commit is contained in:
@@ -8,6 +8,18 @@
|
|||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"background_color": "#111111",
|
"background_color": "#111111",
|
||||||
"theme_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": [
|
"icons": [
|
||||||
{ "src": "/pwa_icons/icon-192x192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
|
{ "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" },
|
{ "src": "/pwa_icons/icon-256x256.png", "sizes": "256x256", "type": "image/png", "purpose": "any" },
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref, onMounted } from 'vue';
|
||||||
|
|
||||||
interface PlayerRow {
|
interface PlayerRow {
|
||||||
sessionId: string;
|
sessionId: string;
|
||||||
@@ -195,7 +195,7 @@ async function downloadNameManagerState() {
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
const jsonString = JSON.stringify(data, null, 2);
|
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 url = URL.createObjectURL(blob);
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const pad = (n: number) => String(n).padStart(2, '0');
|
const pad = (n: number) => String(n).padStart(2, '0');
|
||||||
@@ -269,6 +269,36 @@ async function handleFileUpload(event: Event) {
|
|||||||
target.value = '';
|
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>
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
|
|||||||
@@ -27,3 +27,26 @@ function setAppVhVar() {
|
|||||||
setAppVhVar();
|
setAppVhVar();
|
||||||
window.addEventListener('resize', setAppVhVar);
|
window.addEventListener('resize', setAppVhVar);
|
||||||
window.addEventListener('orientationchange', 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',
|
name: 'LobbyWithUuid',
|
||||||
component: Lobby
|
component: Lobby
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/open-snatchsave',
|
||||||
|
name: 'OpenSnatchSave',
|
||||||
|
component: Dashboard
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/:uuid/game',
|
path: '/:uuid/game',
|
||||||
name: 'GameWithUuid',
|
name: 'GameWithUuid',
|
||||||
|
|||||||
Reference in New Issue
Block a user