| 
									
										
										
										
											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'; | 
					
						
							| 
									
										
										
										
											2024-04-07 21:36:55 +08:00
										 |  |  | import 'package:flutter/foundation.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-27 18:54:31 -08:00
										 |  |  |     final root = await getApplicationSupportDirectory(); | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-07 21:36:55 +08:00
										 |  |  |     debugPrint('application path: ${applicationPath.path}'); | 
					
						
							| 
									
										
										
										
											2023-11-05 14:00:24 +08:00
										 |  |  |     // Pass the environment variables to the Rust SDK
 | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |     final env = _makeAppFlowyConfiguration( | 
					
						
							|  |  |  |       root.path, | 
					
						
							| 
									
										
										
										
											2024-01-30 09:33:34 +08:00
										 |  |  |       context.config.version, | 
					
						
							| 
									
										
										
										
											2023-11-20 20:54:47 +08:00
										 |  |  |       dir.path, | 
					
						
							|  |  |  |       applicationPath.path, | 
					
						
							|  |  |  |       deviceId, | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |       rustEnvs: context.config.rustEnvs, | 
					
						
							| 
									
										
										
										
											2023-11-20 20:54:47 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |     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-27 18:54:31 -08:00
										 |  |  | AppFlowyConfiguration _makeAppFlowyConfiguration( | 
					
						
							|  |  |  |   String root, | 
					
						
							| 
									
										
										
										
											2024-01-30 09:33:34 +08:00
										 |  |  |   String appVersion, | 
					
						
							| 
									
										
										
										
											2023-11-20 20:54:47 +08:00
										 |  |  |   String customAppPath, | 
					
						
							|  |  |  |   String originAppPath, | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |   String deviceId, { | 
					
						
							|  |  |  |   required Map<String, String> rustEnvs, | 
					
						
							|  |  |  | }) { | 
					
						
							| 
									
										
										
										
											2023-11-24 11:54:47 +08:00
										 |  |  |   final env = getIt<AppFlowyCloudSharedEnv>(); | 
					
						
							|  |  |  |   return AppFlowyConfiguration( | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |     root: root, | 
					
						
							| 
									
										
										
										
											2024-01-30 09:33:34 +08:00
										 |  |  |     app_version: appVersion, | 
					
						
							| 
									
										
										
										
											2023-11-24 11:54:47 +08:00
										 |  |  |     custom_app_path: customAppPath, | 
					
						
							|  |  |  |     origin_app_path: originAppPath, | 
					
						
							|  |  |  |     device_id: deviceId, | 
					
						
							| 
									
										
										
										
											2024-04-07 21:36:55 +08:00
										 |  |  |     platform: Platform.operatingSystem, | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |     authenticator_type: env.authenticatorType.value, | 
					
						
							| 
									
										
										
										
											2023-11-24 11:54:47 +08:00
										 |  |  |     supabase_config: env.supabaseConfig, | 
					
						
							|  |  |  |     appflowy_cloud_config: env.appflowyCloudConfig, | 
					
						
							| 
									
										
										
										
											2023-11-27 18:54:31 -08:00
										 |  |  |     envs: rustEnvs, | 
					
						
							| 
									
										
										
										
											2023-11-24 11:54:47 +08:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											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() | 
					
						
							| 
									
										
										
										
											2024-01-29 10:26:45 +08:00
										 |  |  |           .then((directory) => directory.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
										 |  |  | } |