Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions frontend/appflowy_flutter/integration_test/shared/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ extension AppFlowyTestBase on WidgetTester {
final rustEnvs = <String, String>{};
if (cloudType != null) {
switch (cloudType) {
case AuthenticatorType.local:
break;
case AuthenticatorType.appflowyCloudSelfHost:
rustEnvs["GOTRUE_ADMIN_EMAIL"] = "[email protected]";
rustEnvs["GOTRUE_ADMIN_PASSWORD"] = "password";
Expand All @@ -71,9 +69,6 @@ extension AppFlowyTestBase on WidgetTester {
() async {
if (cloudType != null) {
switch (cloudType) {
case AuthenticatorType.local:
await useLocalServer();
break;
case AuthenticatorType.appflowyCloudSelfHost:
await useTestSelfHostedAppFlowyCloud();
getIt.unregister<AuthService>();
Expand Down
46 changes: 23 additions & 23 deletions frontend/appflowy_flutter/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -181,37 +181,37 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/webview_flutter_wkwebview/darwin"

SPEC CHECKSUMS:
app_links: 3da4c36b46cac3bf24eb897f1a6ce80bda109874
appflowy_backend: 78f6a053f756e6bc29bcc5a2106cbe77b756e97a
connectivity_plus: 481668c94744c30c53b8895afb39159d1e619bdf
device_info_plus: 71ffc6ab7634ade6267c7a93088ed7e4f74e5896
app_links: e7a6750a915a9e161c58d91bc610e8cd1d4d0ad0
appflowy_backend: 144c20d8bfb298c4e10fa3fa6701a9f41bf98b88
connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d
device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d
DKImagePickerController: b512c28220a2b8ac7419f21c491fc8534b7601ac
DKPhotoGallery: fdfad5125a9fdda9cc57df834d49df790dbb4179
file_picker: 9b3292d7c8bc68c8a7bf8eb78f730e49c8efc517
flowy_infra_ui: 931b73a18b54a392ab6152eebe29a63a30751f53
file_picker: 09aa5ec1ab24135ccd7a1621c46c84134bfd6655
flowy_infra_ui: 0455e1fa8c51885aa1437848e361e99419f34ebc
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
fluttertoast: 76fea30fcf04176325f6864c87306927bd7d2038
image_picker_ios: 7fe1ff8e34c1790d6fff70a32484959f563a928a
integration_test: 4a889634ef21a45d28d50d622cf412dc6d9f586e
irondash_engine_context: 8e58ca8e0212ee9d1c7dc6a42121849986c88486
keyboard_height_plugin: ef70a8181b29f27670e9e2450814ca6b6dc05b05
open_filex: 432f3cd11432da3e39f47fcc0df2b1603854eff1
package_info_plus: af8e2ca6888548050f16fa2f1938db7b5a5df499
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
permission_handler_apple: 4ed2196e43d0651e8ff7ca3483a069d469701f2d
fluttertoast: e9a18c7be5413da53898f660530c56f35edfba9c
image_picker_ios: c560581cceedb403a6ff17f2f816d7fea1421fc1
integration_test: 252f60fa39af5e17c3aa9899d35d908a0721b573
irondash_engine_context: 3458bf979b90d616ffb8ae03a150bafe2e860cc9
keyboard_height_plugin: 43fa8bba20fd5c4fdeed5076466b8b9d43cc6b86
open_filex: 6e26e659846ec990262224a12ef1c528bb4edbe4
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
saver_gallery: af2d0c762dafda254e0ad025ef0dabd6506cd490
saver_gallery: 76172dc4bf6b40e66d694948ada9ff402304dd87
SDWebImage: b9a731e1d6307f44ca703b3976d18c24ca561e84
Sentry: 1fe34e9c2cbba1e347623610d26db121dcb569f1
sentry_flutter: e24b397f9a61fa5bbefd8279c3b2242ca86faa90
share_plus: 50da8cb520a8f0f65671c6c6a99b3617ed10a58a
shared_preferences_foundation: 9e1978ff2562383bd5676f64ec4e9aa8fa06a6f7
sqflite_darwin: 20b2a3a3b70e43edae938624ce550a3cbf66a3d0
super_native_extensions: b763c02dc3a8fd078389f410bf15149179020cb4
sentry_flutter: a39c2a2d67d5e5b9cb0b94a4985c76dd5b3fc737
share_plus: 8b6f8b3447e494cca5317c8c3073de39b3600d1f
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
super_native_extensions: 4916b3c627a9c7fffdc48a23a9eca0b1ac228fa7
SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780
Toast: 91b396c56ee72a5790816f40d3a94dd357abc196
url_launcher_ios: 694010445543906933d732453a59da0a173ae33d
webview_flutter_wkwebview: 44d4dee7d7056d5ad185d25b38404436d56c547c
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
webview_flutter_wkwebview: 0982481e3d9c78fd5c6f62a002fcd24fc791f1e4

PODFILE CHECKSUM: d0d9b4ff572d8695c38eb3f9b490f55cdfc57eca

Expand Down
2 changes: 2 additions & 0 deletions frontend/appflowy_flutter/lib/env/backend_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppFlowyConfiguration {
required this.platform,
required this.authenticator_type,
required this.appflowy_cloud_config,
required this.is_anon,
required this.envs,
});

Expand All @@ -28,6 +29,7 @@ class AppFlowyConfiguration {
final String origin_app_path;
final String device_id;
final String platform;
final bool is_anon;
final int authenticator_type;
final AppFlowyCloudConfiguration appflowy_cloud_config;
final Map<String, String> envs;
Expand Down
22 changes: 1 addition & 21 deletions frontend/appflowy_flutter/lib/env/cloud_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import 'package:appflowy_backend/log.dart';
///
Future<void> _setAuthenticatorType(AuthenticatorType ty) async {
switch (ty) {
case AuthenticatorType.local:
await getIt<KeyValueStorage>().set(KVKeys.kCloudType, 0.toString());
break;
case AuthenticatorType.appflowyCloud:
await getIt<KeyValueStorage>().set(KVKeys.kCloudType, 2.toString());
break;
Expand Down Expand Up @@ -63,8 +60,6 @@ Future<AuthenticatorType> getAuthenticatorType() async {
}

switch (value ?? "0") {
case "0":
return AuthenticatorType.local;
case "2":
return AuthenticatorType.appflowyCloud;
case "3":
Expand Down Expand Up @@ -100,33 +95,24 @@ bool get isAuthEnabled {
return false;
}

bool get isLocalAuthEnabled {
return currentCloudType().isLocal;
}

/// Determines if AppFlowy Cloud is enabled.
bool get isAppFlowyCloudEnabled {
return currentCloudType().isAppFlowyCloudEnabled;
}

enum AuthenticatorType {
local,
appflowyCloud,
appflowyCloudSelfHost,
// The 'appflowyCloudDevelop' type is used for develop purposes only.
appflowyCloudDevelop;

bool get isLocal => this == AuthenticatorType.local;

bool get isAppFlowyCloudEnabled =>
this == AuthenticatorType.appflowyCloudSelfHost ||
this == AuthenticatorType.appflowyCloudDevelop ||
this == AuthenticatorType.appflowyCloud;

int get value {
switch (this) {
case AuthenticatorType.local:
return 0;
case AuthenticatorType.appflowyCloud:
return 2;
case AuthenticatorType.appflowyCloudSelfHost:
Expand All @@ -138,16 +124,14 @@ enum AuthenticatorType {

static AuthenticatorType fromValue(int value) {
switch (value) {
case 0:
return AuthenticatorType.local;
case 2:
return AuthenticatorType.appflowyCloud;
case 3:
return AuthenticatorType.appflowyCloudSelfHost;
case 4:
return AuthenticatorType.appflowyCloudDevelop;
default:
return AuthenticatorType.local;
return AuthenticatorType.appflowyCloud;
}
}
}
Expand Down Expand Up @@ -180,10 +164,6 @@ Future<void> useAppFlowyBetaCloudWithURL(
await _setAppFlowyCloudUrl(url);
}

Future<void> useLocalServer() async {
await _setAuthenticatorType(AuthenticatorType.local);
}

// Use getIt<AppFlowyCloudSharedEnv>() to get the shared environment.
class AppFlowyCloudSharedEnv {
AppFlowyCloudSharedEnv({
Expand Down
7 changes: 0 additions & 7 deletions frontend/appflowy_flutter/lib/startup/deps_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ void _resolveCommonService(

void _resolveUserDeps(GetIt getIt, IntegrationMode mode) {
switch (currentCloudType()) {
case AuthenticatorType.local:
getIt.registerFactory<AuthService>(
() => BackendAuthService(
AuthenticatorPB.Local,
),
);
break;
case AuthenticatorType.appflowyCloud:
case AuthenticatorType.appflowyCloudSelfHost:
case AuthenticatorType.appflowyCloudDevelop:
Expand Down
5 changes: 4 additions & 1 deletion frontend/appflowy_flutter/lib/startup/startup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ class FlowyRunner {
// init the app window
InitAppWindowTask(),
// Init Rust SDK
InitRustSDKTask(customApplicationPath: applicationDataDirectory),
InitRustSDKTask(
customApplicationPath: applicationDataDirectory,
isAnon: isAnon,
),
// Load Plugins, like document, grid ...
const PluginLoadTask(),
const FileStorageTask(),
Expand Down
27 changes: 23 additions & 4 deletions frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,30 @@ import '../startup.dart';

class InitRustSDKTask extends LaunchTask {
const InitRustSDKTask({
this.customApplicationPath,
required this.isAnon,
required this.customApplicationPath,
});

// Customize the RustSDK initialization path
final Directory? customApplicationPath;
final bool isAnon;

@override
LaunchTaskType get type => LaunchTaskType.dataProcessing;

@override
Future<void> initialize(LaunchContext context) async {
final root = await getApplicationSupportDirectory();
final applicationPath = await appFlowyApplicationDataDirectory();
final dir = customApplicationPath ?? applicationPath;

// Determine application paths in parallel rather than sequentially
final applicationPath = isAnon
? await appFlowyAnonDirectory()
: await appFlowyApplicationDataDirectory();

final dir =
isAnon ? applicationPath : (customApplicationPath ?? applicationPath);

// Get device ID in parallel with path resolution
final deviceId = await getDeviceId();

// Pass the environment variables to the Rust SDK
Expand All @@ -35,6 +45,7 @@ class InitRustSDKTask extends LaunchTask {
dir.path,
applicationPath.path,
deviceId,
isAnon,
rustEnvs: context.config.rustEnvs,
);
await context.getIt<FlowySDK>().init(jsonEncode(env.toJson()));
Expand All @@ -49,7 +60,8 @@ AppFlowyConfiguration _makeAppFlowyConfiguration(
String appVersion,
String customAppPath,
String originAppPath,
String deviceId, {
String deviceId,
bool isAnon, {
required Map<String, String> rustEnvs,
}) {
final env = getIt<AppFlowyCloudSharedEnv>();
Expand All @@ -62,6 +74,7 @@ AppFlowyConfiguration _makeAppFlowyConfiguration(
platform: Platform.operatingSystem,
authenticator_type: env.authenticatorType.value,
appflowy_cloud_config: env.appflowyCloudConfig,
is_anon: isAnon,
envs: rustEnvs,
);
}
Expand All @@ -82,3 +95,9 @@ Future<Directory> appFlowyApplicationDataDirectory() async {
return Directory(path.join(Directory.current.path, '.sandbox'));
}
}

Future<Directory> appFlowyAnonDirectory() async {
final Directory documentsDir =
await getApplicationSupportDirectory().then((directory) => directory);
return Directory(path.join(documentsDir.path, 'anon'));
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ class AppFlowyCloudAuthService implements AuthService {
}

@override
Future<FlowyResult<UserProfilePB, FlowyError>> signUpAsGuest({
Future<void> signUpAsGuest({
Map<String, String> params = const {},
}) async {
return _backendAuthService.signUpAsGuest();
await _backendAuthService.signUpAsGuest();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ class AppFlowyCloudMockAuthService implements AuthService {
}

@override
Future<FlowyResult<UserProfilePB, FlowyError>> signUpAsGuest({
Future<void> signUpAsGuest({
Map<String, String> params = const {},
}) async {
return _appFlowyAuthService.signUpAsGuest();
await _appFlowyAuthService.signUpAsGuest();
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class AuthService {
/// - `params`: Additional parameters for guest registration (optional).
///
/// Returns a default [UserProfilePB].
Future<FlowyResult<UserProfilePB, FlowyError>> signUpAsGuest({
Future<void> signUpAsGuest({
Map<String, String> params,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/auth/auth_service.dart';
import 'package:appflowy/user/application/user_service.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
Expand All @@ -7,9 +8,6 @@ import 'package:appflowy_backend/protobuf/flowy-user/auth.pb.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart'
show SignInPayloadPB, SignUpPayloadPB, UserProfilePB;
import 'package:appflowy_result/appflowy_result.dart';
import 'package:easy_localization/easy_localization.dart';

import '../../../generated/locale_keys.g.dart';
import 'device_id.dart';

class BackendAuthService implements AuthService {
Expand Down Expand Up @@ -60,23 +58,24 @@ class BackendAuthService implements AuthService {
}

@override
Future<FlowyResult<UserProfilePB, FlowyError>> signUpAsGuest({
Future<void> signUpAsGuest({
Map<String, String> params = const {},
}) async {
const password = "Guest!@123456";
final userEmail = "[email protected]";
await runAppFlowy(isAnon: true);
// const password = "Guest!@123456";
// final userEmail = "[email protected]";

final request = SignUpPayloadPB.create()
..name = LocaleKeys.defaultUsername.tr()
..email = userEmail
..password = password
// When sign up as guest, the auth type is always local.
..authType = AuthenticatorPB.Local
..deviceId = await getDeviceId();
final response = await UserEventSignUp(request).send().then(
(value) => value,
);
return response;
// final request = SignUpPayloadPB.create()
// ..name = LocaleKeys.defaultUsername.tr()
// ..email = userEmail
// ..password = password
// // When sign up as guest, the auth type is always local.
// ..authType = AuthenticatorPB.Local
// ..deviceId = await getDeviceId();
// final response = await UserEventSignUp(request).send().then(
// (value) => value,
// );
// return response;
}

@override
Expand Down
11 changes: 1 addition & 10 deletions frontend/appflowy_flutter/lib/user/application/sign_in_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,7 @@ class SignInBloc extends Bloc<SignInEvent, SignInState> {
),
);

final result = await authService.signUpAsGuest();
emit(
result.fold(
(userProfile) => state.copyWith(
isSubmitting: false,
successOrFail: FlowyResult.success(userProfile),
),
(error) => _stateFromCode(error),
),
);
await authService.signUpAsGuest();
}

SignInState _stateFromCode(FlowyError error) {
Expand Down
Loading
Loading