50 lines
1.6 KiB
Dart
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);
|
|
}
|
|
}
|