mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
b4d22bab14
* feat: implement folder indexer * feat: sqlite search views using fts5 * feat: add view indexing to user manager * feat: implement folder indexer * feat: add sqlite search documents * feat: add document indexing to user manager * feat: add document indexing to folder indexer * chore: update collab rev * feat: search frontend integration * refactor: search index * test: add event test * chore: fix ci * feat: initial command palette overlay impl (#4619) * chore: test search engine * chore: initial structure * chore: replace old search request * chore: enable log for lib-dispatch * chore: move search manager to core * feat: move traits and responsibility to search crate * feat: move search to search crate * feat: replace sqlite with tantivy * feat: deserialize tantivy documents * chore: fixes after rebase * chore: clean code * feat: fetch and sort results * fix: code review + cleaning * feat: support custom icons * feat: support view layout icons * feat: rename bloc and fix indexing * fix: prettify dialog * feat: score results * chore: update collab rev * feat: add recent view history to command palette * test: add integration_tests * fix: clippy changes * fix: focus traversal in cmd palette * fix: remove file after merging main * chore: code review and panic-safe * feat: index all views if index does not exist * chore: improve logic with conditional * chore: add is_empty check * chore: abstract logic from folder manager init * chore: update collab rev * chore: code review * chore: fixes after merge + update lock file * chore: revert cargo lock * fix: set icon type when removing icon * fix: code review + dependency inversion * fix: remove icon fix for not persisting icon type * test: simple tests manipulating views * test: create 100 views * fix: tauri build * chore: create 1000 views * chore: create util methods * chore: test * chore: test * chore: remove logs * chore: fix build.rs * chore: export models * chore: enable clear cache on Rust-CI * fix: navigate to newly created views * fix: force disable setting workspace listener on rebuilds * fix: remove late final * fix: missing returns * fix: localization and minor fixes * test: add index assert to large test * fix: missing section param after merging main * chore: try fix unzip file error * chore: lower the test * feat: show hint when result is in trash * feat: one index_writer per index * fix: minor changes after merge * fix: make create_log_filter public after merge * chore: fix test * chore: fix test * chore: flutter analyze * chore: flutter analyze * chore: fix tauri build --------- Co-authored-by: nathan <nathan@appflowy.io> Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Nathan.fooo <86001920+appflowy@users.noreply.github.com>
238 lines
8.1 KiB
Dart
238 lines
8.1 KiB
Dart
import 'package:appflowy/core/config/kv.dart';
|
|
import 'package:appflowy/core/network_monitor.dart';
|
|
import 'package:appflowy/env/cloud_env.dart';
|
|
import 'package:appflowy/plugins/document/application/prelude.dart';
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/openai_client.dart';
|
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
|
|
import 'package:appflowy/plugins/trash/application/prelude.dart';
|
|
import 'package:appflowy/shared/appflowy_cache_manager.dart';
|
|
import 'package:appflowy/shared/custom_image_cache_manager.dart';
|
|
import 'package:appflowy/startup/startup.dart';
|
|
import 'package:appflowy/startup/tasks/appflowy_cloud_task.dart';
|
|
import 'package:appflowy/user/application/auth/af_cloud_auth_service.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/prelude.dart';
|
|
import 'package:appflowy/user/application/reminder/reminder_bloc.dart';
|
|
import 'package:appflowy/user/application/user_listener.dart';
|
|
import 'package:appflowy/user/application/user_service.dart';
|
|
import 'package:appflowy/user/presentation/router.dart';
|
|
import 'package:appflowy/workspace/application/action_navigation/action_navigation_bloc.dart';
|
|
import 'package:appflowy/workspace/application/edit_panel/edit_panel_bloc.dart';
|
|
import 'package:appflowy/workspace/application/favorite/favorite_bloc.dart';
|
|
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';
|
|
import 'package:appflowy/workspace/application/settings/prelude.dart';
|
|
import 'package:appflowy/workspace/application/sidebar/rename_view/rename_view_bloc.dart';
|
|
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
|
|
import 'package:appflowy/workspace/application/user/prelude.dart';
|
|
import 'package:appflowy/workspace/application/view/prelude.dart';
|
|
import 'package:appflowy/workspace/application/workspace/prelude.dart';
|
|
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
|
|
import 'package:appflowy_backend/log.dart';
|
|
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
|
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
|
|
import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
|
|
import 'package:appflowy_popover/appflowy_popover.dart';
|
|
import 'package:flowy_infra/file_picker/file_picker_impl.dart';
|
|
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class DependencyResolver {
|
|
static Future<void> resolve(
|
|
GetIt getIt,
|
|
IntegrationMode mode,
|
|
) async {
|
|
// getIt.registerFactory<KeyValueStorage>(() => RustKeyValue());
|
|
getIt.registerFactory<KeyValueStorage>(() => DartKeyValue());
|
|
|
|
await _resolveCloudDeps(getIt);
|
|
_resolveUserDeps(getIt, mode);
|
|
_resolveHomeDeps(getIt);
|
|
_resolveFolderDeps(getIt);
|
|
_resolveCommonService(getIt, mode);
|
|
}
|
|
}
|
|
|
|
Future<void> _resolveCloudDeps(GetIt getIt) async {
|
|
final env = await AppFlowyCloudSharedEnv.fromEnv();
|
|
Log.info("cloud setting: $env");
|
|
getIt.registerFactory<AppFlowyCloudSharedEnv>(() => env);
|
|
|
|
if (isAppFlowyCloudEnabled) {
|
|
getIt.registerSingleton(
|
|
AppFlowyCloudDeepLink(),
|
|
dispose: (obj) async {
|
|
await obj.dispose();
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
void _resolveCommonService(
|
|
GetIt getIt,
|
|
IntegrationMode mode,
|
|
) async {
|
|
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(
|
|
(s) {
|
|
return HttpOpenAIRepository(
|
|
client: http.Client(),
|
|
apiKey: s.openaiKey,
|
|
);
|
|
},
|
|
(e) {
|
|
throw Exception('Failed to get user profile: ${e.msg}');
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
getIt.registerFactoryAsync<StabilityAIRepository>(
|
|
() async {
|
|
final result = await UserBackendService.getCurrentUserProfile();
|
|
return result.fold(
|
|
(s) {
|
|
return HttpStabilityAIRepository(
|
|
client: http.Client(),
|
|
apiKey: s.stabilityAiKey,
|
|
);
|
|
},
|
|
(e) {
|
|
throw Exception('Failed to get user profile: ${e.msg}');
|
|
},
|
|
);
|
|
},
|
|
);
|
|
|
|
getIt.registerFactory<ClipboardService>(
|
|
() => ClipboardService(),
|
|
);
|
|
|
|
// theme
|
|
getIt.registerFactory<BaseAppearance>(
|
|
() => PlatformExtension.isMobile ? MobileAppearance() : DesktopAppearance(),
|
|
);
|
|
|
|
getIt.registerFactory<FlowyCacheManager>(
|
|
() => FlowyCacheManager()
|
|
..registerCache(TemporaryDirectoryCache())
|
|
..registerCache(CustomImageCacheManager())
|
|
..registerCache(FeatureFlagCache()),
|
|
);
|
|
}
|
|
|
|
void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
|
|
switch (currentCloudType()) {
|
|
case AuthenticatorType.local:
|
|
getIt.registerFactory<AuthService>(
|
|
() => BackendAuthService(
|
|
AuthenticatorPB.Local,
|
|
),
|
|
);
|
|
break;
|
|
case AuthenticatorType.supabase:
|
|
getIt.registerFactory<AuthService>(() => SupabaseAuthService());
|
|
break;
|
|
case AuthenticatorType.appflowyCloud:
|
|
case AuthenticatorType.appflowyCloudSelfHost:
|
|
case AuthenticatorType.appflowyCloudDevelop:
|
|
getIt.registerFactory<AuthService>(() => AppFlowyCloudAuthService());
|
|
break;
|
|
}
|
|
|
|
getIt.registerFactory<AuthRouter>(() => AuthRouter());
|
|
|
|
getIt.registerFactory<SignInBloc>(
|
|
() => SignInBloc(getIt<AuthService>()),
|
|
);
|
|
getIt.registerFactory<SignUpBloc>(
|
|
() => SignUpBloc(getIt<AuthService>()),
|
|
);
|
|
|
|
getIt.registerFactory<SplashRouter>(() => SplashRouter());
|
|
getIt.registerFactory<EditPanelBloc>(() => EditPanelBloc());
|
|
getIt.registerFactory<SplashBloc>(() => SplashBloc());
|
|
getIt.registerLazySingleton<NetworkListener>(() => NetworkListener());
|
|
}
|
|
|
|
void _resolveHomeDeps(GetIt getIt) {
|
|
getIt.registerSingleton(FToast());
|
|
|
|
getIt.registerSingleton(MenuSharedState());
|
|
|
|
getIt.registerFactoryParam<UserListener, UserProfilePB, void>(
|
|
(user, _) => UserListener(userProfile: user),
|
|
);
|
|
|
|
getIt.registerFactoryParam<WorkspaceBloc, UserProfilePB, void>(
|
|
(user, _) => WorkspaceBloc(
|
|
userService: UserBackendService(userId: user.id),
|
|
),
|
|
);
|
|
|
|
// share
|
|
getIt.registerFactoryParam<DocumentShareBloc, ViewPB, void>(
|
|
(view, _) => DocumentShareBloc(view: view),
|
|
);
|
|
|
|
getIt.registerSingleton<ActionNavigationBloc>(ActionNavigationBloc());
|
|
|
|
getIt.registerLazySingleton<TabsBloc>(() => TabsBloc());
|
|
|
|
getIt.registerSingleton<ReminderBloc>(ReminderBloc());
|
|
|
|
getIt.registerSingleton<RenameViewBloc>(RenameViewBloc(PopoverController()));
|
|
}
|
|
|
|
void _resolveFolderDeps(GetIt getIt) {
|
|
//workspace
|
|
getIt.registerFactoryParam<WorkspaceListener, UserProfilePB, String>(
|
|
(user, workspaceId) => WorkspaceListener(
|
|
user: user,
|
|
workspaceId: workspaceId,
|
|
),
|
|
);
|
|
|
|
getIt.registerFactoryParam<ViewBloc, ViewPB, void>(
|
|
(view, _) => ViewBloc(
|
|
view: view,
|
|
),
|
|
);
|
|
|
|
//Settings
|
|
getIt.registerFactoryParam<SettingsDialogBloc, UserProfilePB, void>(
|
|
(user, _) => SettingsDialogBloc(user),
|
|
);
|
|
|
|
//User
|
|
getIt.registerFactoryParam<SettingsUserViewBloc, UserProfilePB, void>(
|
|
(user, _) => SettingsUserViewBloc(user),
|
|
);
|
|
|
|
// trash
|
|
getIt.registerLazySingleton<TrashService>(() => TrashService());
|
|
getIt.registerLazySingleton<TrashListener>(() => TrashListener());
|
|
getIt.registerFactory<TrashBloc>(
|
|
() => TrashBloc(),
|
|
);
|
|
getIt.registerFactory<FavoriteBloc>(() => FavoriteBloc());
|
|
}
|