AppFlowy/frontend/appflowy_flutter/lib/startup/deps_resolver.dart

162 lines
5.6 KiB
Dart
Raw Normal View History

import 'package:appflowy/core/network_monitor.dart';
import 'package:appflowy/plugins/database_view/application/field/field_action_sheet_bloc.dart';
import 'package:appflowy/plugins/database_view/application/field/field_controller.dart';
import 'package:appflowy/plugins/database_view/application/field/field_service.dart';
import 'package:appflowy/plugins/database_view/application/setting/property_bloc.dart';
import 'package:appflowy/plugins/database_view/grid/application/grid_header_bloc.dart';
import 'package:appflowy/user/application/user_listener.dart';
import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy/util/file_picker/file_picker_impl.dart';
import 'package:appflowy/util/file_picker/file_picker_service.dart';
import 'package:appflowy/workspace/application/app/prelude.dart';
import 'package:appflowy/plugins/document/application/prelude.dart';
import 'package:appflowy/workspace/application/settings/settings_location_cubit.dart';
import 'package:appflowy/workspace/application/user/prelude.dart';
import 'package:appflowy/workspace/application/workspace/prelude.dart';
import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart';
import 'package:appflowy/workspace/application/view/prelude.dart';
import 'package:appflowy/workspace/application/menu/prelude.dart';
import 'package:appflowy/workspace/application/settings/prelude.dart';
import 'package:appflowy/user/application/prelude.dart';
import 'package:appflowy/user/presentation/router.dart';
import 'package:appflowy/plugins/trash/application/prelude.dart';
import 'package:appflowy/workspace/presentation/home/home_stack.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/app.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/user_profile.pb.dart';
2022-06-01 07:22:18 +00:00
import 'package:fluttertoast/fluttertoast.dart';
2022-03-25 07:02:43 +00:00
import 'package:get_it/get_it.dart';
class DependencyResolver {
static Future<void> resolve(GetIt getIt) async {
_resolveUserDeps(getIt);
_resolveHomeDeps(getIt);
_resolveFolderDeps(getIt);
_resolveDocDeps(getIt);
_resolveGridDeps(getIt);
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 03:14:42 +00:00
_resolveCommonService(getIt);
2022-03-25 07:02:43 +00:00
}
}
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 03:14:42 +00:00
void _resolveCommonService(GetIt getIt) {
getIt.registerFactory<FilePickerService>(() => FilePicker());
}
2022-03-25 07:02:43 +00:00
void _resolveUserDeps(GetIt getIt) {
getIt.registerFactory<AuthService>(() => AuthService());
getIt.registerFactory<AuthRouter>(() => AuthRouter());
getIt.registerFactory<SignInBloc>(() => SignInBloc(getIt<AuthService>()));
getIt.registerFactory<SignUpBloc>(() => SignUpBloc(getIt<AuthService>()));
getIt.registerFactory<SplashRoute>(() => SplashRoute());
2022-08-09 03:59:22 +00:00
getIt.registerFactory<EditPanelBloc>(() => EditPanelBloc());
2022-03-25 07:02:43 +00:00
getIt.registerFactory<SplashBloc>(() => SplashBloc());
getIt.registerLazySingleton<NetworkListener>(() => NetworkListener());
}
void _resolveHomeDeps(GetIt getIt) {
2022-06-01 07:22:18 +00:00
getIt.registerSingleton(FToast());
2022-04-26 06:43:42 +00:00
getIt.registerSingleton(MenuSharedState());
2022-07-19 06:40:56 +00:00
getIt.registerFactoryParam<UserListener, UserProfilePB, void>(
2022-07-04 02:59:08 +00:00
(user, _) => UserListener(userProfile: user),
2022-03-25 07:02:43 +00:00
);
//
getIt.registerLazySingleton<HomeStackManager>(() => HomeStackManager());
2022-07-19 06:40:56 +00:00
getIt.registerFactoryParam<WelcomeBloc, UserProfilePB, void>(
2022-03-25 07:02:43 +00:00
(user, _) => WelcomeBloc(
userService: UserBackendService(userId: user.id),
2022-07-04 02:59:08 +00:00
userWorkspaceListener: UserWorkspaceListener(userProfile: user),
2022-03-25 07:02:43 +00:00
),
);
// share
getIt.registerLazySingleton<ShareService>(() => ShareService());
2022-07-19 06:11:29 +00:00
getIt.registerFactoryParam<DocShareBloc, ViewPB, void>(
2022-03-25 07:02:43 +00:00
(view, _) => DocShareBloc(view: view, service: getIt<ShareService>()));
}
void _resolveFolderDeps(GetIt getIt) {
//workspace
2022-07-19 06:40:56 +00:00
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
(user, workspaceId) =>
WorkspaceListener(user: user, workspaceId: workspaceId));
2022-03-25 07:02:43 +00:00
2022-07-19 06:11:29 +00:00
// ViewPB
getIt.registerFactoryParam<ViewListener, ViewPB, void>(
2022-03-25 07:02:43 +00:00
(view, _) => ViewListener(view: view),
);
2022-07-19 06:11:29 +00:00
getIt.registerFactoryParam<ViewBloc, ViewPB, void>(
2022-03-25 07:02:43 +00:00
(view, _) => ViewBloc(
view: view,
),
);
2022-07-19 06:40:56 +00:00
getIt.registerFactoryParam<MenuUserBloc, UserProfilePB, void>(
2022-07-04 02:59:08 +00:00
(user, _) => MenuUserBloc(user),
2022-03-25 07:02:43 +00:00
);
2022-07-21 16:01:39 +00:00
//Settings
getIt.registerFactoryParam<SettingsDialogBloc, UserProfilePB, void>(
2022-07-21 16:01:39 +00:00
(user, _) => SettingsDialogBloc(user),
);
feat: Customize the storage folder path (#1538) * feat: support customize folder path * feat: add l10n and optimize the logic * chore: code refactor * feat: add file read/write permission for macOS * fix: add toast for restoring path * feat: fetch apps and show them * feat: fetch apps and show them * feat: implement select document logic * feat: l10n and add select item callback * feat: add space between tile * chore: move file exporter to settings * chore: update UI * feat: support customizing folder when launching the app * feat: auto register after customizing folder * feat: l10n * feat: l10n * chore: reinitialize flowy sdk when calling init_sdk * chore: remove flowysdk const keyword to make sure it can be rebuild * chore: clear kv values when user logout * chore: replace current workspace id key in kv.db * feat: add config.name as a part of seesion_cache_key * feat: support open folder when launching * chore: fix some bugs * chore: dart fix & flutter analyze * chore: wrap 'sign up with ramdom user' as interface * feat: dismiss settings view after changing the folder * fix: read kv value after initializaing with new path * chore: remove user_id prefix from current workspace key * fix: move open latest view action to bloc * test: add test utils for integration tests * chore: move integration_test to its parent directory * test: add integration_test ci * test: switch to B from A, then switch to A again * chore: fix warings and format code and fix tests * chore: remove comment out codes * chore: rename some properties name and optimize the logic * chore: abstract logic of settings file exporter widget to cubit * chore: abstract location customizer view from file system view * chore: abstract settings page index to enum type * chore: remove the redundant underscore * test: fix integration test error * chore: enable integration test for windows and ubuntu * feat: abstract file picker as service and mock it under integration test * chore: fix bloc test Co-authored-by: nathan <nathan@appflowy.io>
2022-12-20 03:14:42 +00:00
// Location
getIt.registerFactory<SettingsLocationCubit>(
() => SettingsLocationCubit(),
);
2022-07-09 14:00:17 +00:00
//User
getIt.registerFactoryParam<SettingsUserViewBloc, UserProfilePB, void>(
2022-07-09 14:00:17 +00:00
(user, _) => SettingsUserViewBloc(user),
);
2022-07-19 06:11:29 +00:00
// AppPB
getIt.registerFactoryParam<AppBloc, AppPB, void>(
(app, _) => AppBloc(app: app),
2022-03-25 07:02:43 +00:00
);
// trash
getIt.registerLazySingleton<TrashService>(() => TrashService());
getIt.registerLazySingleton<TrashListener>(() => TrashListener());
getIt.registerFactory<TrashBloc>(
() => TrashBloc(),
2022-03-25 07:02:43 +00:00
);
}
void _resolveDocDeps(GetIt getIt) {
// Doc
2022-07-19 06:11:29 +00:00
getIt.registerFactoryParam<DocumentBloc, ViewPB, void>(
2022-10-26 02:38:57 +00:00
(view, _) => DocumentBloc(view: view),
2022-03-25 07:02:43 +00:00
);
}
void _resolveGridDeps(GetIt getIt) {
getIt.registerFactoryParam<GridHeaderBloc, String, FieldController>(
(viewId, fieldController) => GridHeaderBloc(
viewId: viewId,
2022-09-03 09:16:48 +00:00
fieldController: fieldController,
2022-03-25 07:02:43 +00:00
),
);
getIt.registerFactoryParam<FieldActionSheetBloc, FieldCellContext, void>(
(data, _) => FieldActionSheetBloc(fieldCellContext: data),
2022-03-25 07:02:43 +00:00
);
getIt.registerFactoryParam<DatabasePropertyBloc, String, FieldController>(
(viewId, cache) =>
DatabasePropertyBloc(viewId: viewId, fieldController: cache),
2022-04-03 09:05:28 +00:00
);
2022-03-25 07:02:43 +00:00
}