chore: migrate to new Hive

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2022-07-22 17:06:50 +02:00
parent 3194348958
commit 5b9daebcf9
7 changed files with 60 additions and 14 deletions

3
.gitignore vendored
View File

@ -42,6 +42,9 @@ lib/generated_plugin_registrant.dart
docs/build/ docs/build/
docs/.jekyll-cache/ docs/.jekyll-cache/
docs/_site/ docs/_site/
web/worker.js
web/worker.js.map
web/worker.js.deps
# Exceptions to above rules. # Exceptions to above rules.
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages

View File

@ -7,6 +7,7 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
import 'package:matrix/matrix.dart'; import 'package:matrix/matrix.dart';
import 'package:vrouter/vrouter.dart'; import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/utils/client_manager.dart';
import '../../widgets/matrix.dart'; import '../../widgets/matrix.dart';
import 'settings_emotes_view.dart'; import 'settings_emotes_view.dart';
@ -206,7 +207,7 @@ class EmotesSettingsController extends State<EmotesSettings> {
); );
try { try {
file = (await file.generateThumbnail( file = (await file.generateThumbnail(
compute: Matrix.of(context).client.runInBackground, nativeImplementations: ClientManager.nativeImplementations,
))!; ))!;
} catch (_) { } catch (_) {
// do nothing // do nothing

View File

@ -16,11 +16,20 @@ import 'matrix_sdk_extensions.dart/fluffybox_database.dart';
abstract class ClientManager { abstract class ClientManager {
static const String clientNamespace = 'im.fluffychat.store.clients'; static const String clientNamespace = 'im.fluffychat.store.clients';
/// the expected native implementations for the device
static final nativeImplementations = kIsWeb
? NativeImplementationsWebWorker(Uri.parse('native_executor.js'))
: NativeImplementationsIsolate(compute);
static Future<List<Client>> getClients({bool initialize = true}) async { static Future<List<Client>> getClients({bool initialize = true}) async {
if (PlatformInfos.isLinux) { if (PlatformInfos.isLinux) {
Hive.init((await getApplicationSupportDirectory()).path); Hive.init((await getApplicationSupportDirectory()).path);
} else { } else {
await Hive.initFlutter(); await Hive.initFlutter(
null,
HiveStorageBackendPreference.webWorker('worker.js'),
);
} }
final clientNames = <String>{}; final clientNames = <String>{};
try { try {
@ -109,7 +118,7 @@ abstract class ClientManager {
PlatformInfos.isMacOS) PlatformInfos.isMacOS)
AuthenticationTypes.sso AuthenticationTypes.sso
}, },
compute: compute, nativeImplementations: nativeImplementations,
customImageResizer: PlatformInfos.isMobile ? customImageResizer : null, customImageResizer: PlatformInfos.isMobile ? customImageResizer : null,
); );
} }

View File

@ -262,6 +262,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.0.1" version: "3.0.1"
cryptography:
dependency: transitive
description:
name: cryptography
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
csslib: csslib:
dependency: transitive dependency: transitive
description: description:
@ -493,6 +500,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.1+3" version: "0.8.1+3"
fixnum:
dependency: transitive
description:
name: fixnum
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
fluffybox: fluffybox:
dependency: transitive dependency: transitive
description: description:
@ -834,18 +848,22 @@ packages:
source: hosted source: hosted
version: "0.7.0" version: "0.7.0"
hive: hive:
dependency: transitive dependency: "direct overridden"
description: description:
name: hive path: hive
url: "https://pub.dartlang.org" ref: cacfc53dc1114491eaa3d3f3842312db910c1330
source: hosted resolved-ref: cacfc53dc1114491eaa3d3f3842312db910c1330
version: "2.2.1" url: "https://github.com/hivedb/hive.git"
source: git
version: "2.2.3"
hive_flutter: hive_flutter:
dependency: "direct main" dependency: "direct main"
description: description:
name: hive_flutter path: hive_flutter
url: "https://pub.dartlang.org" ref: cacfc53dc1114491eaa3d3f3842312db910c1330
source: hosted resolved-ref: cacfc53dc1114491eaa3d3f3842312db910c1330
url: "https://github.com/hivedb/hive.git"
source: git
version: "1.1.0" version: "1.1.0"
html: html:
dependency: transitive dependency: transitive
@ -1063,7 +1081,7 @@ packages:
name: matrix name: matrix
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.11.0" version: "0.11.1"
matrix_api_lite: matrix_api_lite:
dependency: transitive dependency: transitive
description: description:
@ -1240,7 +1258,7 @@ packages:
name: path_provider name: path_provider
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.0.9" version: "2.0.11"
path_provider_android: path_provider_android:
dependency: transitive dependency: transitive
description: description:

View File

@ -61,7 +61,7 @@ dependencies:
keyboard_shortcuts: ^0.1.4 keyboard_shortcuts: ^0.1.4
localstorage: ^4.0.0+1 localstorage: ^4.0.0+1
lottie: ^1.2.2 lottie: ^1.2.2
matrix: ^0.11.0 matrix: ^0.11.1
matrix_homeserver_recommendations: ^0.2.1 matrix_homeserver_recommendations: ^0.2.1
matrix_link_text: ^1.0.2 matrix_link_text: ^1.0.2
native_imaging: native_imaging:
@ -160,6 +160,16 @@ dependency_overrides:
hosted: hosted:
name: geolocator_android name: geolocator_android
url: https://hanntech-gmbh.gitlab.io/free2pass/flutter-geolocator-floss url: https://hanntech-gmbh.gitlab.io/free2pass/flutter-geolocator-floss
hive:
git:
url: https://github.com/hivedb/hive.git
path: hive
ref: cacfc53dc1114491eaa3d3f3842312db910c1330
hive_flutter:
git:
url: https://github.com/hivedb/hive.git
path: hive_flutter
ref: cacfc53dc1114491eaa3d3f3842312db910c1330
# waiting for null safety # waiting for null safety
# Upstream pull request: https://github.com/AntoineMarcel/keyboard_shortcuts/pull/13 # Upstream pull request: https://github.com/AntoineMarcel/keyboard_shortcuts/pull/13
keyboard_shortcuts: keyboard_shortcuts:

View File

@ -3,3 +3,5 @@ flutter config --enable-web
flutter clean flutter clean
flutter pub get flutter pub get
flutter build web --release --verbose --source-maps flutter build web --release --verbose --source-maps
dart compile js ./web/worker.dart -o ./web/worker.js -m

3
web/worker.dart Normal file
View File

@ -0,0 +1,3 @@
import 'package:hive/hive.dart';
main() => startWebWorker();