diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index 3e043a44..7e0b904d 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -104,8 +104,8 @@ abstract class ClientManager { EventTypes.RoomPowerLevels, }, logLevel: kReleaseMode ? Level.warning : Level.verbose, - databaseBuilder: FlutterFluffyBoxDatabase.databaseBuilder, - legacyDatabaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder, + databaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder, + legacyDatabaseBuilder: FlutterFluffyBoxDatabase.databaseBuilder, supportedLoginTypes: { AuthenticationTypes.password, if (PlatformInfos.isMobile || diff --git a/lib/utils/matrix_sdk_extensions.dart/flutter_hive_collections_database.dart b/lib/utils/matrix_sdk_extensions.dart/flutter_hive_collections_database.dart index f8d41dd6..aee23b20 100644 --- a/lib/utils/matrix_sdk_extensions.dart/flutter_hive_collections_database.dart +++ b/lib/utils/matrix_sdk_extensions.dart/flutter_hive_collections_database.dart @@ -21,7 +21,7 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase { key: key, ); - static const String _cipherStorageKey = 'database_encryption_key'; + static const String _cipherStorageKey = 'hive_encryption_key'; static Future databaseBuilder( Client client) async { @@ -71,7 +71,8 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase { } catch (e, s) { Logs().w('Unable to open Hive. Delete database and storage key...', e, s); const FlutterSecureStorage().delete(key: _cipherStorageKey); - await db.clear(); + await db.clear().catchError((_) {}); + await Hive.deleteFromDisk(); rethrow; } Logs().d('Hive is ready'); @@ -96,10 +97,10 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase { } } // do not destroy your stable FluffyChat in debug mode - if (kDebugMode) { - directory = Directory(directory.uri.resolve('debug').toFilePath()); - directory.create(recursive: true); - } + directory = Directory(directory.uri + .resolve(kDebugMode ? 'hive_debug' : 'hive') + .toFilePath()); + directory.create(recursive: true); path = directory.path; } return path; diff --git a/pubspec.lock b/pubspec.lock index 2bf2fcf5..f063036a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -839,7 +839,7 @@ packages: name: hive url: "https://pub.dartlang.org" source: hosted - version: "2.2.1" + version: "2.2.3" hive_flutter: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 51c9ad50..95db366a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -52,7 +52,7 @@ dependencies: future_loading_dialog: ^0.2.3 geolocator: ^7.6.2 handy_window: ^0.1.6 - hive: 2.2.1 # Newer version will break migration from hive collections + hive: ^2.2.3 hive_flutter: ^1.1.0 http: ^0.13.4 image: ^3.1.1