diff --git a/lib/utils/legacy_famedlysdk_store.dart b/lib/utils/legacy_famedlysdk_store.dart index ea8f5c6c..45b0dba2 100644 --- a/lib/utils/legacy_famedlysdk_store.dart +++ b/lib/utils/legacy_famedlysdk_store.dart @@ -1,15 +1,12 @@ import 'dart:async'; import 'dart:core'; -import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:localstorage/localstorage.dart'; import 'package:path_provider/path_provider.dart'; import 'package:fluffychat/utils/platform_infos.dart'; -// import 'package:flutter_secure_storage/flutter_secure_storage.dart'; - // see https://github.com/mogol/flutter_secure_storage/issues/161#issuecomment-704578453 class AsyncMutex { Completer? _completer; @@ -31,41 +28,31 @@ class AsyncMutex { } class Store { - FlutterSecureStorage? secureStorage; - LocalStorage? storage; + final FlutterSecureStorage? secureStorage; static final _mutex = AsyncMutex(); + Store() + : secureStorage = + PlatformInfos.isMobile ? const FlutterSecureStorage() : null; + Future _setupLocalStorage() async { - if (PlatformInfos.isMobile) { - if (PlatformInfos.isAndroid) { - return DeviceInfoPlugin().androidInfo.then((info) { - if ((info.version.sdkInt ?? 16) >= 19) { - secureStorage = const FlutterSecureStorage(); - } - }); - } else { - secureStorage = const FlutterSecureStorage(); - } - } else { - if (storage == null) { - final directory = PlatformInfos.isBetaDesktop - ? await getApplicationSupportDirectory() - : (PlatformInfos.isWeb - ? null - : await getApplicationDocumentsDirectory()); - storage = LocalStorage('LocalStorage', directory?.path); - await storage!.ready; - } + if (storage == null) { + final directory = PlatformInfos.isBetaDesktop + ? await getApplicationSupportDirectory() + : (PlatformInfos.isWeb + ? null + : await getApplicationDocumentsDirectory()); + storage = LocalStorage('LocalStorage', directory?.path); + await storage!.ready; } } Future getItem(String key) async { - final storage = this.storage; - if (!PlatformInfos.isMobile && storage != null) { + if (!PlatformInfos.isMobile) { await _setupLocalStorage(); try { - return storage.getItem(key)?.toString(); + return storage!.getItem(key)?.toString(); } catch (_) { return null; } @@ -90,8 +77,8 @@ class Store { } Future setItem(String key, String? value) async { - await _setupLocalStorage(); if (!PlatformInfos.isMobile) { + await _setupLocalStorage(); return await storage!.setItem(key, value); } try {