Nathan.fooo 1fad713477
feat: custom server url in application (#3996)
* chore:test

* chore: update ui

* feat: set appflowy cloud url

* chore: add self host docs

* fix: save user

* fix: sign out when authenticator not match

* fix: sign out when authenticator not match

* fix: db lock

* chore: remove unuse env file

* test: disable supabase cloud test

* test: disable supabase cloud test

* chore: fix save
2023-11-24 11:54:47 +08:00

75 lines
2.3 KiB
Dart

import 'dart:convert';
import 'dart:io';
import 'package:appflowy/env/backend_env.dart';
import 'package:appflowy/env/env.dart';
import 'package:appflowy/user/application/auth/device_id.dart';
import 'package:appflowy_backend/appflowy_backend.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;
import '../startup.dart';
class InitRustSDKTask extends LaunchTask {
const InitRustSDKTask({
this.customApplicationPath,
});
// Customize the RustSDK initialization path
final Directory? customApplicationPath;
@override
LaunchTaskType get type => LaunchTaskType.dataProcessing;
@override
Future<void> initialize(LaunchContext context) async {
final applicationPath = await appFlowyApplicationDataDirectory();
final dir = customApplicationPath ?? applicationPath;
final deviceId = await getDeviceId();
// Pass the environment variables to the Rust SDK
final env = _getAppFlowyConfiguration(
dir.path,
applicationPath.path,
deviceId,
);
await context.getIt<FlowySDK>().init(jsonEncode(env.toJson()));
}
@override
Future<void> dispose() async {}
}
AppFlowyConfiguration _getAppFlowyConfiguration(
String customAppPath,
String originAppPath,
String deviceId,
) {
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,
);
}
/// The default directory to store the user data. The directory can be
/// customized by the user via the [ApplicationDataStorage]
Future<Directory> appFlowyApplicationDataDirectory() async {
switch (integrationMode()) {
case IntegrationMode.develop:
final Directory documentsDir = await getApplicationSupportDirectory()
..create();
return Directory(path.join(documentsDir.path, 'data_dev')).create();
case IntegrationMode.release:
final Directory documentsDir = await getApplicationSupportDirectory();
return Directory(path.join(documentsDir.path, 'data')).create();
case IntegrationMode.unitTest:
case IntegrationMode.integrationTest:
return Directory(path.join(Directory.current.path, '.sandbox'));
}
}