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

191 lines
6.4 KiB
Dart
Raw Normal View History

import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/network_monitor.dart';
import 'package:appflowy/env/env.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';
feat: integrate new editor (#2536) * feat: update editor * feat: integrate new editor * feat: integrate the document2 into folder2 * feat: integrate the new editor * chore: cargo fix * chore: active document feature for flowy-error * feat: convert the editor action to collab action * feat: migrate the grid and board * feat: migrate the callout block * feat: migrate the divider * chore: migrate the callout and math equation * feat: migrate the code block * feat: add shift + enter command in code block * feat: support tab and shift+tab in code block * fix: cursor error after inserting divider * feat: migrate the grid and board * feat: migrate the emoji picker * feat: migrate openai * feat: integrate floating toolbar * feat: migrate the smart editor * feat: migrate the cover * feat: add option block action * chore: implement block selection and delete option * feat: support background color * feat: dismiss color picker afer setting color * feat: migrate the cover block * feat: resize the font * chore: cutomsize the padding * chore: wrap the option button with ignore widget * feat: customize the heading style * chore: optimize the divider line height * fix: the option button can't dismiss * ci: rust test * chore: flutter analyze * fix: code block selection * fix: dismiss the emoji picker after selecting one * chore: optimize the transaction adapter * fix: can't save the new content * feat: show export page when some errors happen * feat: implement get_view_data for document --------- Co-authored-by: nathan <nathan@appflowy.io>
2023-05-16 06:58:24 +00:00
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_client.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy/user/application/auth/supabase_auth_service.dart';
import 'package:appflowy/user/application/user_listener.dart';
import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
feat: Dynamically Load Themes in AppFlowy (#2670) * feat: dynamic theme plugin (init) * feat: provide fallback color if plugin becomes out of date (transparent) * feat: use applicationDocumentsDirectory to store plugins * chore: remove json files * fix: add toJson to resolve analyzer errors * fix: analyzer (unused imports) * feat: add code generation scripts for freezed files (call recursively in packages) * fix: revert changes to dry generation * feat: call directly into script * refactor: scripts try to be stateless :) * fix: path to code generation in toml * fix: generate script permissions * fix: path not correct in generate.sh * feat: modify execution permissions before executing scripts * chore: switch order of build_runner and easy_localizations * fix: fs is not valid duckscript cmd * chore: clean build_runner before executing * chore: upgrade freezed and build_runner attempt to resolve InvalidType error * fix: use exec cmd.exe to chmod * feat: add task to generate all files * chore: remove redundant task (Code Gen) * chore: remove json_annoation to dev_dependencies * fix: dropped & between commands * chore: rename file and class to FlowyDynamicPlugin * fix: dependency hell * fix: json annotation in colorscheme * fix: analyzer warnings * fix: duckscript runner for code generator * fix: try without setting file permissions * chore: move file picker to infra * chore: restructure project directory * feat: add BLoC components for consumers * chore: update dependencies in pubspec.yaml file * fix: file picker imports * feat: add new translations for features * feat: add new widgets to render upload * fix: import * feat: add text overflow * feat: use animated switcher * chore: export FileType * fix: directory was not created, only files were copied * chore: separate some logic * feat: add saveFile to FilePickerService * fix: analyzer error with unused imports * feat: add translations for uploading * feat: add builtins property to apptheme * feat: add theme preview widget * fix: upload widgets need to fill whole space and account for overflow * refactor: do not watch file system for changes * feat: add deletion confirmation dialog * feat: add form factor resolution for dyanmic layout * feat: trigger rebuild only when plugins are loaded * feat: make all methods static * chore: remove TODO comment, requires further design * chore: move models to subfolder * fix: references to plugin service instance * fix: rebase errors * fix: more rebasing errors * feat: remove multiple themes from one plugin * refactor: use pattern to resolve widget in settings_appearance_view * refactor: remove commented code * feat: add translations * fix: import error * refactor: separate concerns a bit more * fix: bug in toJson serialization code * feat: add package to use represent memory files * fix: analyzer warnings * chore: add translation * chore: remove unused exceptions * chore: use join * chore: add documentation * feat: add tests on theme * fix: fix scripts for macOS * feat: use appFlowyDocumentDirectory * fix: remove unused import * fix: imports * feat: allow plugin service to be passed * fix: theme tests * feat: separate themes by built-in and plugin * fix: rebase change name of appFlowyDocumentDirectory * chore: add test to check that initial state falls back to initial theme * chore: theme upload preview widget * chore: rename to brightness setting * refactor: appearance for settings appearance view * feat: change show dialog api and use it * fix: handle plugin compilation exception when incorrect format supplied * fix: style of theme upload * fix: always change state so that ui updates * chore: style of loading widget * fix: analyzer errors * feat: add learn more button to documentation --------- Co-authored-by: Yijing Huang <hyj891204@gmail.com> Co-authored-by: nathan <nathan@appflowy.io>
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';
import 'package:appflowy/plugins/document/application/prelude.dart';
2023-08-02 13:20:51 +00:00
import 'package:appflowy/workspace/application/favorite/favorite_bloc.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/menu/menu.dart';
import 'package:appflowy_backend/protobuf/flowy-folder2/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';
import 'package:http/http.dart' as http;
2022-03-25 07:02:43 +00:00
class DependencyResolver {
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);
_resolveCommonService(getIt, mode);
2022-03-25 07:02:43 +00:00
}
}
void _resolveCommonService(
GetIt getIt,
IntegrationMode mode,
) async {
// getIt.registerFactory<KeyValueStorage>(() => RustKeyValue());
getIt.registerFactory<KeyValueStorage>(() => DartKeyValue());
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
getIt.registerFactory<FilePickerService>(() => FilePicker());
if (mode.isTest) {
getIt.registerFactory<ApplicationDataStorage>(
() => MockApplicationDataStorage(),
);
} else {
getIt.registerFactory<ApplicationDataStorage>(
() => ApplicationDataStorage(),
);
}
getIt.registerFactoryAsync<OpenAIRepository>(
() async {
final result = await UserBackendService.getCurrentUserProfile();
return result.fold(
(l) {
feat: integrate new editor (#2536) * feat: update editor * feat: integrate new editor * feat: integrate the document2 into folder2 * feat: integrate the new editor * chore: cargo fix * chore: active document feature for flowy-error * feat: convert the editor action to collab action * feat: migrate the grid and board * feat: migrate the callout block * feat: migrate the divider * chore: migrate the callout and math equation * feat: migrate the code block * feat: add shift + enter command in code block * feat: support tab and shift+tab in code block * fix: cursor error after inserting divider * feat: migrate the grid and board * feat: migrate the emoji picker * feat: migrate openai * feat: integrate floating toolbar * feat: migrate the smart editor * feat: migrate the cover * feat: add option block action * chore: implement block selection and delete option * feat: support background color * feat: dismiss color picker afer setting color * feat: migrate the cover block * feat: resize the font * chore: cutomsize the padding * chore: wrap the option button with ignore widget * feat: customize the heading style * chore: optimize the divider line height * fix: the option button can't dismiss * ci: rust test * chore: flutter analyze * fix: code block selection * fix: dismiss the emoji picker after selecting one * chore: optimize the transaction adapter * fix: can't save the new content * feat: show export page when some errors happen * feat: implement get_view_data for document --------- Co-authored-by: nathan <nathan@appflowy.io>
2023-05-16 06:58:24 +00:00
throw Exception('Failed to get user profile: ${l.msg}');
},
(r) {
return HttpOpenAIRepository(
client: http.Client(),
feat: integrate new editor (#2536) * feat: update editor * feat: integrate new editor * feat: integrate the document2 into folder2 * feat: integrate the new editor * chore: cargo fix * chore: active document feature for flowy-error * feat: convert the editor action to collab action * feat: migrate the grid and board * feat: migrate the callout block * feat: migrate the divider * chore: migrate the callout and math equation * feat: migrate the code block * feat: add shift + enter command in code block * feat: support tab and shift+tab in code block * fix: cursor error after inserting divider * feat: migrate the grid and board * feat: migrate the emoji picker * feat: migrate openai * feat: integrate floating toolbar * feat: migrate the smart editor * feat: migrate the cover * feat: add option block action * chore: implement block selection and delete option * feat: support background color * feat: dismiss color picker afer setting color * feat: migrate the cover block * feat: resize the font * chore: cutomsize the padding * chore: wrap the option button with ignore widget * feat: customize the heading style * chore: optimize the divider line height * fix: the option button can't dismiss * ci: rust test * chore: flutter analyze * fix: code block selection * fix: dismiss the emoji picker after selecting one * chore: optimize the transaction adapter * fix: can't save the new content * feat: show export page when some errors happen * feat: implement get_view_data for document --------- Co-authored-by: nathan <nathan@appflowy.io>
2023-05-16 06:58:24 +00:00
apiKey: r.openaiKey,
);
},
);
},
);
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
}
2022-03-25 07:02:43 +00:00
void _resolveUserDeps(GetIt getIt) {
if (isSupabaseEnabled) {
getIt.registerFactory<AuthService>(() => SupabaseAuthService());
} else {
getIt.registerFactory<AuthService>(() => AppFlowyAuthService());
}
2022-03-25 07:02:43 +00:00
getIt.registerFactory<AuthRouter>(() => AuthRouter());
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
);
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
2022-07-19 06:11:29 +00:00
getIt.registerFactoryParam<DocShareBloc, ViewPB, void>(
(view, _) => DocShareBloc(view: view),
);
getIt.registerLazySingleton<TabsBloc>(() => TabsBloc());
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>(
(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
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
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>(
() => 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
}
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, FieldContext, 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
);
feat: integrate new editor (#2536) * feat: update editor * feat: integrate new editor * feat: integrate the document2 into folder2 * feat: integrate the new editor * chore: cargo fix * chore: active document feature for flowy-error * feat: convert the editor action to collab action * feat: migrate the grid and board * feat: migrate the callout block * feat: migrate the divider * chore: migrate the callout and math equation * feat: migrate the code block * feat: add shift + enter command in code block * feat: support tab and shift+tab in code block * fix: cursor error after inserting divider * feat: migrate the grid and board * feat: migrate the emoji picker * feat: migrate openai * feat: integrate floating toolbar * feat: migrate the smart editor * feat: migrate the cover * feat: add option block action * chore: implement block selection and delete option * feat: support background color * feat: dismiss color picker afer setting color * feat: migrate the cover block * feat: resize the font * chore: cutomsize the padding * chore: wrap the option button with ignore widget * feat: customize the heading style * chore: optimize the divider line height * fix: the option button can't dismiss * ci: rust test * chore: flutter analyze * fix: code block selection * fix: dismiss the emoji picker after selecting one * chore: optimize the transaction adapter * fix: can't save the new content * feat: show export page when some errors happen * feat: implement get_view_data for document --------- Co-authored-by: nathan <nathan@appflowy.io>
2023-05-16 06:58:24 +00:00
}