2021-06-19 23:41:19 +08:00
|
|
|
import 'dart:io';
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/appflowy_backend.dart';
|
2022-12-20 11:14:42 +08:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
import '../startup.dart';
|
2021-06-19 23:41:19 +08:00
|
|
|
|
2021-12-04 22:24:32 +08:00
|
|
|
class InitRustSDKTask extends LaunchTask {
|
2022-12-20 11:14:42 +08:00
|
|
|
InitRustSDKTask({
|
|
|
|
this.directory,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Customize the RustSDK initialization path
|
|
|
|
final Future<Directory>? directory;
|
|
|
|
|
2021-06-19 23:41:19 +08:00
|
|
|
@override
|
|
|
|
LaunchTaskType get type => LaunchTaskType.dataProcessing;
|
|
|
|
|
|
|
|
@override
|
2021-07-12 23:27:58 +08:00
|
|
|
Future<void> initialize(LaunchContext context) async {
|
2022-12-20 11:14:42 +08:00
|
|
|
// use the custom directory
|
|
|
|
if (directory != null) {
|
|
|
|
return directory!.then((directory) async {
|
|
|
|
await context.getIt<FlowySDK>().init(directory);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return appFlowyDocumentDirectory().then((directory) async {
|
|
|
|
await context.getIt<FlowySDK>().init(directory);
|
|
|
|
});
|
|
|
|
}
|
2022-04-28 20:54:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Directory> appFlowyDocumentDirectory() async {
|
|
|
|
switch (integrationEnv()) {
|
|
|
|
case IntegrationMode.develop:
|
2022-10-15 23:34:56 +08:00
|
|
|
Directory documentsDir = await getApplicationDocumentsDirectory();
|
2022-04-28 20:54:04 +08:00
|
|
|
return Directory('${documentsDir.path}/flowy_dev').create();
|
|
|
|
case IntegrationMode.release:
|
2022-10-15 23:34:56 +08:00
|
|
|
Directory documentsDir = await getApplicationDocumentsDirectory();
|
2022-04-28 20:54:04 +08:00
|
|
|
return Directory('${documentsDir.path}/flowy').create();
|
|
|
|
case IntegrationMode.test:
|
|
|
|
return Directory("${Directory.current.path}/.sandbox");
|
2022-02-19 23:19:33 +08:00
|
|
|
}
|
2021-06-19 23:41:19 +08:00
|
|
|
}
|