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 {
static const String clientNamespace = 'im.fluffychat.store.clients';
static Future<List<Client>> getClients({
bool initialize = true,
required SharedPreferences store,
@ -113,7 +114,11 @@ abstract class ClientManager {
},
logLevel: kReleaseMode ? Level.warning : Level.verbose,
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: {
AuthenticationTypes.password,
AuthenticationTypes.sso,

@ -18,9 +18,15 @@ import 'cipher.dart';
import 'sqlcipher_stub.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;
try {
// unless it's the migration builder, always fall back onto Hive on Linux
if (PlatformInfos.isLinux && !isLegacy) throw UnimplementedError();
database = await _constructDatabase(client);
await database.open();
return database;
@ -34,15 +40,23 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
),
);
// Send error notification:
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
ClientManager.sendInitNotification(
l10n.initAppError,
l10n.databaseBuildErrorBody(
AppConfig.newIssueUrl.toString(),
e.toString(),
),
);
final bool hideErrorMessage = PlatformInfos.isLinux;
if (!hideErrorMessage) {
// Send error notification:
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
ClientManager.sendInitNotification(
l10n.initAppError,
l10n.databaseBuildErrorBody(
AppConfig.newIssueUrl.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);
}

Loading…
Cancel
Save