import 'package:shared_preferences/shared_preferences.dart'; import 'models.dart'; class AppStorage { static const _hostsKey = 'remote_hosts_v1'; static const _localeKey = 'locale'; static const _widthKey = 'desktop_width'; static const _heightKey = 'desktop_height'; static const _fpsKey = 'desktop_fps'; Future> loadHosts() async { final preferences = await SharedPreferences.getInstance(); final encoded = preferences.getString(_hostsKey); if (encoded == null) return const []; try { return RemoteHost.decodeList(encoded); } on Object { return const []; } } Future saveHosts(List hosts) async { final preferences = await SharedPreferences.getInstance(); await preferences.setString(_hostsKey, RemoteHost.encodeList(hosts)); } Future loadSettings() async { final preferences = await SharedPreferences.getInstance(); return AppSettings( languageCode: preferences.getString(_localeKey), maxWidth: preferences.getInt(_widthKey) ?? 1280, maxHeight: preferences.getInt(_heightKey) ?? 720, framesPerSecond: preferences.getInt(_fpsKey) ?? 15, ); } Future saveSettings(AppSettings settings) async { final preferences = await SharedPreferences.getInstance(); if (settings.languageCode == null) { await preferences.remove(_localeKey); } else { await preferences.setString(_localeKey, settings.languageCode!); } await preferences.setInt(_widthKey, settings.maxWidth); await preferences.setInt(_heightKey, settings.maxHeight); await preferences.setInt(_fpsKey, settings.framesPerSecond); } }