fix: migrate back to Hive on Linux

Signed-off-by: The one with the braid <info@braid.business>
pull/1010/head
The one with the braid 11 months ago
parent 9a8f604fc1
commit 1026d4c721

@ -22,6 +22,7 @@ import 'matrix_sdk_extensions/flutter_matrix_dart_sdk_database/builder.dart';
abstract class ClientManager { abstract class ClientManager {
static const String clientNamespace = 'im.fluffychat.store.clients'; static const String clientNamespace = 'im.fluffychat.store.clients';
static Future<List<Client>> getClients({ static Future<List<Client>> getClients({
bool initialize = true, bool initialize = true,
required SharedPreferences store, required SharedPreferences store,
@ -113,7 +114,11 @@ abstract class ClientManager {
}, },
logLevel: kReleaseMode ? Level.warning : Level.verbose, logLevel: kReleaseMode ? Level.warning : Level.verbose,
databaseBuilder: flutterMatrixSdkDatabaseBuilder, databaseBuilder: flutterMatrixSdkDatabaseBuilder,
legacyDatabaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder, // workaround : migrate back from SQLite to Hive on Linux
// Related : https://github.com/krille-chan/fluffychat/issues/972
legacyDatabaseBuilder: PlatformInfos.isLinux
? (client) => flutterMatrixSdkDatabaseBuilder(client, isLegacy: true)
: FlutterHiveCollectionsDatabase.databaseBuilder,
supportedLoginTypes: { supportedLoginTypes: {
AuthenticationTypes.password, AuthenticationTypes.password,
AuthenticationTypes.sso, AuthenticationTypes.sso,

@ -18,9 +18,15 @@ import 'cipher.dart';
import 'sqlcipher_stub.dart' import 'sqlcipher_stub.dart'
if (dart.library.io) 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart'; if (dart.library.io) 'package:sqlcipher_flutter_libs/sqlcipher_flutter_libs.dart';
Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async { Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(
Client client, {
bool isLegacy = false,
}) async {
MatrixSdkDatabase? database; MatrixSdkDatabase? database;
try { try {
// unless it's the migration builder, always fall back onto Hive on Linux
if (PlatformInfos.isLinux && !isLegacy) throw UnimplementedError();
database = await _constructDatabase(client); database = await _constructDatabase(client);
await database.open(); await database.open();
return database; return database;
@ -34,6 +40,8 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
), ),
); );
final bool hideErrorMessage = PlatformInfos.isLinux;
if (!hideErrorMessage) {
// Send error notification: // Send error notification:
final l10n = lookupL10n(PlatformDispatcher.instance.locale); final l10n = lookupL10n(PlatformDispatcher.instance.locale);
ClientManager.sendInitNotification( ClientManager.sendInitNotification(
@ -43,6 +51,12 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
e.toString(), e.toString(),
), ),
); );
} else {
Logs().w(
'Linux database error using SQfLite. Due to many issues in this implementation, falling back to Hive.',
e,
);
}
return FlutterHiveCollectionsDatabase.databaseBuilder(client); return FlutterHiveCollectionsDatabase.databaseBuilder(client);
} }

Loading…
Cancel
Save