startup.dart 2.7 KB

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