2023-11-05 06:00:24 +00:00
|
|
|
import 'dart:convert';
|
2021-06-19 15:41:19 +00:00
|
|
|
import 'dart:io';
|
2022-12-20 03:14:42 +00:00
|
|
|
|
2023-11-05 06:00:24 +00:00
|
|
|
import 'package:appflowy/env/backend_env.dart';
|
2023-11-25 09:18:31 +00:00
|
|
|
import 'package:appflowy/env/cloud_env.dart';
|
2023-11-20 12:54:47 +00:00
|
|
|
import 'package:appflowy/user/application/auth/device_id.dart';
|
2023-01-08 04:10:53 +00:00
|
|
|
import 'package:appflowy_backend/appflowy_backend.dart';
|
2024-04-07 13:36:55 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-12-20 03:14:42 +00:00
|
|
|
import 'package:path_provider/path_provider.dart';
|
2023-03-13 17:06:08 +00:00
|
|
|
import 'package:path/path.dart' as path;
|
2022-12-20 03:14:42 +00:00
|
|
|
|
|
|
|
|
import '../startup.dart';
|
2021-06-19 15:41:19 +00:00
|
|
|
|
2021-12-04 14:24:32 +00:00
|
|
|
class InitRustSDKTask extends LaunchTask {
|
2023-05-17 03:03:33 +00:00
|
|
|
const InitRustSDKTask({
|
2023-11-20 12:54:47 +00:00
|
|
|
this.customApplicationPath,
|
2022-12-20 03:14:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Customize the RustSDK initialization path
|
2023-11-20 12:54:47 +00:00
|
|
|
final Directory? customApplicationPath;
|
2022-12-20 03:14:42 +00:00
|
|
|
|
2021-06-19 15:41:19 +00:00
|
|
|
@override
|
|
|
|
|
LaunchTaskType get type => LaunchTaskType.dataProcessing;
|
|
|
|
|
|
|
|
|
|
@override
|
2021-07-12 15:27:58 +00:00
|
|
|
Future<void> initialize(LaunchContext context) async {
|
2023-11-28 02:54:31 +00:00
|
|
|
final root = await getApplicationSupportDirectory();
|
2023-11-20 12:54:47 +00:00
|
|
|
final applicationPath = await appFlowyApplicationDataDirectory();
|
|
|
|
|
final dir = customApplicationPath ?? applicationPath;
|
|
|
|
|
final deviceId = await getDeviceId();
|
2023-05-23 15:55:21 +00:00
|
|
|
|
2024-04-07 13:36:55 +00:00
|
|
|
debugPrint('application path: ${applicationPath.path}');
|
2023-11-05 06:00:24 +00:00
|
|
|
// Pass the environment variables to the Rust SDK
|
2023-11-28 02:54:31 +00:00
|
|
|
final env = _makeAppFlowyConfiguration(
|
|
|
|
|
root.path,
|
2024-01-30 01:33:34 +00:00
|
|
|
context.config.version,
|
2023-11-20 12:54:47 +00:00
|
|
|
dir.path,
|
|
|
|
|
applicationPath.path,
|
|
|
|
|
deviceId,
|
2023-11-28 02:54:31 +00:00
|
|
|
rustEnvs: context.config.rustEnvs,
|
2023-11-20 12:54:47 +00:00
|
|
|
);
|
|
|
|
|
await context.getIt<FlowySDK>().init(jsonEncode(env.toJson()));
|
2022-04-28 12:54:04 +00:00
|
|
|
}
|
2023-10-24 15:13:51 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Future<void> dispose() async {}
|
2022-04-28 12:54:04 +00:00
|
|
|
}
|
|
|
|
|
|
2023-11-28 02:54:31 +00:00
|
|
|
AppFlowyConfiguration _makeAppFlowyConfiguration(
|
|
|
|
|
String root,
|
2024-01-30 01:33:34 +00:00
|
|
|
String appVersion,
|
2023-11-20 12:54:47 +00:00
|
|
|
String customAppPath,
|
|
|
|
|
String originAppPath,
|
2023-11-28 02:54:31 +00:00
|
|
|
String deviceId, {
|
|
|
|
|
required Map<String, String> rustEnvs,
|
|
|
|
|
}) {
|
2023-11-24 03:54:47 +00:00
|
|
|
final env = getIt<AppFlowyCloudSharedEnv>();
|
|
|
|
|
return AppFlowyConfiguration(
|
2023-11-28 02:54:31 +00:00
|
|
|
root: root,
|
2024-01-30 01:33:34 +00:00
|
|
|
app_version: appVersion,
|
2023-11-24 03:54:47 +00:00
|
|
|
custom_app_path: customAppPath,
|
|
|
|
|
origin_app_path: originAppPath,
|
|
|
|
|
device_id: deviceId,
|
2024-04-07 13:36:55 +00:00
|
|
|
platform: Platform.operatingSystem,
|
2023-11-28 02:54:31 +00:00
|
|
|
authenticator_type: env.authenticatorType.value,
|
2023-11-24 03:54:47 +00:00
|
|
|
supabase_config: env.supabaseConfig,
|
|
|
|
|
appflowy_cloud_config: env.appflowyCloudConfig,
|
2023-11-28 02:54:31 +00:00
|
|
|
envs: rustEnvs,
|
2023-11-24 03:54:47 +00:00
|
|
|
);
|
2023-05-23 15:55:21 +00:00
|
|
|
}
|
|
|
|
|
|
2023-06-21 04:15:32 +00: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 07:40:22 +00:00
|
|
|
switch (integrationMode()) {
|
2022-04-28 12:54:04 +00:00
|
|
|
case IntegrationMode.develop:
|
2023-06-07 08:25:37 +00:00
|
|
|
final Directory documentsDir = await getApplicationSupportDirectory()
|
2024-01-29 02:26:45 +00:00
|
|
|
.then((directory) => directory.create());
|
2023-04-04 00:41:16 +00:00
|
|
|
return Directory(path.join(documentsDir.path, 'data_dev')).create();
|
2022-04-28 12:54:04 +00:00
|
|
|
case IntegrationMode.release:
|
2023-06-07 08:25:37 +00:00
|
|
|
final Directory documentsDir = await getApplicationSupportDirectory();
|
2023-04-04 00:41:16 +00:00
|
|
|
return Directory(path.join(documentsDir.path, 'data')).create();
|
2023-07-02 15:37:30 +00:00
|
|
|
case IntegrationMode.unitTest:
|
2023-06-15 14:43:07 +00:00
|
|
|
case IntegrationMode.integrationTest:
|
2023-03-13 17:06:08 +00:00
|
|
|
return Directory(path.join(Directory.current.path, '.sandbox'));
|
2022-02-19 15:19:33 +00:00
|
|
|
}
|
2021-06-19 15:41:19 +00:00
|
|
|
}
|