mobile: opcion de auto-backup local al terminar entreno o editar rutina

En el build movil (Capacitor) los datos solo viven en el dispositivo, sin
backend. Ademas del export/import manual ya existente, se agrega un toggle
en Settings que escribe una copia fechada en la carpeta Documents (visible
en Files/gestor de archivos) tras terminar un entrenamiento o salir del
editor de rutinas, para que una app de sincronizacion externa (o una copia
manual) siempre tenga algo reciente que llevarse.
This commit is contained in:
Josevi committed 2026-08-24 20:54:28 +02:00
1 parent 02ea938b2c
commit 50194442b6
6 files changed
+39 -2

No files matched your search

+18
View File
@@ -10,6 +10,7 @@
// Like the demo build, MOBILE is replaced at build time, so all of this folds away in
// web bundles; the Capacitor plugins are only ever imported behind it.
import { t } from './i18n-core.js'
import { todayISO } from './format.js'
export const MOBILE = import.meta.env.VITE_MOBILE === '1'
@@ -66,3 +67,20 @@ export async function shareExport(json, filename) {
const w = await Filesystem.writeFile({ path: filename, directory: Directory.Cache, data: json, encoding: Encoding.UTF8 })
await Share.share({ title: filename, url: w.uri })
}
// "Auto-backup on changes" (Settings): a dated snapshot dropped into the Documents folder —
// visible in Files (iOS) / a file manager (Android), unlike the private mirror nativeSave keeps
// — so whatever the user points at that folder (a sync app, a manual copy) always has something
// recent. One file per day; later triggers the same day just overwrite it.
export async function writeAutoBackup(state) {
try {
const { Filesystem, Directory, Encoding } = await import('@capacitor/filesystem')
await Filesystem.writeFile({
path: `opengym-backup-${todayISO()}.json`,
directory: Directory.Documents,
data: JSON.stringify(state),
encoding: Encoding.UTF8,
recursive: true,
})
} catch (e) { /* best effort — the private mirror in Directory.Data still has the data */ }
}