fix: migrate back to Hive on Linux
Signed-off-by: The one with the braid <info@braid.business>
This commit is contained in:
parent
9a8f604fc1
commit
1026d4c721
2 changed files with 30 additions and 11 deletions
|
|
@ -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,15 +40,23 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Send error notification:
|
final bool hideErrorMessage = PlatformInfos.isLinux;
|
||||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
if (!hideErrorMessage) {
|
||||||
ClientManager.sendInitNotification(
|
// Send error notification:
|
||||||
l10n.initAppError,
|
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||||
l10n.databaseBuildErrorBody(
|
ClientManager.sendInitNotification(
|
||||||
AppConfig.newIssueUrl.toString(),
|
l10n.initAppError,
|
||||||
e.toString(),
|
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);
|
return FlutterHiveCollectionsDatabase.databaseBuilder(client);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue