mirror of
https://github.com/dz0ny/meshcore-sar.git
synced 2026-10-10 12:15:04 +00:00
chore: Initial commit
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XPovRHpejR4zRxuhjY4Qs3
This commit is contained in:
54
lib/services/profiles_feature_service.dart
Normal file
54
lib/services/profiles_feature_service.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class ProfilesFeatureService {
|
||||
static const String enabledKey = 'profiles_enabled';
|
||||
|
||||
static Future<bool> isEnabled() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
return prefs.getBool(enabledKey) ?? true;
|
||||
}
|
||||
|
||||
static Future<void> setEnabled(bool enabled) async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setBool(enabledKey, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
class ProfileStorageScope {
|
||||
static bool _profilesEnabled = true;
|
||||
static String _activeProfileId = 'default';
|
||||
|
||||
static Future<void> bootstrap({
|
||||
required bool profilesEnabled,
|
||||
required String activeProfileId,
|
||||
}) async {
|
||||
_profilesEnabled = profilesEnabled;
|
||||
_activeProfileId = activeProfileId;
|
||||
}
|
||||
|
||||
static void setScope({
|
||||
required bool profilesEnabled,
|
||||
required String activeProfileId,
|
||||
}) {
|
||||
_profilesEnabled = profilesEnabled;
|
||||
_activeProfileId = activeProfileId;
|
||||
}
|
||||
|
||||
static bool get profilesEnabled => _profilesEnabled;
|
||||
static String get activeProfileId => _activeProfileId;
|
||||
|
||||
static String? get effectiveNamespace {
|
||||
if (!_profilesEnabled || _activeProfileId == 'default') {
|
||||
return null;
|
||||
}
|
||||
return _activeProfileId;
|
||||
}
|
||||
|
||||
static String scopedKey(String baseKey, {String? namespace}) {
|
||||
final scope = namespace ?? effectiveNamespace;
|
||||
if (scope == null || scope.isEmpty) {
|
||||
return baseKey;
|
||||
}
|
||||
return 'profile.$scope.$baseKey';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user