2021-06-19 23:41:19 +08:00
|
|
|
import 'dart:io';
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-05-23 23:55:21 +08:00
|
|
|
import 'package:appflowy/env/env.dart';
|
2023-01-08 12:10:53 +08:00
|
|
|
import 'package:appflowy_backend/appflowy_backend.dart';
|
2023-05-23 23:55:21 +08:00
|
|
|
import 'package:appflowy_backend/env_serde.dart';
|
2022-12-20 11:14:42 +08:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2023-03-14 01:06:08 +08:00
|
|
|
import 'package:path/path.dart' as path;
|
2022-12-20 11:14:42 +08:00
|
|
|
|
|
|
|
import '../startup.dart';
|
2021-06-19 23:41:19 +08:00
|
|
|
|
2021-12-04 22:24:32 +08:00
|
|
|
class InitRustSDKTask extends LaunchTask {
|
2023-05-17 11:03:33 +08:00
|
|
|
const InitRustSDKTask({
|
2022-12-20 11:14:42 +08:00
|
|
|
this.directory,
|
|
|
|
});
|
|
|
|
|
|
|
|
// Customize the RustSDK initialization path
|
2023-05-21 18:53:59 +08:00
|
|
|
final Directory? directory;
|
2022-12-20 11:14:42 +08:00
|
|
|
|
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 {
|
2023-05-21 18:53:59 +08:00
|
|
|
final dir = directory ?? await appFlowyDocumentDirectory();
|
2023-05-23 23:55:21 +08:00
|
|
|
|
|
|
|
context.getIt<FlowySDK>().setEnv(getAppFlowyEnv());
|
2023-05-21 18:53:59 +08:00
|
|
|
await context.getIt<FlowySDK>().init(dir);
|
2022-04-28 20:54:04 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 23:55:21 +08:00
|
|
|
AppFlowyEnv getAppFlowyEnv() {
|
|
|
|
final supabaseConfig = SupabaseConfiguration(
|
|
|
|
url: Env.supabaseUrl,
|
|
|
|
key: Env.supabaseKey,
|
|
|
|
jwt_secret: Env.supabaseJwtSecret,
|
|
|
|
);
|
|
|
|
|
|
|
|
final collabTableConfig =
|
|
|
|
CollabTableConfig(enable: true, table_name: Env.supabaseCollabTable);
|
|
|
|
|
|
|
|
final supbaseDBConfig = SupabaseDBConfig(
|
|
|
|
url: Env.supabaseUrl,
|
|
|
|
key: Env.supabaseKey,
|
|
|
|
jwt_secret: Env.supabaseJwtSecret,
|
|
|
|
collab_table_config: collabTableConfig,
|
|
|
|
);
|
|
|
|
|
|
|
|
return AppFlowyEnv(
|
|
|
|
supabase_config: supabaseConfig,
|
|
|
|
supabase_db_config: supbaseDBConfig,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-28 20:54:04 +08:00
|
|
|
Future<Directory> appFlowyDocumentDirectory() async {
|
|
|
|
switch (integrationEnv()) {
|
|
|
|
case IntegrationMode.develop:
|
2023-06-03 20:43:46 +08:00
|
|
|
Directory documentsDir = await getApplicationSupportDirectory()
|
2023-05-21 18:53:59 +08:00
|
|
|
..create();
|
2023-04-04 08:41:16 +08:00
|
|
|
return Directory(path.join(documentsDir.path, 'data_dev')).create();
|
2022-04-28 20:54:04 +08:00
|
|
|
case IntegrationMode.release:
|
2023-06-03 20:43:46 +08:00
|
|
|
Directory documentsDir = await getApplicationSupportDirectory();
|
2023-04-04 08:41:16 +08:00
|
|
|
return Directory(path.join(documentsDir.path, 'data')).create();
|
2022-04-28 20:54:04 +08:00
|
|
|
case IntegrationMode.test:
|
2023-03-14 01:06:08 +08:00
|
|
|
return Directory(path.join(Directory.current.path, '.sandbox'));
|
2022-02-19 23:19:33 +08:00
|
|
|
}
|
2021-06-19 23:41:19 +08:00
|
|
|
}
|