73 lines
2.1 KiB
TypeScript
73 lines
2.1 KiB
TypeScript
import { File, Paths } from 'expo-file-system';
|
||
import * as FileSystem from 'expo-file-system/legacy';
|
||
import { FRAMES } from '../data/frames';
|
||
|
||
export interface AppSettings {
|
||
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, 2–5 = burst
|
||
burstIntervalSec: number; // seconds between burst shots
|
||
// Welcome screen text
|
||
welcomeText: string;
|
||
}
|
||
|
||
const settingsFile = new File(Paths.document, 'settings.json');
|
||
|
||
const DEFAULT_SETTINGS: AppSettings = {
|
||
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!',
|
||
};
|
||
|
||
/**
|
||
* Load settings from persistent storage.
|
||
*/
|
||
export async function loadSettings(): Promise<AppSettings> {
|
||
try {
|
||
if (settingsFile.exists) {
|
||
const content = await settingsFile.text();
|
||
const parsed = JSON.parse(content);
|
||
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 FileSystem.writeAsStringAsync(settingsFile.uri, content);
|
||
console.log('Settings saved successfully:', content);
|
||
} catch (e) {
|
||
console.error('Failed to save settings:', e);
|
||
throw e;
|
||
}
|
||
}
|