2023-11-05 14:00:24 +08:00
|
|
|
import 'dart:convert';
|
2021-06-19 23:41:19 +08:00
|
|
|
import 'dart:io';
|
2022-12-20 11:14:42 +08:00
|
|
|
|
2023-11-05 14:00:24 +08:00
|
|
|
import 'package:appflowy/env/backend_env.dart';
|
2023-11-25 01:18:31 -08:00
|
|
|
import 'package:appflowy/env/cloud_env.dart';
|
2023-11-20 20:54:47 +08:00
|
|
|
import 'package:appflowy/user/application/auth/device_id.dart';
|
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';
|
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({
|
2023-11-20 20:54:47 +08:00
|
|
|
this.customApplicationPath,
|
2022-12-20 11:14:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Customize the RustSDK initialization path
|
2023-11-20 20:54:47 +08:00
|
|
|
final Directory? customApplicationPath;
|
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-11-20 20:54:47 +08:00
|
|
|
final applicationPath = await appFlowyApplicationDataDirectory();
|
|
|
|
final dir = customApplicationPath ?? applicationPath;
|
|
|
|
final deviceId = await getDeviceId();
|
2023-05-23 23:55:21 +08:00
|
|
|
|
2023-11-05 14:00:24 +08:00
|
|
|
// Pass the environment variables to the Rust SDK
|
2023-11-20 20:54:47 +08:00
|
|
|
final env = _getAppFlowyConfiguration(
|
|
|
|
dir.path,
|
|
|
|
applicationPath.path,
|
|
|
|
deviceId,
|
|
|
|
);
|
|
|
|
await context.getIt<FlowySDK>().init(jsonEncode(env.toJson()));
|
2022-04-28 20:54:04 +08:00
|
|
|
}
|
2023-10-24 23:13:51 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> dispose() async {}
|
2022-04-28 20:54:04 +08:00
|
|
|
}
|
|
|
|
|
2023-11-20 20:54:47 +08:00
|
|
|
AppFlowyConfiguration _getAppFlowyConfiguration(
|
|
|
|
String customAppPath,
|
|
|
|
String originAppPath,
|
|
|
|
String deviceId,
|
|
|
|
) {
|
2023-11-24 11:54:47 +08:00
|
|
|
final env = getIt<AppFlowyCloudSharedEnv>();
|
|
|
|
return AppFlowyConfiguration(
|
|
|
|
custom_app_path: customAppPath,
|
|
|
|
origin_app_path: originAppPath,
|
|
|
|
device_id: deviceId,
|
|
|
|
cloud_type: env.cloudType.value,
|
|
|
|
supabase_config: env.supabaseConfig,
|
|
|
|
appflowy_cloud_config: env.appflowyCloudConfig,
|
|
|
|
);
|
2023-05-23 23:55:21 +08:00
|
|
|
}
|
|
|
|
|
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 {
|
2023-08-22 15:40:22 +08:00
|
|
|
switch (integrationMode()) {
|
2022-04-28 20:54:04 +08:00
|
|
|
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
|
|
|
}
|