startup.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:app_flowy/startup/launcher.dart';
  2. import 'package:app_flowy/startup/tasks/prelude.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get_it/get_it.dart';
  5. import 'package:app_flowy/workspace/infrastructure/deps_resolver.dart';
  6. import 'package:app_flowy/user/infrastructure/deps_resolver.dart';
  7. import 'package:flowy_sdk/flowy_sdk.dart';
  8. import 'tasks/init_platform_service.dart';
  9. // [[diagram: flowy startup flow]]
  10. // ┌──────────┐
  11. // │ FlowyApp │
  12. // └──────────┘
  13. // │ impl
  14. // ▼
  15. // ┌────────┐ 1.run ┌──────────┐
  16. // │ System │───┬───▶│EntryPoint│
  17. // └────────┘ │ └──────────┘ ┌─────────────────┐
  18. // │ ┌──▶ │ RustSDKInitTask │
  19. // │ ┌───────────┐ │ └─────────────────┘
  20. // └──▶ │AppLauncher│───┤
  21. // 2.launch └───────────┘ │ ┌─────────────┐ ┌──────────────────┐ ┌───────────────┐
  22. // └───▶│AppWidgetTask│────────▶│ApplicationWidget │─────▶│ SplashScreen │
  23. // └─────────────┘ └──────────────────┘ └───────────────┘
  24. //
  25. // 3.build MeterialApp
  26. final getIt = GetIt.instance;
  27. enum IntegrationEnv {
  28. dev,
  29. pro,
  30. }
  31. abstract class EntryPoint {
  32. Widget create();
  33. }
  34. class System {
  35. static void run(EntryPoint f) {
  36. // Specify the env
  37. const env = IntegrationEnv.dev;
  38. // Config the deps graph
  39. getIt.registerFactory<EntryPoint>(() => f);
  40. resolveDependencies(env);
  41. // add task
  42. getIt<AppLauncher>().addTask(InitRustSDKTask());
  43. getIt<AppLauncher>().addTask(AppWidgetTask());
  44. getIt<AppLauncher>().addTask(InitPlatformService());
  45. // execute the tasks
  46. getIt<AppLauncher>().launch();
  47. }
  48. }
  49. void resolveDependencies(IntegrationEnv env) => initGetIt(getIt, env);
  50. Future<void> initGetIt(
  51. GetIt getIt,
  52. IntegrationEnv env,
  53. ) async {
  54. getIt.registerLazySingleton<FlowySDK>(() => const FlowySDK());
  55. getIt.registerLazySingleton<AppLauncher>(() => AppLauncher(env, getIt));
  56. await UserDepsResolver.resolve(getIt);
  57. await HomeDepsResolver.resolve(getIt);
  58. }