Files
Schnappix/src/services/settings.ts
T

89 lines
2.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { File, Paths } from 'expo-file-system';
import * as FileSystem from 'expo-file-system/legacy';
import { FRAMES } from '../data/frames';
export const APP_VERSION = 2; // Increment this whenever you want settings to reset on update
export interface AppSettings {
appVersion: number;
countdownDuration: number; // in seconds
printerIp: string;
adminPassword: string;
kioskModeEnabled: boolean;
// Photo Frames
frameMode: 'off' | 'always' | 'available';
selectedFrameId: string | null;
availableFrameIds: string[];
// Date/Time overlay
dateOverlay: 'off' | 'date' | 'datetime';
dateOverlayPosition: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'bottom-center';
// Event text (shown in date sticker & welcome)
eventText: string;
// Continuous shooting / burst
burstCount: number; // 1 = single shot, 25 = burst
burstIntervalSec: number; // seconds between burst shots
// Welcome screen text
welcomeText: string;
footerText: string;
// System
useFrontCamera: boolean;
enableLogs: boolean;
}
const settingsFile = new File(Paths.document, 'settings.json');
const DEFAULT_SETTINGS: AppSettings = {
appVersion: APP_VERSION,
countdownDuration: 3,
printerIp: '192.168.1.100',
adminPassword: '1234',
kioskModeEnabled: false,
frameMode: 'available',
selectedFrameId: null,
availableFrameIds: FRAMES.map(f => f.id),
dateOverlay: 'off',
dateOverlayPosition: 'bottom-right',
eventText: '',
burstCount: 1,
burstIntervalSec: 5,
welcomeText: 'Willkommen zu unserer Feier!',
footerText: 'ZUM STARTEN TIPPEN • Fotos machen • Collage • Drucken',
useFrontCamera: false,
enableLogs: true,
};
/**
* Load settings from persistent storage.
*/
export async function loadSettings(): Promise<AppSettings> {
try {
const content = await settingsFile.text();
const parsed = JSON.parse(content);
// Reset to defaults if the app version has changed (app updated)
if (parsed.appVersion !== APP_VERSION) {
console.log(`Settings version mismatch (old: ${parsed.appVersion}, new: ${APP_VERSION}). Resetting to default.`);
return DEFAULT_SETTINGS;
}
return { ...DEFAULT_SETTINGS, ...parsed };
} catch (e) {
console.error('Failed to load settings, using defaults:', e);
}
return DEFAULT_SETTINGS;
}
/**
* Save settings to persistent storage.
*/
export async function saveSettings(settings: AppSettings): Promise<void> {
try {
const content = JSON.stringify(settings, null, 2);
await settingsFile.write(content);
console.log('Settings saved successfully:', content);
} catch (e) {
console.error('Failed to save settings:', e);
throw e;
}
}