feat(app): configure and safely switch multi-address servers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../core/servers/server_scope.dart';
|
||||
|
||||
import '../domain/attention_models.dart';
|
||||
|
||||
@@ -20,7 +21,9 @@ abstract interface class AttentionStore {
|
||||
/// disk returns null/false instead of throwing into the caller's frame. Only the
|
||||
/// documented [attentionStorageKey] is touched, never the legacy web key.
|
||||
class SharedPreferencesAttentionStore implements AttentionStore {
|
||||
const SharedPreferencesAttentionStore();
|
||||
const SharedPreferencesAttentionStore({this.serverId = ''});
|
||||
final String serverId;
|
||||
String get _key => scopedServerKey(attentionStorageKey, serverId);
|
||||
|
||||
Future<SharedPreferences?> _preferences() async {
|
||||
try {
|
||||
@@ -35,7 +38,7 @@ class SharedPreferencesAttentionStore implements AttentionStore {
|
||||
final preferences = await _preferences();
|
||||
if (preferences == null) return null;
|
||||
try {
|
||||
return preferences.getString(attentionStorageKey);
|
||||
return preferences.getString(_key);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
@@ -46,7 +49,7 @@ class SharedPreferencesAttentionStore implements AttentionStore {
|
||||
final preferences = await _preferences();
|
||||
if (preferences == null) return false;
|
||||
try {
|
||||
return await preferences.setString(attentionStorageKey, value);
|
||||
return await preferences.setString(_key, value);
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user