2023-05-21 10:53:59 +00:00
|
|
|
import 'package:appflowy/core/config/kv.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
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';
|
2023-05-16 06:58:24 +00:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_client.dart';
|
2023-07-02 15:37:30 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-05-21 10:53:59 +00:00
|
|
|
import 'package:appflowy/user/application/auth/auth_service.dart';
|
|
|
|
import 'package:appflowy/user/application/auth/supabase_auth_service.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/user/application/user_listener.dart';
|
|
|
|
import 'package:appflowy/user/application/user_service.dart';
|
2023-07-03 14:07:11 +00:00
|
|
|
import 'package:flowy_infra/file_picker/file_picker_impl.dart';
|
|
|
|
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/plugins/document/application/prelude.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';
|
2023-04-04 00:41:16 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
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';
|
2023-05-03 07:43:11 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
2022-03-25 07:02:43 +00:00
|
|
|
|
|
|
|
class DependencyResolver {
|
2023-07-02 15:37:30 +00:00
|
|
|
static Future<void> resolve(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationMode mode,
|
|
|
|
) async {
|
2022-03-25 07:02:43 +00:00
|
|
|
_resolveUserDeps(getIt);
|
|
|
|
_resolveHomeDeps(getIt);
|
|
|
|
_resolveFolderDeps(getIt);
|
|
|
|
_resolveDocDeps(getIt);
|
|
|
|
_resolveGridDeps(getIt);
|
2023-07-02 15:37:30 +00:00
|
|
|
_resolveCommonService(getIt, mode);
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-02 15:37:30 +00:00
|
|
|
void _resolveCommonService(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationMode mode,
|
|
|
|
) async {
|
2023-05-21 10:53:59 +00:00
|
|
|
// getIt.registerFactory<KeyValueStorage>(() => RustKeyValue());
|
|
|
|
getIt.registerFactory<KeyValueStorage>(() => DartKeyValue());
|
2022-12-20 03:14:42 +00:00
|
|
|
getIt.registerFactory<FilePickerService>(() => FilePicker());
|
2023-07-02 15:37:30 +00:00
|
|
|
if (mode.isTest) {
|
|
|
|
getIt.registerFactory<ApplicationDataStorage>(
|
|
|
|
() => MockApplicationDataStorage(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
getIt.registerFactory<ApplicationDataStorage>(
|
|
|
|
() => ApplicationDataStorage(),
|
|
|
|
);
|
|
|
|
}
|
2023-05-03 07:43:11 +00:00
|
|
|
|
|
|
|
getIt.registerFactoryAsync<OpenAIRepository>(
|
|
|
|
() async {
|
|
|
|
final result = await UserBackendService.getCurrentUserProfile();
|
|
|
|
return result.fold(
|
|
|
|
(l) {
|
2023-05-16 06:58:24 +00:00
|
|
|
throw Exception('Failed to get user profile: ${l.msg}');
|
|
|
|
},
|
|
|
|
(r) {
|
2023-05-03 07:43:11 +00:00
|
|
|
return HttpOpenAIRepository(
|
|
|
|
client: http.Client(),
|
2023-05-16 06:58:24 +00:00
|
|
|
apiKey: r.openaiKey,
|
2023-05-03 07:43:11 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2022-12-20 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 07:02:43 +00:00
|
|
|
void _resolveUserDeps(GetIt getIt) {
|
2023-05-21 10:53:59 +00:00
|
|
|
// getIt.registerFactory<AuthService>(() => AppFlowyAuthService());
|
|
|
|
getIt.registerFactory<AuthService>(() => SupabaseAuthService());
|
|
|
|
|
2022-03-25 07:02:43 +00:00
|
|
|
getIt.registerFactory<AuthRouter>(() => AuthRouter());
|
|
|
|
|
2023-05-21 10:53:59 +00:00
|
|
|
getIt.registerFactory<SignInBloc>(
|
|
|
|
() => SignInBloc(getIt<AuthService>()),
|
|
|
|
);
|
|
|
|
getIt.registerFactory<SignUpBloc>(
|
|
|
|
() => SignUpBloc(getIt<AuthService>()),
|
|
|
|
);
|
2022-03-25 07:02:43 +00:00
|
|
|
|
|
|
|
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(
|
2023-02-26 08:27:17 +00:00
|
|
|
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
|
2022-07-19 06:11:29 +00:00
|
|
|
getIt.registerFactoryParam<DocShareBloc, ViewPB, void>(
|
2023-06-10 14:38:25 +00:00
|
|
|
(view, _) => DocShareBloc(view: view),
|
2023-04-10 07:10:42 +00:00
|
|
|
);
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _resolveFolderDeps(GetIt getIt) {
|
|
|
|
//workspace
|
2022-07-19 06:40:56 +00:00
|
|
|
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
|
2023-04-10 07:10:42 +00:00
|
|
|
(user, workspaceId) =>
|
|
|
|
WorkspaceListener(user: user, workspaceId: workspaceId),
|
|
|
|
);
|
2022-03-25 07:02:43 +00:00
|
|
|
|
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
|
2022-07-21 16:21:07 +00:00
|
|
|
getIt.registerFactoryParam<SettingsDialogBloc, UserProfilePB, void>(
|
2022-07-21 16:01:39 +00:00
|
|
|
(user, _) => SettingsDialogBloc(user),
|
|
|
|
);
|
|
|
|
|
2022-07-09 14:00:17 +00:00
|
|
|
//User
|
2022-07-21 16:21:07 +00:00
|
|
|
getIt.registerFactoryParam<SettingsUserViewBloc, UserProfilePB, void>(
|
2022-07-09 14:00:17 +00:00
|
|
|
(user, _) => SettingsUserViewBloc(user),
|
|
|
|
);
|
|
|
|
|
2022-03-25 07:02:43 +00:00
|
|
|
// trash
|
|
|
|
getIt.registerLazySingleton<TrashService>(() => TrashService());
|
|
|
|
getIt.registerLazySingleton<TrashListener>(() => TrashListener());
|
|
|
|
getIt.registerFactory<TrashBloc>(
|
2022-10-25 08:51:51 +00:00
|
|
|
() => 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) {
|
2023-02-26 08:27:17 +00:00
|
|
|
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
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2023-06-04 01:28:13 +00:00
|
|
|
getIt.registerFactoryParam<FieldActionSheetBloc, FieldContext, void>(
|
2022-10-23 08:44:10 +00:00
|
|
|
(data, _) => FieldActionSheetBloc(fieldCellContext: data),
|
2022-03-25 07:02:43 +00:00
|
|
|
);
|
|
|
|
|
2023-02-26 08:27:17 +00:00
|
|
|
getIt.registerFactoryParam<DatabasePropertyBloc, String, FieldController>(
|
|
|
|
(viewId, cache) =>
|
|
|
|
DatabasePropertyBloc(viewId: viewId, fieldController: cache),
|
2022-04-03 09:05:28 +00:00
|
|
|
);
|
2023-05-16 06:58:24 +00:00
|
|
|
}
|