Files
PeachDeployments/lib/Peach/memory/InternalMemory.dart
alvocool 38881d1fe1 Add app source and tests
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-11 10:15:30 +03:00

50 lines
1.6 KiB
Dart

import 'package:shared_preferences/shared_preferences.dart';
import '../about/internal/application/DeploymentRecord.dart';
import '../about/internal/application/ServerProfile.dart';
import 'ConfigStore.dart';
import 'ConnectInternalMemory.dart';
import 'DeploymentStore.dart';
/// The one concrete [ConnectInternalMemory]. Non-secret data goes to
/// shared_preferences via the two stores; passwords go to the OS keystore via
/// [SecretStore] — reads hydrate them back onto the profiles so callers only
/// ever see whole [ServerProfile]s.
class InternalMemory implements ConnectInternalMemory {
static const _themeKey = 'peach.thememode';
final ConfigStore _config = ConfigStore();
final DeploymentStore _deployments = DeploymentStore();
@override
Future<List<ServerProfile>> getServers() => _config.load();
@override
Future setServers(List<ServerProfile> servers) => _config.save(servers);
@override
Future deleteServerSecret(String serverId) => _config.deleteSecret(serverId);
@override
Future<List<DeploymentRecord>> getDeployments() => _deployments.load();
@override
Future<List<DeploymentRecord>> addDeployment(DeploymentRecord record) =>
_deployments.add(record);
@override
Future clearDeployments() => _deployments.clear();
@override
Future<String> getThemeMode() async {
final prefs = await SharedPreferences.getInstance();
return prefs.getString(_themeKey) ?? 'dark';
}
@override
Future setThemeMode(String mode) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_themeKey, mode);
}
}