diff --git a/packages/neon/neon/lib/neon.dart b/packages/neon/neon/lib/neon.dart index 8b23e1b6..62d4e126 100644 --- a/packages/neon/neon/lib/neon.dart +++ b/packages/neon/neon/lib/neon.dart @@ -31,7 +31,7 @@ Future runNeon({ await NeonPlatform.setup(); await RequestManager.instance.initCache(); - await AppStorage.init(); + await NeonStorage.init(); final packageInfo = await PackageInfo.fromPlatform(); buildUserAgent(packageInfo); diff --git a/packages/neon/neon/lib/src/settings/models/storage.dart b/packages/neon/neon/lib/src/settings/models/storage.dart index 349845ab..885b4e67 100644 --- a/packages/neon/neon/lib/src/settings/models/storage.dart +++ b/packages/neon/neon/lib/src/settings/models/storage.dart @@ -15,22 +15,17 @@ abstract interface class SettingsStorage { Future remove(final String key); } -@immutable @internal -class AppStorage implements SettingsStorage { - const AppStorage(this._id); - - final String _id; - +final class NeonStorage { /// Shared preferences instance. /// - /// Use [reqireDatabase] to access it. + /// Use [database] to access it. /// Make sure it has been initialized wiht [init] before. static SharedPreferences? _sharedPreferences; /// Sets up the [SharedPreferences] instance. /// - /// Required to be called before accessing [reqireDatabase]. + /// Required to be called before accessing [database]. static Future init() async { if (_sharedPreferences != null) { return; @@ -40,37 +35,45 @@ class AppStorage implements SettingsStorage { } @visibleForTesting - static SharedPreferences get reqireDatabase { + static SharedPreferences get database { if (_sharedPreferences == null) { throw StateError( - 'AppStorage has not been initialized yet. Please make sure AppStorage.init() has been called before and completed.', + 'NeonStorage has not been initialized yet. Please make sure NeonStorage.init() has been called before and completed.', ); } return _sharedPreferences!; } +} + +@immutable +@internal +class AppStorage implements SettingsStorage { + const AppStorage(this._id); + + final String _id; String _formatKey(final String key) => '$_id-$key'; - bool containsKey(final String key) => reqireDatabase.containsKey(_formatKey(key)); + bool containsKey(final String key) => NeonStorage.database.containsKey(_formatKey(key)); @override - Future remove(final String key) => reqireDatabase.remove(_formatKey(key)); + Future remove(final String key) => NeonStorage.database.remove(_formatKey(key)); @override - String? getString(final String key) => reqireDatabase.getString(_formatKey(key)); + String? getString(final String key) => NeonStorage.database.getString(_formatKey(key)); @override - Future setString(final String key, final String value) => reqireDatabase.setString(_formatKey(key), value); + Future setString(final String key, final String value) => NeonStorage.database.setString(_formatKey(key), value); @override - bool? getBool(final String key) => reqireDatabase.getBool(_formatKey(key)); + bool? getBool(final String key) => NeonStorage.database.getBool(_formatKey(key)); @override - Future setBool(final String key, final bool value) => reqireDatabase.setBool(_formatKey(key), value); + Future setBool(final String key, final bool value) => NeonStorage.database.setBool(_formatKey(key), value); - List? getStringList(final String key) => reqireDatabase.getStringList(_formatKey(key)); + List? getStringList(final String key) => NeonStorage.database.getStringList(_formatKey(key)); Future setStringList(final String key, final List value) => - reqireDatabase.setStringList(_formatKey(key), value); + NeonStorage.database.setStringList(_formatKey(key), value); } diff --git a/packages/neon/neon/lib/src/utils/push_utils.dart b/packages/neon/neon/lib/src/utils/push_utils.dart index b3bce24f..d119e5c2 100644 --- a/packages/neon/neon/lib/src/utils/push_utils.dart +++ b/packages/neon/neon/lib/src/utils/push_utils.dart @@ -70,7 +70,7 @@ class PushUtils { } }, ); - await AppStorage.init(); + await NeonStorage.init(); final keypair = await loadRSAKeypair(const AppStorage(AppIDs.notifications)); diff --git a/packages/neon/neon/test/storage_test.dart b/packages/neon/neon/test/storage_test.dart index bda8df24..d88f8aea 100644 --- a/packages/neon/neon/test/storage_test.dart +++ b/packages/neon/neon/test/storage_test.dart @@ -4,11 +4,11 @@ import 'package:test/test.dart'; void main() { test('AppStorage', () async { - expect(() => AppStorage.reqireDatabase, throwsA(isA())); + expect(() => NeonStorage.database, throwsA(isA())); SharedPreferences.setMockInitialValues({}); - await AppStorage.init(); + await NeonStorage.init(); - expect(AppStorage.reqireDatabase, isA()); + expect(NeonStorage.database, isA()); }); }