diff --git a/lib/utils/client_manager.dart b/lib/utils/client_manager.dart index 72f28587..732ec888 100644 --- a/lib/utils/client_manager.dart +++ b/lib/utils/client_manager.dart @@ -5,8 +5,8 @@ import 'package:flutter/foundation.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:matrix/encryption/utils/key_verification.dart'; import 'package:matrix/matrix.dart'; -import 'package:sembast/sembast.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:sembast/sembast.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'famedlysdk_store.dart'; @@ -80,7 +80,7 @@ abstract class ClientManager { KeyVerificationMethod.emoji, }, importantStateEvents: {'im.ponies.room_emotes'}, - databaseBuilder: FluffyBoxDatabase.databaseBuilder, + databaseBuilder: FlutterFluffyBoxDatabase.databaseBuilder, legacyDatabaseBuilder: FlutterMatrixSembastDatabase.databaseBuilder, supportedLoginTypes: { AuthenticationTypes.password, diff --git a/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart b/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart index b1dd1c74..f5eb46cc 100644 --- a/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart +++ b/lib/utils/matrix_sdk_extensions.dart/fluffybox_database.dart @@ -3,27 +3,23 @@ import 'dart:typed_data'; import 'package:flutter/foundation.dart' hide Key; import 'package:flutter/services.dart'; -import 'package:idb_shim/idb_browser.dart'; -import 'package:idb_shim/idb.dart' hide Event; -import 'package:sqflite/sqflite.dart' as sqflite; import 'package:encrypt/encrypt.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; -import 'package:idb_sqflite/idb_sqflite.dart'; import 'package:matrix/matrix.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:sqflite/sqflite.dart' as sqflite; import '../platform_infos.dart'; -class FluffyBoxDatabase extends MatrixIndexedDatabase { - FluffyBoxDatabase( +class FlutterFluffyBoxDatabase extends FluffyBoxDatabase { + FlutterFluffyBoxDatabase( String name, { String path, - IdbFactory dbFactory, + Future Function() openSqlDatabase, }) : super( name, - path, - factory: dbFactory, + openSqlDatabase: openSqlDatabase, ); static const String _cipherStorageKey = 'database_encryption_key'; @@ -54,21 +50,17 @@ class FluffyBoxDatabase extends MatrixIndexedDatabase { } final db = FluffyBoxDatabase( - 'FluffyBox-${client.clientName}', - path: await _findDatabasePath(client), - dbFactory: factory, + 'fluffybox_${client.clientName.replaceAll(' ', '_').toLowerCase()}', + openSqlDatabase: () => _openSqlDatabase(client), ); await db.open(); Logs().d('FluffyBox is ready'); return db; } - static IdbFactory get factory { - if (kIsWeb) return idbFactoryBrowser; - if (Platform.isAndroid || Platform.isIOS) { - return getIdbFactorySqflite(sqflite.databaseFactory); - } - return idbFactoryNative; + static Future _openSqlDatabase(Client client) async { + final path = await _findDatabasePath(client); + return await sqflite.openDatabase(path); } static Future _findDatabasePath(Client client) async { @@ -84,7 +76,8 @@ class FluffyBoxDatabase extends MatrixIndexedDatabase { directory = Directory.current; } } - path = '${directory.path}${client.clientName}.db'; + path = + '${directory.path}${client.clientName.replaceAll(' ', '-')}.sqflite'; } return path; } diff --git a/pubspec.lock b/pubspec.lock index d9f7bed1..5f6fe622 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -351,6 +351,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.2" + fluffybox: + dependency: transitive + description: + name: fluffybox + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0" flutter: dependency: "direct main" description: flutter @@ -782,7 +789,7 @@ packages: description: path: "." ref: "krille/idb" - resolved-ref: "5996f6bb01ba1110c1f8fb84c39dd6bcf0d2900a" + resolved-ref: aee9bbf8afd1114a25ad547822d2e3eda6c73c83 url: "https://gitlab.com/famedly/company/frontend/famedlysdk.git" source: git version: "0.7.0-nullsafety.6" @@ -1317,7 +1324,14 @@ packages: name: sqflite_common url: "https://pub.dartlang.org" source: hosted - version: "2.0.0+2" + version: "2.0.1+1" + sqflite_common_ffi: + dependency: transitive + description: + name: sqflite_common_ffi + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.0" sqflite_sqlcipher: dependency: "direct main" description: @@ -1325,6 +1339,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + sqlite3: + dependency: transitive + description: + name: sqlite3 + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" stack_trace: dependency: transitive description: @@ -1669,5 +1690,5 @@ packages: source: hosted version: "3.1.0" sdks: - dart: ">=2.14.0 <3.0.0" + dart: ">=2.14.4 <3.0.0" flutter: ">=2.5.0"