Skip to content

Commit

Permalink
hot-fix: remove directory to init Hive database, so later can be init…
Browse files Browse the repository at this point in the history
…ialzed in tom
  • Loading branch information
sherlockvn authored and hoangdat committed Sep 27, 2023
1 parent c90f805 commit db39ab4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
12 changes: 1 addition & 11 deletions lib/data/network/dio_cache_option.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import 'package:dio_cache_interceptor/dio_cache_interceptor.dart';
import 'package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart';
import 'package:flutter/foundation.dart';
import 'package:matrix/matrix.dart';
import 'package:path_provider/path_provider.dart';

class DioCacheOption {
static const String _hiveBoxName = "twake_dio_cache_hive_store";
Expand All @@ -20,18 +18,10 @@ class DioCacheOption {
return _instance;
}

Future<String?> _getAppDirPath() async {
if (kIsWeb) return null;
final appDir = await getApplicationDocumentsDirectory();
Logs().d('DioCacheOption::_getAppDirPath() appDirPath ${appDir.path}');
return appDir.path;
}

Future<void> setUpDioHiveCache() async {
Logs().d('DioCacheOption::_setUpDioHiveCache() Start setup DioHiveCache');
final appDirPath = await _getAppDirPath();
_hiveCacheStore = HiveCacheStore(
appDirPath,
null,
hiveBoxName: _hiveBoxName,
);
Logs().d('DioCacheOption::_setUpDioHiveCache() DioHiveCache Ready');
Expand Down
6 changes: 6 additions & 0 deletions lib/di/global/get_it_initializer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fluffychat/data/datasource_impl/media/media_data_source_impl.dar
import 'package:fluffychat/data/datasource_impl/recovery_words_data_source_impl.dart';
import 'package:fluffychat/data/datasource_impl/tom_configurations_datasource_impl.dart';
import 'package:fluffychat/data/network/contact/tom_contact_api.dart';
import 'package:fluffychat/data/network/dio_cache_option.dart';
import 'package:fluffychat/data/network/media/media_api.dart';
import 'package:fluffychat/data/network/recovery_words/recovery_words_api.dart';
import 'package:fluffychat/data/repository/contact/tom_contact_repository_impl.dart';
Expand Down Expand Up @@ -65,6 +66,7 @@ class GetItInitializer {
}

void bindingGlobal() {
setupDioCache();
NetworkDI().bind();
HiveDI().bind();
NetworkConnectivityDI().bind();
Expand All @@ -75,6 +77,10 @@ class GetItInitializer {
getIt.registerFactory<Queue>(() => Queue());
}

void setupDioCache() {
DioCacheOption.instance.setUpDioHiveCache();
}

void bindingAPI() {
getIt.registerLazySingleton<RecoveryWordsAPI>(() => RecoveryWordsAPI());
getIt.registerFactory<TomContactAPI>(() => TomContactAPI());
Expand Down
3 changes: 0 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:collection/collection.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/config/setting_keys.dart';
import 'package:fluffychat/data/network/dio_cache_option.dart';
import 'package:fluffychat/di/global/get_it_initializer.dart';
import 'package:fluffychat/utils/client_manager.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand Down Expand Up @@ -30,8 +29,6 @@ void main() async {
await firstClient?.roomsLoading;
await firstClient?.accountDataLoading;

await DioCacheOption.instance.setUpDioHiveCache();

GetItInitializer().setUp();

// If the app starts in detached mode, we assume that it is in
Expand Down

0 comments on commit db39ab4

Please sign in to comment.