mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
Merge branch 'master' into dev
This commit is contained in:
commit
5536b951cf
@ -4,6 +4,8 @@ import 'dart:convert';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
import 'package:hive/hive.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';
|
import 'package:spotube/utils/primitive_utils.dart';
|
||||||
|
|
||||||
const secureStorage = FlutterSecureStorage(
|
const secureStorage = FlutterSecureStorage(
|
||||||
@ -32,22 +34,38 @@ abstract class PersistedStateNotifier<T> extends StateNotifier<T> {
|
|||||||
static late LazyBox _box;
|
static late LazyBox _box;
|
||||||
static late LazyBox _encryptedBox;
|
static late LazyBox _encryptedBox;
|
||||||
|
|
||||||
|
static Future<String?> read(String key) async {
|
||||||
|
final localStorage = await SharedPreferences.getInstance();
|
||||||
|
if (kIsMacOS || kIsIOS) {
|
||||||
|
return localStorage.getString(key);
|
||||||
|
} else {
|
||||||
|
return secureStorage.read(key: key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Future<void> 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<void> initializeBoxes() async {
|
static Future<void> initializeBoxes() async {
|
||||||
String? boxName = await secureStorage.read(key: kKeyBoxName);
|
String? boxName = await read(kKeyBoxName);
|
||||||
|
|
||||||
if (boxName == null) {
|
if (boxName == null) {
|
||||||
boxName = "spotube-${PrimitiveUtils.uuid.v4()}";
|
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) {
|
if (encryptionKey == null) {
|
||||||
encryptionKey = base64Url.encode(Hive.generateSecureKey());
|
encryptionKey = base64Url.encode(Hive.generateSecureKey());
|
||||||
await secureStorage.write(
|
await write(getBoxKey(boxName), encryptionKey);
|
||||||
key: getBoxKey(boxName),
|
|
||||||
value: encryptionKey,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_encryptedBox = await Hive.openLazyBox(
|
_encryptedBox = await Hive.openLazyBox(
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
<true />
|
<true />
|
||||||
<key>com.apple.security.network.server</key>
|
<key>com.apple.security.network.server</key>
|
||||||
<true />
|
<true />
|
||||||
<key>keychain-access-groups</key>
|
<!-- Requires Certification -->
|
||||||
<array />
|
<!-- <key>keychain-access-groups</key>
|
||||||
|
<array /> -->
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
@ -8,7 +8,8 @@
|
|||||||
<true />
|
<true />
|
||||||
<key>com.apple.security.network.server</key>
|
<key>com.apple.security.network.server</key>
|
||||||
<true />
|
<true />
|
||||||
<key>keychain-access-groups</key>
|
<!-- Requires Certification -->
|
||||||
<array />
|
<!-- <key>keychain-access-groups</key>
|
||||||
|
<array /> -->
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
Loading…
Reference in New Issue
Block a user