2021-10-11 05:15:41 +00:00
|
|
|
import 'package:app_flowy/startup/launcher.dart';
|
2021-06-19 15:41:19 +00:00
|
|
|
import 'package:app_flowy/startup/tasks/prelude.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get_it/get_it.dart';
|
2021-10-11 05:15:41 +00:00
|
|
|
import 'package:app_flowy/workspace/infrastructure/deps_resolver.dart';
|
|
|
|
import 'package:app_flowy/user/infrastructure/deps_resolver.dart';
|
|
|
|
import 'package:flowy_sdk/flowy_sdk.dart';
|
2021-06-19 15:41:19 +00:00
|
|
|
|
2021-12-04 14:24:32 +00:00
|
|
|
import 'tasks/init_platform_service.dart';
|
|
|
|
|
2021-10-11 05:15:41 +00:00
|
|
|
// [[diagram: flowy startup flow]]
|
|
|
|
// ┌──────────┐
|
|
|
|
// │ FlowyApp │
|
|
|
|
// └──────────┘
|
|
|
|
// │ impl
|
|
|
|
// ▼
|
|
|
|
// ┌────────┐ 1.run ┌──────────┐
|
|
|
|
// │ System │───┬───▶│EntryPoint│
|
|
|
|
// └────────┘ │ └──────────┘ ┌─────────────────┐
|
|
|
|
// │ ┌──▶ │ RustSDKInitTask │
|
|
|
|
// │ ┌───────────┐ │ └─────────────────┘
|
|
|
|
// └──▶ │AppLauncher│───┤
|
|
|
|
// 2.launch └───────────┘ │ ┌─────────────┐ ┌──────────────────┐ ┌───────────────┐
|
|
|
|
// └───▶│AppWidgetTask│────────▶│ApplicationWidget │─────▶│ SplashScreen │
|
|
|
|
// └─────────────┘ └──────────────────┘ └───────────────┘
|
|
|
|
//
|
|
|
|
// 3.build MeterialApp
|
2021-06-19 15:41:19 +00:00
|
|
|
final getIt = GetIt.instance;
|
|
|
|
enum IntegrationEnv {
|
|
|
|
dev,
|
|
|
|
pro,
|
|
|
|
}
|
|
|
|
|
2021-09-12 14:19:59 +00:00
|
|
|
abstract class EntryPoint {
|
2021-06-19 15:41:19 +00:00
|
|
|
Widget create();
|
|
|
|
}
|
|
|
|
|
2021-09-12 14:19:59 +00:00
|
|
|
class System {
|
|
|
|
static void run(EntryPoint f) {
|
2021-11-19 07:23:58 +00:00
|
|
|
// Specify the env
|
2021-06-19 15:41:19 +00:00
|
|
|
const env = IntegrationEnv.dev;
|
|
|
|
|
|
|
|
// Config the deps graph
|
2021-09-12 14:19:59 +00:00
|
|
|
getIt.registerFactory<EntryPoint>(() => f);
|
2021-06-19 15:41:19 +00:00
|
|
|
|
|
|
|
resolveDependencies(env);
|
|
|
|
|
|
|
|
// add task
|
2021-12-04 14:24:32 +00:00
|
|
|
getIt<AppLauncher>().addTask(InitRustSDKTask());
|
2021-06-19 15:41:19 +00:00
|
|
|
getIt<AppLauncher>().addTask(AppWidgetTask());
|
2021-12-04 14:24:32 +00:00
|
|
|
getIt<AppLauncher>().addTask(InitPlatformService());
|
2021-06-19 15:41:19 +00:00
|
|
|
|
|
|
|
// execute the tasks
|
|
|
|
getIt<AppLauncher>().launch();
|
|
|
|
}
|
|
|
|
}
|
2021-10-11 05:15:41 +00:00
|
|
|
|
|
|
|
void resolveDependencies(IntegrationEnv env) => initGetIt(getIt, env);
|
|
|
|
|
|
|
|
Future<void> initGetIt(
|
|
|
|
GetIt getIt,
|
|
|
|
IntegrationEnv env,
|
|
|
|
) async {
|
|
|
|
getIt.registerLazySingleton<FlowySDK>(() => const FlowySDK());
|
|
|
|
getIt.registerLazySingleton<AppLauncher>(() => AppLauncher(env, getIt));
|
|
|
|
|
|
|
|
await UserDepsResolver.resolve(getIt);
|
|
|
|
await HomeDepsResolver.resolve(getIt);
|
|
|
|
}
|