mirror of
https://github.com/jagandeepbrar/lunasea.git
synced 2026-08-31 04:32:32 +00:00
fix(config): Prevent database from being unloaded from memory on clear
This commit is contained in:
@@ -27,7 +27,7 @@ class Database {
|
||||
|
||||
void bootstrap() {
|
||||
clearAll();
|
||||
for (_BoxInstance instance in _BoxInstance.values) instance.setDefaults();
|
||||
for (_BoxInstance instance in _BoxInstance.values) instance.bootstrap();
|
||||
}
|
||||
|
||||
void clearAll() {
|
||||
@@ -96,7 +96,7 @@ extension _BoxInstanceExtension on _BoxInstance {
|
||||
}
|
||||
}
|
||||
|
||||
void setDefaults() {
|
||||
void bootstrap() {
|
||||
switch (this) {
|
||||
case _BoxInstance.ALERTS:
|
||||
break;
|
||||
@@ -122,6 +122,6 @@ class _BoxManager<E> {
|
||||
_BoxManager(this._instance);
|
||||
|
||||
Box<E> get box => Hive.box<E>(_instance.key);
|
||||
Future<int> clear() async => box.clear();
|
||||
Future<void> clear() async => box.keys.forEach((k) => box.delete(k));
|
||||
Future<int> size() async => box.length;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@ import 'package:lunasea/modules/settings.dart';
|
||||
|
||||
class LunaProfile {
|
||||
/// Returns a list of the profiles, sorted by their lowercase key/display name.
|
||||
List<String?> profilesList() => Database.profiles.box.keys
|
||||
.map<String?>((profile) => profile as String?)
|
||||
List<String> profilesList() => Database.profiles.box.keys
|
||||
.map<String>((profile) => profile as String)
|
||||
.toList()
|
||||
..sort((a, b) => a!.toLowerCase().compareTo(b!.toLowerCase()));
|
||||
..sort((a, b) => a.toLowerCase().compareTo(b.toLowerCase()));
|
||||
|
||||
/// Safely change profiles.
|
||||
///
|
||||
|
||||
@@ -22,9 +22,10 @@ class LunaEncryption {
|
||||
return _encrypted;
|
||||
} catch (error, stack) {
|
||||
LunaLogger().error(
|
||||
'Failed to decrypted "$data" using the key "$encryptionKey"',
|
||||
error,
|
||||
stack);
|
||||
'Failed to decrypted "$data" using the key "$encryptionKey"',
|
||||
error,
|
||||
stack,
|
||||
);
|
||||
}
|
||||
return ENCRYPTION_FAILURE;
|
||||
}
|
||||
@@ -41,9 +42,12 @@ class LunaEncryption {
|
||||
IV iv = IV.fromLength(_IV_LENGTH);
|
||||
final _encrypter = Encrypter(AES(key));
|
||||
return _encrypter.decrypt64(data, iv: iv);
|
||||
} catch (error) {
|
||||
LunaLogger().warning('LunaEncryption', 'decrypt',
|
||||
'Failed to decrypted "$data" using the key "$decryptionKey"');
|
||||
} catch (error, stack) {
|
||||
LunaLogger().error(
|
||||
'Failed to decrypted "$data" using the key "$decryptionKey"',
|
||||
error,
|
||||
stack,
|
||||
);
|
||||
}
|
||||
return ENCRYPTION_FAILURE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user