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';
|
2023-05-16 06:58:24 +00:00
|
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_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';
|
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';
|
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';
|
|
|
|
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';
|
2023-10-17 06:48:58 +00:00
|
|
|
import 'package:appflowy/workspace/application/notifications/notification_action_bloc.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';
|
|
|
|
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-04-04 00:41:16 +00:00
|
|
|
import 'package:appflowy_backend/protobuf/flowy-folder2/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;
|
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();
|
2023-12-27 03:42:39 +00:00
|
|
|
Log.info("cloud setting: \n$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());
|
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
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
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(
|
|
|
|
(l) {
|
|
|
|
throw Exception('Failed to get user profile: ${l.msg}');
|
|
|
|
},
|
|
|
|
(r) {
|
|
|
|
return HttpStabilityAIRepository(
|
|
|
|
client: http.Client(),
|
|
|
|
apiKey: r.stabilityAiKey,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
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(),
|
|
|
|
);
|
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:
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
);
|
|
|
|
|
2023-09-12 02:32:26 +00:00
|
|
|
getIt.registerFactoryParam<WorkspaceBloc, UserProfilePB, void>(
|
|
|
|
(user, _) => WorkspaceBloc(
|
2023-02-26 08:27:17 +00:00
|
|
|
userService: UserBackendService(userId: user.id),
|
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
|
|
|
);
|
2023-07-12 11:13:18 +00:00
|
|
|
|
2023-10-02 07:12:24 +00:00
|
|
|
getIt.registerSingleton<NotificationActionBloc>(NotificationActionBloc());
|
|
|
|
|
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());
|
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-10-12 04:54:08 +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,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
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
|
|
|
);
|
2023-08-02 13:20:51 +00:00
|
|
|
getIt.registerFactory<FavoriteBloc>(() => FavoriteBloc());
|
2022-03-25 07:02:43 +00:00
|
|
|
}
|