diff --git a/lib/utils/persisted_state_notifier.dart b/lib/utils/persisted_state_notifier.dart index 60b8d2fd1..9f444c1b7 100644 --- a/lib/utils/persisted_state_notifier.dart +++ b/lib/utils/persisted_state_notifier.dart @@ -4,6 +4,8 @@ import 'dart:convert'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:hive/hive.dart'; +import 'package:shared_preferences/shared_preferences.dart'; +import 'package:spotube/utils/platform.dart'; import 'package:spotube/utils/primitive_utils.dart'; const secureStorage = FlutterSecureStorage( @@ -32,22 +34,38 @@ abstract class PersistedStateNotifier extends StateNotifier { static late LazyBox _box; static late LazyBox _encryptedBox; + static Future read(String key) async { + final localStorage = await SharedPreferences.getInstance(); + if (kIsMacOS || kIsIOS) { + return localStorage.getString(key); + } else { + return secureStorage.read(key: key); + } + } + + static Future write(String key, String value) async { + final localStorage = await SharedPreferences.getInstance(); + if (kIsMacOS || kIsIOS) { + await localStorage.setString(key, value); + return; + } else { + return secureStorage.write(key: key, value: value); + } + } + static Future initializeBoxes() async { - String? boxName = await secureStorage.read(key: kKeyBoxName); + String? boxName = await read(kKeyBoxName); if (boxName == null) { boxName = "spotube-${PrimitiveUtils.uuid.v4()}"; - await secureStorage.write(key: kKeyBoxName, value: boxName); + await write(kKeyBoxName, boxName); } - String? encryptionKey = await secureStorage.read(key: getBoxKey(boxName)); + String? encryptionKey = await read(getBoxKey(boxName)); if (encryptionKey == null) { encryptionKey = base64Url.encode(Hive.generateSecureKey()); - await secureStorage.write( - key: getBoxKey(boxName), - value: encryptionKey, - ); + await write(getBoxKey(boxName), encryptionKey); } _encryptedBox = await Hive.openLazyBox( diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements index e016b40d7..2788f09ee 100644 --- a/macos/Runner/DebugProfile.entitlements +++ b/macos/Runner/DebugProfile.entitlements @@ -10,7 +10,8 @@ com.apple.security.network.server - keychain-access-groups - + + \ No newline at end of file diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements index cdf193e51..db95233f6 100644 --- a/macos/Runner/Release.entitlements +++ b/macos/Runner/Release.entitlements @@ -8,7 +8,8 @@ com.apple.security.network.server - keychain-access-groups - + + \ No newline at end of file