2023-05-21 18:53:59 +08:00
|
|
|
import 'package:appflowy/core/config/kv.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/core/network_monitor.dart';
|
2023-11-25 01:18:31 -08:00
|
|
|
import 'package:appflowy/env/cloud_env.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/plugins/document/application/prelude.dart';
|
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
2023-05-16 14:58:24 +08:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_client.dart';
|
2023-10-09 23:14:24 +08:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/plugins/trash/application/prelude.dart';
|
2023-07-02 23:37:30 +08:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-11-29 12:55:13 -08:00
|
|
|
import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart';
|
2023-10-02 17:22:22 +08:00
|
|
|
import 'package:appflowy/user/application/auth/af_cloud_auth_service.dart';
|
2023-05-21 18:53:59 +08:00
|
|
|
import 'package:appflowy/user/application/auth/auth_service.dart';
|
|
|
|
import 'package:appflowy/user/application/auth/supabase_auth_service.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/user/application/prelude.dart';
|
2023-10-02 09:12:24 +02:00
|
|
|
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/user/application/user_listener.dart';
|
|
|
|
import 'package:appflowy/user/application/user_service.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/user/presentation/router.dart';
|
|
|
|
import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart';
|
2023-08-02 18:50:51 +05:30
|
|
|
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
2023-10-17 08:48:58 +02:00
|
|
|
import 'package:appflowy/workspace/application/notifications/notification_action_bloc.dart';
|
2023-11-20 10:35:13 +08: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 13:54:26 +08:00
|
|
|
import 'package:appflowy/workspace/application/settings/prelude.dart';
|
2024-01-29 20:55:37 +01:00
|
|
|
import 'package:appflowy/workspace/application/sidebar/rename_view/rename_view_bloc.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/workspace/application/user/prelude.dart';
|
|
|
|
import 'package:appflowy/workspace/application/view/prelude.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:appflowy/workspace/application/workspace/prelude.dart';
|
2023-08-13 17:14:58 +08:00
|
|
|
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
2023-12-27 11:42:39 +08:00
|
|
|
import 'package:appflowy_backend/log.dart';
|
2023-12-31 07:29:40 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
2023-10-02 17:22:22 +08:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
2023-12-27 11:42:39 +08:00
|
|
|
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
2024-01-29 20:55:37 +01:00
|
|
|
import 'package:appflowy_popover/appflowy_popover.dart';
|
2023-08-21 13:54:26 +08:00
|
|
|
import 'package:flowy_infra/file_picker/file_picker_impl.dart';
|
|
|
|
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
2022-06-01 15:22:18 +08:00
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
2022-03-25 15:02:43 +08: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 15:02:43 +08:00
|
|
|
|
|
|
|
class DependencyResolver {
|
2023-07-02 23:37:30 +08:00
|
|
|
static Future<void> resolve(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationMode mode,
|
|
|
|
) async {
|
2023-11-24 11:54:47 +08:00
|
|
|
// getIt.registerFactory<KeyValueStorage>(() => RustKeyValue());
|
|
|
|
getIt.registerFactory<KeyValueStorage>(() => DartKeyValue());
|
|
|
|
|
|
|
|
await _resolveCloudDeps(getIt);
|
2023-08-22 15:40:22 +08:00
|
|
|
_resolveUserDeps(getIt, mode);
|
2022-03-25 15:02:43 +08:00
|
|
|
_resolveHomeDeps(getIt);
|
|
|
|
_resolveFolderDeps(getIt);
|
2023-07-02 23:37:30 +08:00
|
|
|
_resolveCommonService(getIt, mode);
|
2022-03-25 15:02:43 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 11:54:47 +08:00
|
|
|
Future<void> _resolveCloudDeps(GetIt getIt) async {
|
2023-11-27 18:54:31 -08:00
|
|
|
final env = await AppFlowyCloudSharedEnv.fromEnv();
|
2024-01-12 14:34:59 +08:00
|
|
|
Log.info("cloud setting: $env");
|
2023-11-27 18:54:31 -08:00
|
|
|
getIt.registerFactory<AppFlowyCloudSharedEnv>(() => env);
|
2023-11-29 12:55:13 -08:00
|
|
|
|
|
|
|
if (isAppFlowyCloudEnabled) {
|
|
|
|
getIt.registerSingleton(
|
|
|
|
AppFlowyCloudDeepLink(),
|
|
|
|
dispose: (obj) async {
|
|
|
|
await obj.dispose();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2023-11-24 11:54:47 +08:00
|
|
|
}
|
|
|
|
|
2023-07-02 23:37:30 +08:00
|
|
|
void _resolveCommonService(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationMode mode,
|
|
|
|
) async {
|
2022-12-20 11:14:42 +08:00
|
|
|
getIt.registerFactory<FilePickerService>(() => FilePicker());
|
2023-07-02 23:37:30 +08: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 14:58:24 +08: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 14:58:24 +08:00
|
|
|
apiKey: r.openaiKey,
|
2023-05-03 07:43:11 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2023-08-21 13:54:26 +08:00
|
|
|
|
2023-10-09 23:14:24 +08:00
|
|
|
getIt.registerFactoryAsync<StabilityAIRepository>(
|
|
|
|
() async {
|
|
|
|
final result = await UserBackendService.getCurrentUserProfile();
|
|
|
|
return result.fold(
|
|
|
|
(l) {
|
|
|
|
throw Exception('Failed to get user profile: ${l.msg}');
|
|
|
|
},
|
|
|
|
(r) {
|
|
|
|
return HttpStabilityAIRepository(
|
|
|
|
client: http.Client(),
|
|
|
|
apiKey: r.stabilityAiKey,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2023-08-21 13:54:26 +08:00
|
|
|
getIt.registerFactory<ClipboardService>(
|
|
|
|
() => ClipboardService(),
|
|
|
|
);
|
2023-11-20 10:35:13 +08:00
|
|
|
|
|
|
|
// theme
|
|
|
|
getIt.registerFactory<BaseAppearance>(
|
|
|
|
() => PlatformExtension.isMobile ? MobileAppearance() : DesktopAppearance(),
|
|
|
|
);
|
2022-12-20 11:14:42 +08:00
|
|
|
}
|
|
|
|
|
2023-08-22 15:40:22 +08:00
|
|
|
void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
|
2023-10-02 17:22:22 +08:00
|
|
|
switch (currentCloudType()) {
|
2023-11-27 18:54:31 -08:00
|
|
|
case AuthenticatorType.local:
|
2023-10-02 17:22:22 +08:00
|
|
|
getIt.registerFactory<AuthService>(
|
|
|
|
() => BackendAuthService(
|
2023-12-26 02:03:42 +08:00
|
|
|
AuthenticatorPB.Local,
|
2023-10-02 17:22:22 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
2023-11-27 18:54:31 -08:00
|
|
|
case AuthenticatorType.supabase:
|
2023-11-28 15:49:47 -08:00
|
|
|
getIt.registerFactory<AuthService>(() => SupabaseAuthService());
|
2023-10-02 17:22:22 +08:00
|
|
|
break;
|
2023-11-27 18:54:31 -08:00
|
|
|
case AuthenticatorType.appflowyCloud:
|
2024-01-12 14:34:59 +08:00
|
|
|
case AuthenticatorType.appflowyCloudSelfHost:
|
2024-01-15 12:53:53 +08:00
|
|
|
case AuthenticatorType.appflowyCloudDevelop:
|
2023-11-28 15:49:47 -08:00
|
|
|
getIt.registerFactory<AuthService>(() => AppFlowyCloudAuthService());
|
2023-10-02 17:22:22 +08:00
|
|
|
break;
|
2023-08-03 08:48:04 +08:00
|
|
|
}
|
2023-05-21 18:53:59 +08:00
|
|
|
|
2022-03-25 15:02:43 +08:00
|
|
|
getIt.registerFactory<AuthRouter>(() => AuthRouter());
|
|
|
|
|
2023-05-21 18:53:59 +08:00
|
|
|
getIt.registerFactory<SignInBloc>(
|
|
|
|
() => SignInBloc(getIt<AuthService>()),
|
|
|
|
);
|
|
|
|
getIt.registerFactory<SignUpBloc>(
|
|
|
|
() => SignUpBloc(getIt<AuthService>()),
|
|
|
|
);
|
2022-03-25 15:02:43 +08:00
|
|
|
|
2023-09-11 21:32:26 -05:00
|
|
|
getIt.registerFactory<SplashRouter>(() => SplashRouter());
|
2022-08-09 11:59:22 +08:00
|
|
|
getIt.registerFactory<EditPanelBloc>(() => EditPanelBloc());
|
2022-03-25 15:02:43 +08:00
|
|
|
getIt.registerFactory<SplashBloc>(() => SplashBloc());
|
|
|
|
getIt.registerLazySingleton<NetworkListener>(() => NetworkListener());
|
|
|
|
}
|
|
|
|
|
|
|
|
void _resolveHomeDeps(GetIt getIt) {
|
2022-06-01 15:22:18 +08:00
|
|
|
getIt.registerSingleton(FToast());
|
|
|
|
|
2022-04-26 14:43:42 +08:00
|
|
|
getIt.registerSingleton(MenuSharedState());
|
|
|
|
|
2022-07-19 14:40:56 +08:00
|
|
|
getIt.registerFactoryParam<UserListener, UserProfilePB, void>(
|
2022-07-04 10:59:08 +08:00
|
|
|
(user, _) => UserListener(userProfile: user),
|
2022-03-25 15:02:43 +08:00
|
|
|
);
|
|
|
|
|
2023-09-11 21:32:26 -05:00
|
|
|
getIt.registerFactoryParam<WorkspaceBloc, UserProfilePB, void>(
|
|
|
|
(user, _) => WorkspaceBloc(
|
2023-02-26 16:27:17 +08:00
|
|
|
userService: UserBackendService(userId: user.id),
|
2022-03-25 15:02:43 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
// share
|
2022-07-19 14:11:29 +08:00
|
|
|
getIt.registerFactoryParam<DocShareBloc, ViewPB, void>(
|
2023-06-10 22:38:25 +08:00
|
|
|
(view, _) => DocShareBloc(view: view),
|
2023-04-10 15:10:42 +08:00
|
|
|
);
|
2023-07-12 13:13:18 +02:00
|
|
|
|
2023-10-02 09:12:24 +02:00
|
|
|
getIt.registerSingleton<NotificationActionBloc>(NotificationActionBloc());
|
|
|
|
|
2023-07-12 13:13:18 +02:00
|
|
|
getIt.registerLazySingleton<TabsBloc>(() => TabsBloc());
|
2023-10-02 09:12:24 +02:00
|
|
|
|
2023-11-09 00:32:10 +01:00
|
|
|
getIt.registerSingleton<ReminderBloc>(ReminderBloc());
|
2024-01-29 20:55:37 +01:00
|
|
|
|
|
|
|
getIt.registerSingleton<RenameViewBloc>(RenameViewBloc(PopoverController()));
|
2022-03-25 15:02:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void _resolveFolderDeps(GetIt getIt) {
|
|
|
|
//workspace
|
2022-07-19 14:40:56 +08:00
|
|
|
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
|
2023-10-12 06:54:08 +02:00
|
|
|
(user, workspaceId) => WorkspaceListener(
|
|
|
|
user: user,
|
|
|
|
workspaceId: workspaceId,
|
|
|
|
),
|
2023-04-10 15:10:42 +08:00
|
|
|
);
|
2022-03-25 15:02:43 +08:00
|
|
|
|
2022-07-19 14:11:29 +08:00
|
|
|
getIt.registerFactoryParam<ViewBloc, ViewPB, void>(
|
2022-03-25 15:02:43 +08:00
|
|
|
(view, _) => ViewBloc(
|
|
|
|
view: view,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-07-22 00:01:39 +08:00
|
|
|
//Settings
|
2022-07-22 00:21:07 +08:00
|
|
|
getIt.registerFactoryParam<SettingsDialogBloc, UserProfilePB, void>(
|
2022-07-22 00:01:39 +08:00
|
|
|
(user, _) => SettingsDialogBloc(user),
|
|
|
|
);
|
|
|
|
|
2022-07-09 22:00:17 +08:00
|
|
|
//User
|
2022-07-22 00:21:07 +08:00
|
|
|
getIt.registerFactoryParam<SettingsUserViewBloc, UserProfilePB, void>(
|
2022-07-09 22:00:17 +08:00
|
|
|
(user, _) => SettingsUserViewBloc(user),
|
|
|
|
);
|
|
|
|
|
2022-03-25 15:02:43 +08:00
|
|
|
// trash
|
|
|
|
getIt.registerLazySingleton<TrashService>(() => TrashService());
|
|
|
|
getIt.registerLazySingleton<TrashListener>(() => TrashListener());
|
|
|
|
getIt.registerFactory<TrashBloc>(
|
2022-10-25 16:51:51 +08:00
|
|
|
() => TrashBloc(),
|
2022-03-25 15:02:43 +08:00
|
|
|
);
|
2023-08-02 18:50:51 +05:30
|
|
|
getIt.registerFactory<FavoriteBloc>(() => FavoriteBloc());
|
2022-03-25 15:02:43 +08:00
|
|
|
}
|