chore: Revert legacy store changes
This commit is contained in:
parent
de6741e43c
commit
c7ebc6d63d
|
@ -1,15 +1,12 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
|
|
||||||
import 'package:device_info_plus/device_info_plus.dart';
|
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:localstorage/localstorage.dart';
|
import 'package:localstorage/localstorage.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/utils/platform_infos.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
|
// see https://github.com/mogol/flutter_secure_storage/issues/161#issuecomment-704578453
|
||||||
class AsyncMutex {
|
class AsyncMutex {
|
||||||
Completer<void>? _completer;
|
Completer<void>? _completer;
|
||||||
|
@ -31,41 +28,31 @@ class AsyncMutex {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Store {
|
class Store {
|
||||||
FlutterSecureStorage? secureStorage;
|
|
||||||
|
|
||||||
LocalStorage? storage;
|
LocalStorage? storage;
|
||||||
|
final FlutterSecureStorage? secureStorage;
|
||||||
static final _mutex = AsyncMutex();
|
static final _mutex = AsyncMutex();
|
||||||
|
|
||||||
|
Store()
|
||||||
|
: secureStorage =
|
||||||
|
PlatformInfos.isMobile ? const FlutterSecureStorage() : null;
|
||||||
|
|
||||||
Future<void> _setupLocalStorage() async {
|
Future<void> _setupLocalStorage() async {
|
||||||
if (PlatformInfos.isMobile) {
|
if (storage == null) {
|
||||||
if (PlatformInfos.isAndroid) {
|
final directory = PlatformInfos.isBetaDesktop
|
||||||
return DeviceInfoPlugin().androidInfo.then((info) {
|
? await getApplicationSupportDirectory()
|
||||||
if ((info.version.sdkInt ?? 16) >= 19) {
|
: (PlatformInfos.isWeb
|
||||||
secureStorage = const FlutterSecureStorage();
|
? null
|
||||||
}
|
: await getApplicationDocumentsDirectory());
|
||||||
});
|
storage = LocalStorage('LocalStorage', directory?.path);
|
||||||
} else {
|
await storage!.ready;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String?> getItem(String key) async {
|
Future<String?> getItem(String key) async {
|
||||||
final storage = this.storage;
|
if (!PlatformInfos.isMobile) {
|
||||||
if (!PlatformInfos.isMobile && storage != null) {
|
|
||||||
await _setupLocalStorage();
|
await _setupLocalStorage();
|
||||||
try {
|
try {
|
||||||
return storage.getItem(key)?.toString();
|
return storage!.getItem(key)?.toString();
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -90,8 +77,8 @@ class Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> setItem(String key, String? value) async {
|
Future<void> setItem(String key, String? value) async {
|
||||||
await _setupLocalStorage();
|
|
||||||
if (!PlatformInfos.isMobile) {
|
if (!PlatformInfos.isMobile) {
|
||||||
|
await _setupLocalStorage();
|
||||||
return await storage!.setItem(key, value);
|
return await storage!.setItem(key, value);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue