mirror of
https://github.com/krille-chan/fluffychat
synced 2024-10-05 15:12:44 +00:00
feat: Try out FluffyBox 2 database
This commit is contained in:
parent
07c9b832cb
commit
129c1ab697
9 changed files with 135 additions and 15 deletions
|
@ -44,7 +44,7 @@ android {
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "chat.fluffy.fluffychat"
|
applicationId "chat.fluffy.fluffychat"
|
||||||
minSdkVersion 19
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 33
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|
1
android/app/proguard-rules.pro
vendored
Normal file
1
android/app/proguard-rules.pro
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
-keep class net.sqlcipher.** { *; }
|
|
@ -10,6 +10,7 @@ import 'package:fluffychat/utils/custom_http_client.dart';
|
||||||
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
import 'package:fluffychat/utils/custom_image_resizer.dart';
|
||||||
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
import 'package:fluffychat/utils/matrix_sdk_extensions/flutter_hive_collections_database.dart';
|
||||||
import 'package:fluffychat/utils/platform_infos.dart';
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
import 'matrix_sdk_extensions/flutter_matrix_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';
|
||||||
|
@ -102,7 +103,8 @@ abstract class ClientManager {
|
||||||
EventTypes.RoomPowerLevels,
|
EventTypes.RoomPowerLevels,
|
||||||
},
|
},
|
||||||
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
logLevel: kReleaseMode ? Level.warning : Level.verbose,
|
||||||
databaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder,
|
databaseBuilder: flutterMatrixSdkDatabaseBuilder,
|
||||||
|
legacyDatabaseBuilder: FlutterHiveCollectionsDatabase.databaseBuilder,
|
||||||
supportedLoginTypes: {
|
supportedLoginTypes: {
|
||||||
AuthenticationTypes.password,
|
AuthenticationTypes.password,
|
||||||
AuthenticationTypes.sso,
|
AuthenticationTypes.sso,
|
||||||
|
|
|
@ -64,7 +64,7 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase {
|
||||||
|
|
||||||
final db = FlutterHiveCollectionsDatabase(
|
final db = FlutterHiveCollectionsDatabase(
|
||||||
'hive_collections_${client.clientName.replaceAll(' ', '_').toLowerCase()}',
|
'hive_collections_${client.clientName.replaceAll(' ', '_').toLowerCase()}',
|
||||||
await _findDatabasePath(client),
|
await findDatabasePath(client),
|
||||||
key: hiverCipher,
|
key: hiverCipher,
|
||||||
);
|
);
|
||||||
try {
|
try {
|
||||||
|
@ -80,7 +80,7 @@ class FlutterHiveCollectionsDatabase extends HiveCollectionsDatabase {
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<String> _findDatabasePath(Client client) async {
|
static Future<String> findDatabasePath(Client client) async {
|
||||||
String path = client.clientName;
|
String path = client.clientName;
|
||||||
if (!kIsWeb) {
|
if (!kIsWeb) {
|
||||||
Directory directory;
|
Directory directory;
|
||||||
|
|
|
@ -0,0 +1,86 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart' as ffi;
|
||||||
|
import 'package:sqflite_sqlcipher/sqflite.dart';
|
||||||
|
import 'package:universal_html/html.dart' as html;
|
||||||
|
|
||||||
|
import 'package:fluffychat/utils/platform_infos.dart';
|
||||||
|
|
||||||
|
Future<MatrixSdkDatabase> flutterMatrixSdkDatabaseBuilder(Client client) async {
|
||||||
|
final database = await _constructDatabase(client);
|
||||||
|
await database.open();
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<MatrixSdkDatabase> _constructDatabase(Client client) async {
|
||||||
|
if (kIsWeb) {
|
||||||
|
html.window.navigator.storage?.persist();
|
||||||
|
return MatrixSdkDatabase(client.clientName);
|
||||||
|
}
|
||||||
|
if (PlatformInfos.isDesktop) {
|
||||||
|
final path = await getApplicationSupportDirectory();
|
||||||
|
return MatrixSdkDatabase(
|
||||||
|
client.clientName,
|
||||||
|
database: await ffi.databaseFactoryFfi.openDatabase(
|
||||||
|
'$path/${client.clientName}',
|
||||||
|
),
|
||||||
|
maxFileSize: 1024 * 1024 * 10,
|
||||||
|
fileStoragePath: path,
|
||||||
|
deleteFilesAfterDuration: const Duration(days: 30),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final path = await getDatabasesPath();
|
||||||
|
const passwordStorageKey = 'database_password';
|
||||||
|
String? password;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Workaround for secure storage is calling Platform.operatingSystem on web
|
||||||
|
if (kIsWeb) throw MissingPluginException();
|
||||||
|
|
||||||
|
const secureStorage = FlutterSecureStorage();
|
||||||
|
final containsEncryptionKey =
|
||||||
|
await secureStorage.read(key: passwordStorageKey) != null;
|
||||||
|
if (!containsEncryptionKey) {
|
||||||
|
final rng = Random.secure();
|
||||||
|
final list = Uint8List(32);
|
||||||
|
list.setAll(0, Iterable.generate(list.length, (i) => rng.nextInt(256)));
|
||||||
|
final newPassword = base64UrlEncode(list);
|
||||||
|
await secureStorage.write(
|
||||||
|
key: passwordStorageKey,
|
||||||
|
value: newPassword,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// workaround for if we just wrote to the key and it still doesn't exist
|
||||||
|
password = await secureStorage.read(key: passwordStorageKey);
|
||||||
|
if (password == null) throw MissingPluginException();
|
||||||
|
} on MissingPluginException catch (_) {
|
||||||
|
const FlutterSecureStorage()
|
||||||
|
.delete(key: passwordStorageKey)
|
||||||
|
.catchError((_) {});
|
||||||
|
Logs().i('Database encryption is not supported on this platform');
|
||||||
|
} catch (e, s) {
|
||||||
|
const FlutterSecureStorage()
|
||||||
|
.delete(key: passwordStorageKey)
|
||||||
|
.catchError((_) {});
|
||||||
|
Logs().w('Unable to init database encryption', e, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return MatrixSdkDatabase(
|
||||||
|
client.clientName,
|
||||||
|
database: await openDatabase(
|
||||||
|
'$path/${client.clientName}',
|
||||||
|
password: password,
|
||||||
|
),
|
||||||
|
maxFileSize: 1024 * 1024 * 10,
|
||||||
|
fileStoragePath: await getTemporaryDirectory(),
|
||||||
|
deleteFilesAfterDuration: const Duration(days: 30),
|
||||||
|
);
|
||||||
|
}
|
|
@ -28,6 +28,7 @@ import record_macos
|
||||||
import share_plus
|
import share_plus
|
||||||
import shared_preferences_foundation
|
import shared_preferences_foundation
|
||||||
import sqflite
|
import sqflite
|
||||||
|
import sqflite_sqlcipher
|
||||||
import url_launcher_macos
|
import url_launcher_macos
|
||||||
import video_compress
|
import video_compress
|
||||||
import video_player_avfoundation
|
import video_player_avfoundation
|
||||||
|
@ -58,6 +59,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||||
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
||||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||||
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
|
||||||
|
SqfliteSqlCipherPlugin.register(with: registry.registrar(forPlugin: "SqfliteSqlCipherPlugin"))
|
||||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||||
VideoCompressPlugin.register(with: registry.registrar(forPlugin: "VideoCompressPlugin"))
|
VideoCompressPlugin.register(with: registry.registrar(forPlugin: "VideoCompressPlugin"))
|
||||||
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
|
FVPVideoPlayerPlugin.register(with: registry.registrar(forPlugin: "FVPVideoPlayerPlugin"))
|
||||||
|
|
30
pubspec.lock
30
pubspec.lock
|
@ -1153,10 +1153,10 @@ packages:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: matrix
|
name: matrix
|
||||||
sha256: "155673171920dceb224bd209f51a3e41fc5c015f55ec780c9d95e54eb84ba582"
|
sha256: "21f8e3b3aaf32c80f62ccfbb0335161c32a2c3585661f967b1253c630367b9a7"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.24.0"
|
version: "0.24.1"
|
||||||
matrix_api_lite:
|
matrix_api_lite:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -1715,7 +1715,7 @@ packages:
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.10.0"
|
version: "1.10.0"
|
||||||
sqflite:
|
sqflite:
|
||||||
dependency: transitive
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: sqflite
|
name: sqflite
|
||||||
sha256: "591f1602816e9c31377d5f008c2d9ef7b8aca8941c3f89cc5fd9d84da0c38a9a"
|
sha256: "591f1602816e9c31377d5f008c2d9ef7b8aca8941c3f89cc5fd9d84da0c38a9a"
|
||||||
|
@ -1730,6 +1730,30 @@ packages:
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.5.0+2"
|
version: "2.5.0+2"
|
||||||
|
sqflite_common_ffi:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sqflite_common_ffi
|
||||||
|
sha256: "35d2fce1e971707c227cc4775cc017d5eafe06c2654c3435ebd5c3ad6c170f5f"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.3.0+4"
|
||||||
|
sqflite_sqlcipher:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sqflite_sqlcipher
|
||||||
|
sha256: e1dfb55bf21ee5a18c43f28faa4291272a801da4ab34a6ba9973b6c0e1ed77da
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.1"
|
||||||
|
sqlite3:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: sqlite3
|
||||||
|
sha256: db65233e6b99e99b2548932f55a987961bc06d82a31a0665451fa0b4fff4c3fb
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.1.0"
|
||||||
stack_trace:
|
stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -61,7 +61,7 @@ dependencies:
|
||||||
keyboard_shortcuts: ^0.1.4
|
keyboard_shortcuts: ^0.1.4
|
||||||
latlong2: ^0.8.1
|
latlong2: ^0.8.1
|
||||||
linkify: ^5.0.0
|
linkify: ^5.0.0
|
||||||
matrix: ^0.24.0
|
matrix: ^0.24.1
|
||||||
matrix_homeserver_recommendations: ^0.3.0
|
matrix_homeserver_recommendations: ^0.3.0
|
||||||
native_imaging: ^0.1.0
|
native_imaging: ^0.1.0
|
||||||
package_info_plus: ^4.0.0
|
package_info_plus: ^4.0.0
|
||||||
|
@ -78,6 +78,9 @@ dependencies:
|
||||||
share_plus: ^7.2.1
|
share_plus: ^7.2.1
|
||||||
shared_preferences: ^2.2.0 # Pinned because https://github.com/flutter/flutter/issues/118401
|
shared_preferences: ^2.2.0 # Pinned because https://github.com/flutter/flutter/issues/118401
|
||||||
slugify: ^2.0.0
|
slugify: ^2.0.0
|
||||||
|
sqflite: ^2.3.0
|
||||||
|
sqflite_common_ffi: ^2.3.0+4
|
||||||
|
sqflite_sqlcipher: ^2.2.1
|
||||||
swipe_to_action: ^0.2.0
|
swipe_to_action: ^0.2.0
|
||||||
tor_detector_web: ^1.1.0
|
tor_detector_web: ^1.1.0
|
||||||
uni_links: ^0.5.1
|
uni_links: ^0.5.1
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
diff --git a/android/app/build.gradle b/android/app/build.gradle
|
diff --git a/android/app/build.gradle b/android/app/build.gradle
|
||||||
index 001fbd72..339b35af 100644
|
index bf972f30..46cebdc6 100644
|
||||||
--- a/android/app/build.gradle
|
--- a/android/app/build.gradle
|
||||||
+++ b/android/app/build.gradle
|
+++ b/android/app/build.gradle
|
||||||
@@ -70,6 +70,10 @@
|
@@ -70,6 +70,10 @@
|
||||||
|
@ -28,13 +28,15 @@ index 001fbd72..339b35af 100644
|
||||||
-//apply plugin: 'com.google.gms.google-services'
|
-//apply plugin: 'com.google.gms.google-services'
|
||||||
+apply plugin: 'com.google.gms.google-services'
|
+apply plugin: 'com.google.gms.google-services'
|
||||||
diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro
|
diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro
|
||||||
new file mode 100644
|
index d0e0fbc9..0a546da0 100644
|
||||||
index 00000000..40570865
|
--- a/android/app/proguard-rules.pro
|
||||||
--- /dev/null
|
|
||||||
+++ b/android/app/proguard-rules.pro
|
+++ b/android/app/proguard-rules.pro
|
||||||
@@ -0,0 +1,41 @@
|
@@ -1 +1,42 @@
|
||||||
|
--keep class net.sqlcipher.** { *; }
|
||||||
|
\ No newline at end of file
|
||||||
+-optimizationpasses 5
|
+-optimizationpasses 5
|
||||||
+## Flutter wrapper
|
+## Flutter wrapper
|
||||||
|
+-keep class net.sqlcipher.** { *; }
|
||||||
+-keep class io.flutter.app.** { *; }
|
+-keep class io.flutter.app.** { *; }
|
||||||
+-keep class io.flutter.plugin.** { *; }
|
+-keep class io.flutter.plugin.** { *; }
|
||||||
+-keep class io.flutter.util.** { *; }
|
+-keep class io.flutter.util.** { *; }
|
||||||
|
@ -110,7 +112,7 @@ index 1afc4606..894d1571 100644
|
||||||
return provideEngine(this)
|
return provideEngine(this)
|
||||||
}
|
}
|
||||||
diff --git a/android/build.gradle b/android/build.gradle
|
diff --git a/android/build.gradle b/android/build.gradle
|
||||||
index 85aa8647..3b7e09e7 100644
|
index bd394967..2e9d54de 100644
|
||||||
--- a/android/build.gradle
|
--- a/android/build.gradle
|
||||||
+++ b/android/build.gradle
|
+++ b/android/build.gradle
|
||||||
@@ -8,7 +8,7 @@ buildscript {
|
@@ -8,7 +8,7 @@ buildscript {
|
||||||
|
@ -145,7 +147,7 @@ index 8e67ae92..da4da5c3 100644
|
||||||
DateTime? lastReceivedPush;
|
DateTime? lastReceivedPush;
|
||||||
|
|
||||||
diff --git a/pubspec.yaml b/pubspec.yaml
|
diff --git a/pubspec.yaml b/pubspec.yaml
|
||||||
index 6999d0b8..b2c9144f 100644
|
index 193e6ed6..f70e48d4 100644
|
||||||
--- a/pubspec.yaml
|
--- a/pubspec.yaml
|
||||||
+++ b/pubspec.yaml
|
+++ b/pubspec.yaml
|
||||||
@@ -26,7 +26,7 @@ dependencies:
|
@@ -26,7 +26,7 @@ dependencies:
|
||||||
|
|
Loading…
Reference in a new issue