AppFlowy/app_flowy/lib/startup/tasks/sdk_task.dart

53 lines
1.6 KiB
Dart
Raw Normal View History

2021-06-19 15:41:19 +00:00
import 'dart:io';
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/startup.dart';
import 'package:bloc/bloc.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flowy_sdk/flowy_sdk.dart';
import 'package:flutter/material.dart';
import 'package:flowy_log/flowy_log.dart';
2021-06-19 15:41:19 +00:00
class RustSDKInitTask extends LaunchTask {
@override
LaunchTaskType get type => LaunchTaskType.dataProcessing;
@override
2021-07-12 15:27:58 +00:00
Future<void> initialize(LaunchContext context) async {
2021-06-19 15:41:19 +00:00
WidgetsFlutterBinding.ensureInitialized();
Bloc.observer = ApplicationBlocObserver();
2021-07-03 13:40:13 +00:00
Directory directory = await getApplicationDocumentsDirectory();
final documentPath = directory.path;
2021-07-12 15:27:58 +00:00
2021-10-11 05:15:41 +00:00
return Directory('$documentPath/flowy').create().then((Directory directory) async {
2021-07-29 09:46:20 +00:00
switch (context.env) {
case IntegrationEnv.dev:
// await context.getIt<FlowySDK>().init(Directory('./temp/flowy_dev'));
await context.getIt<FlowySDK>().init(directory);
break;
case IntegrationEnv.pro:
await context.getIt<FlowySDK>().init(directory);
break;
default:
assert(false, 'Unsupported env');
}
});
2021-06-19 15:41:19 +00:00
}
}
class ApplicationBlocObserver extends BlocObserver {
@override
2021-07-24 10:55:13 +00:00
// ignore: unnecessary_overrides
2021-06-19 15:41:19 +00:00
void onTransition(Bloc bloc, Transition transition) {
2021-10-11 05:15:41 +00:00
Log.debug("[current]: ${transition.currentState} \n[next]: ${transition.nextState}");
2021-06-19 15:41:19 +00:00
super.onTransition(bloc, transition);
}
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
Log.debug(error);
super.onError(bloc, error, stackTrace);
}
}