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-06-21 12:15:32 +08:00
|
|
|
final dir = directory ?? await appFlowyApplicationDataDirectory();
|
2023-05-23 23:55:21 +08:00
|
|
|
|
2023-07-05 20:57:09 +08:00
|
|
|
final env = getAppFlowyEnv();
|
|
|
|
context.getIt<FlowySDK>().setEnv(env);
|
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() {
|
2023-07-05 20:57:09 +08:00
|
|
|
final supabaseConfig = SupabaseConfiguration(
|
2023-07-29 09:46:24 +08:00
|
|
|
enable_sync: true,
|
2023-05-23 23:55:21 +08:00
|
|
|
url: Env.supabaseUrl,
|
2023-07-29 09:46:24 +08:00
|
|
|
anon_key: Env.supabaseAnonKey,
|
2023-05-23 23:55:21 +08:00
|
|
|
jwt_secret: Env.supabaseJwtSecret,
|
|
|
|
);
|
|
|
|
|
|
|
|
return AppFlowyEnv(
|
|
|
|
supabase_config: supabaseConfig,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-21 12:15:32 +08:00
|
|
|
/// The default directory to store the user data. The directory can be
|
|
|
|
/// customized by the user via the [ApplicationDataStorage]
|
|
|
|
Future<Directory> appFlowyApplicationDataDirectory() async {
|
2022-04-28 20:54:04 +08:00
|
|
|
switch (integrationEnv()) {
|
|
|
|
case IntegrationMode.develop:
|
2023-06-07 13:55:37 +05:30
|
|
|
final 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-07 13:55:37 +05:30
|
|
|
final Directory documentsDir = await getApplicationSupportDirectory();
|
2023-04-04 08:41:16 +08:00
|
|
|
return Directory(path.join(documentsDir.path, 'data')).create();
|
2023-07-02 23:37:30 +08:00
|
|
|
case IntegrationMode.unitTest:
|
2023-06-15 22:43:07 +08:00
|
|
|
case IntegrationMode.integrationTest:
|
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
|
|
|
}
|