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';
|
2023-11-25 09:18:31 +00:00
|
|
|
import 'package:appflowy/env/cloud_env.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/plugins/document/application/prelude.dart';
|
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
2024-06-24 23:59:38 +00:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/ai_client.dart';
|
2023-10-09 15:14:24 +00:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/plugins/trash/application/prelude.dart';
|
2024-03-04 04:24:25 +00:00
|
|
|
import 'package:appflowy/shared/appflowy_cache_manager.dart';
|
|
|
|
import 'package:appflowy/shared/custom_image_cache_manager.dart';
|
2023-07-02 15:37:30 +00:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-11-29 20:55:13 +00:00
|
|
|
import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart';
|
2024-06-24 23:59:38 +00:00
|
|
|
import 'package:appflowy/user/application/ai_service.dart';
|
2023-10-02 09:22:22 +00:00
|
|
|
import 'package:appflowy/user/application/auth/af_cloud_auth_service.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-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/user/application/prelude.dart';
|
2023-10-02 07:12:24 +00:00
|
|
|
import 'package:appflowy/user/application/reminder/reminder_bloc.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-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/user/presentation/router.dart';
|
2024-04-12 08:21:41 +00:00
|
|
|
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart';
|
2023-08-02 13:20:51 +00:00
|
|
|
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
2024-04-23 13:46:57 +00:00
|
|
|
import 'package:appflowy/workspace/application/recent/cached_recent_service.dart';
|
2023-11-20 02:35:13 +00:00
|
|
|
import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart';
|
|
|
|
import 'package:appflowy/workspace/application/settings/appearance/desktop_appearance.dart';
|
|
|
|
import 'package:appflowy/workspace/application/settings/appearance/mobile_appearance.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/workspace/application/settings/prelude.dart';
|
2024-01-29 19:55:37 +00:00
|
|
|
import 'package:appflowy/workspace/application/sidebar/rename_view/rename_view_bloc.dart';
|
2024-06-12 15:08:55 +00:00
|
|
|
import 'package:appflowy/workspace/application/subscription_success_listenable/subscription_success_listenable.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
2023-02-26 08:27:17 +00:00
|
|
|
import 'package:appflowy/workspace/application/user/prelude.dart';
|
|
|
|
import 'package:appflowy/workspace/application/view/prelude.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:appflowy/workspace/application/workspace/prelude.dart';
|
2023-08-13 09:14:58 +00:00
|
|
|
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
2023-12-27 03:42:39 +00:00
|
|
|
import 'package:appflowy_backend/log.dart';
|
2023-12-30 23:29:40 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
2023-10-02 09:22:22 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
2023-12-27 03:42:39 +00:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
2024-01-29 19:55:37 +00:00
|
|
|
import 'package:appflowy_popover/appflowy_popover.dart';
|
2023-08-21 05:54:26 +00:00
|
|
|
import 'package:flowy_infra/file_picker/file_picker_impl.dart';
|
|
|
|
import 'package:flowy_infra/file_picker/file_picker_service.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 {
|
2023-11-24 03:54:47 +00:00
|
|
|
// getIt.registerFactory<KeyValueStorage>(() => RustKeyValue());
|
|
|
|
getIt.registerFactory<KeyValueStorage>(() => DartKeyValue());
|
|
|
|
|
|
|
|
await _resolveCloudDeps(getIt);
|
2023-08-22 07:40:22 +00:00
|
|
|
_resolveUserDeps(getIt, mode);
|
2022-03-25 07:02:43 +00:00
|
|
|
_resolveHomeDeps(getIt);
|
|
|
|
_resolveFolderDeps(getIt);
|
2023-07-02 15:37:30 +00:00
|
|
|
_resolveCommonService(getIt, mode);
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 03:54:47 +00:00
|
|
|
Future<void> _resolveCloudDeps(GetIt getIt) async {
|
2023-11-28 02:54:31 +00:00
|
|
|
final env = await AppFlowyCloudSharedEnv.fromEnv();
|
2024-01-12 06:34:59 +00:00
|
|
|
Log.info("cloud setting: $env");
|
2023-11-28 02:54:31 +00:00
|
|
|
getIt.registerFactory<AppFlowyCloudSharedEnv>(() => env);
|
2023-11-29 20:55:13 +00:00
|
|
|
|
|
|
|
if (isAppFlowyCloudEnabled) {
|
|
|
|
getIt.registerSingleton(
|
|
|
|
AppFlowyCloudDeepLink(),
|
|
|
|
dispose: (obj) async {
|
|
|
|
await obj.dispose();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-11-24 03:54:47 +00:00
|
|
|
}
|
|
|
|
|
2023-07-02 15:37:30 +00:00
|
|
|
void _resolveCommonService(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationMode mode,
|
|
|
|
) async {
|
2022-12-20 03:14:42 +00:00
|
|
|
getIt.registerFactory<FilePickerService>(() => FilePicker());
|
2024-04-30 12:09:08 +00:00
|
|
|
|
|
|
|
getIt.registerFactory<ApplicationDataStorage>(
|
|
|
|
() => mode.isTest ? MockApplicationDataStorage() : ApplicationDataStorage(),
|
|
|
|
);
|
2023-05-03 07:43:11 +00:00
|
|
|
|
2024-06-24 23:59:38 +00:00
|
|
|
getIt.registerFactoryAsync<AIRepository>(
|
2023-05-03 07:43:11 +00:00
|
|
|
() async {
|
|
|
|
final result = await UserBackendService.getCurrentUserProfile();
|
|
|
|
return result.fold(
|
2024-02-24 13:54:10 +00:00
|
|
|
(s) {
|
2024-06-24 23:59:38 +00:00
|
|
|
return AppFlowyAIService();
|
2023-05-03 07:43:11 +00:00
|
|
|
},
|
2024-02-24 13:54:10 +00:00
|
|
|
(e) {
|
|
|
|
throw Exception('Failed to get user profile: ${e.msg}');
|
|
|
|
},
|
2023-05-03 07:43:11 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2023-08-21 05:54:26 +00:00
|
|
|
|
2023-10-09 15:14:24 +00:00
|
|
|
getIt.registerFactoryAsync<StabilityAIRepository>(
|
|
|
|
() async {
|
|
|
|
final result = await UserBackendService.getCurrentUserProfile();
|
|
|
|
return result.fold(
|
2024-02-24 13:54:10 +00:00
|
|
|
(s) {
|
2023-10-09 15:14:24 +00:00
|
|
|
return HttpStabilityAIRepository(
|
|
|
|
client: http.Client(),
|
2024-02-24 13:54:10 +00:00
|
|
|
apiKey: s.stabilityAiKey,
|
2023-10-09 15:14:24 +00:00
|
|
|
);
|
|
|
|
},
|
2024-02-24 13:54:10 +00:00
|
|
|
(e) {
|
|
|
|
throw Exception('Failed to get user profile: ${e.msg}');
|
|
|
|
},
|
2023-10-09 15:14:24 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-08-21 05:54:26 +00:00
|
|
|
getIt.registerFactory<ClipboardService>(
|
|
|
|
() => ClipboardService(),
|
|
|
|
);
|
2023-11-20 02:35:13 +00:00
|
|
|
|
|
|
|
// theme
|
|
|
|
getIt.registerFactory<BaseAppearance>(
|
|
|
|
() => PlatformExtension.isMobile ? MobileAppearance() : DesktopAppearance(),
|
|
|
|
);
|
2024-03-04 04:24:25 +00:00
|
|
|
|
|
|
|
getIt.registerFactory<FlowyCacheManager>(
|
|
|
|
() => FlowyCacheManager()
|
|
|
|
..registerCache(TemporaryDirectoryCache())
|
2024-03-07 01:28:58 +00:00
|
|
|
..registerCache(CustomImageCacheManager())
|
|
|
|
..registerCache(FeatureFlagCache()),
|
2024-03-04 04:24:25 +00:00
|
|
|
);
|
2022-12-20 03:14:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-22 07:40:22 +00:00
|
|
|
void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
|
2023-10-02 09:22:22 +00:00
|
|
|
switch (currentCloudType()) {
|
2023-11-28 02:54:31 +00:00
|
|
|
case AuthenticatorType.local:
|
2023-10-02 09:22:22 +00:00
|
|
|
getIt.registerFactory<AuthService>(
|
|
|
|
() => BackendAuthService(
|
2023-12-25 18:03:42 +00:00
|
|
|
AuthenticatorPB.Local,
|
2023-10-02 09:22:22 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
2023-11-28 02:54:31 +00:00
|
|
|
case AuthenticatorType.supabase:
|
2023-11-28 23:49:47 +00:00
|
|
|
getIt.registerFactory<AuthService>(() => SupabaseAuthService());
|
2023-10-02 09:22:22 +00:00
|
|
|
break;
|
2023-11-28 02:54:31 +00:00
|
|
|
case AuthenticatorType.appflowyCloud:
|
2024-01-12 06:34:59 +00:00
|
|
|
case AuthenticatorType.appflowyCloudSelfHost:
|
2024-01-15 04:53:53 +00:00
|
|
|
case AuthenticatorType.appflowyCloudDevelop:
|
2023-11-28 23:49:47 +00:00
|
|
|
getIt.registerFactory<AuthService>(() => AppFlowyCloudAuthService());
|
2023-10-02 09:22:22 +00:00
|
|
|
break;
|
2023-08-03 00:48:04 +00:00
|
|
|
}
|
2023-05-21 10:53:59 +00:00
|
|
|
|
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
|
|
|
|
2023-09-12 02:32:26 +00:00
|
|
|
getIt.registerFactory<SplashRouter>(() => SplashRouter());
|
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());
|
2024-04-23 13:46:57 +00:00
|
|
|
getIt.registerLazySingleton<CachedRecentService>(() => CachedRecentService());
|
2024-06-12 15:08:55 +00:00
|
|
|
getIt.registerLazySingleton<SubscriptionSuccessListenable>(
|
|
|
|
() => SubscriptionSuccessListenable(),
|
|
|
|
);
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
|
|
|
|
// share
|
2024-04-08 10:01:20 +00:00
|
|
|
getIt.registerFactoryParam<DocumentShareBloc, ViewPB, void>(
|
|
|
|
(view, _) => DocumentShareBloc(view: view),
|
2023-04-10 07:10:42 +00:00
|
|
|
);
|
2023-07-12 11:13:18 +00:00
|
|
|
|
2024-04-12 08:21:41 +00:00
|
|
|
getIt.registerSingleton<ActionNavigationBloc>(ActionNavigationBloc());
|
2023-10-02 07:12:24 +00:00
|
|
|
|
2023-07-12 11:13:18 +00:00
|
|
|
getIt.registerLazySingleton<TabsBloc>(() => TabsBloc());
|
2023-10-02 07:12:24 +00:00
|
|
|
|
2023-11-08 23:32:10 +00:00
|
|
|
getIt.registerSingleton<ReminderBloc>(ReminderBloc());
|
2024-01-29 19:55:37 +00:00
|
|
|
|
|
|
|
getIt.registerSingleton<RenameViewBloc>(RenameViewBloc(PopoverController()));
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _resolveFolderDeps(GetIt getIt) {
|
2024-04-23 13:46:57 +00:00
|
|
|
// Workspace
|
2022-07-19 06:40:56 +00:00
|
|
|
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
|
2024-04-23 13:46:57 +00:00
|
|
|
(user, workspaceId) =>
|
|
|
|
WorkspaceListener(user: user, workspaceId: workspaceId),
|
2023-04-10 07:10:42 +00:00
|
|
|
);
|
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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2024-04-23 13:46:57 +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),
|
|
|
|
);
|
|
|
|
|
2024-04-23 13:46:57 +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),
|
|
|
|
);
|
|
|
|
|
2024-04-23 13:46:57 +00:00
|
|
|
// Trash
|
2022-03-25 07:02:43 +00:00
|
|
|
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
|
|
|
);
|
2024-04-23 13:46:57 +00:00
|
|
|
|
|
|
|
// Favorite
|
2023-08-02 13:20:51 +00:00
|
|
|
getIt.registerFactory<FavoriteBloc>(() => FavoriteBloc());
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|