From c4f4bcf4575547bd4bbc9c242687d6907804ff7d Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Sat, 13 Jan 2024 03:08:07 +0800 Subject: [PATCH] feat: using appflowy cloud as the default cloud type (#4380) * feat: using appflowy cloud as the default cloud type * fix: test * Update cloud_env.dart --- .../appflowy_flutter/lib/env/cloud_env.dart | 43 +++++++++++-------- .../widgets/setting_appflowy_cloud.dart | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/frontend/appflowy_flutter/lib/env/cloud_env.dart b/frontend/appflowy_flutter/lib/env/cloud_env.dart index 7d22829f2c..252349c02f 100644 --- a/frontend/appflowy_flutter/lib/env/cloud_env.dart +++ b/frontend/appflowy_flutter/lib/env/cloud_env.dart @@ -20,20 +20,23 @@ import 'package:dartz/dartz.dart'; Future setAuthenticatorType(AuthenticatorType ty) async { switch (ty) { case AuthenticatorType.local: - getIt().set(KVKeys.kCloudType, 0.toString()); + await getIt().set(KVKeys.kCloudType, 0.toString()); break; case AuthenticatorType.supabase: - getIt().set(KVKeys.kCloudType, 1.toString()); + await getIt().set(KVKeys.kCloudType, 1.toString()); break; case AuthenticatorType.appflowyCloud: - getIt().set(KVKeys.kCloudType, 2.toString()); + await getIt().set(KVKeys.kCloudType, 2.toString()); + await setAppFlowyCloudUrl(const Some(kAppflowyCloudUrl)); break; case AuthenticatorType.appflowyCloudSelfHost: - getIt().set(KVKeys.kCloudType, 3.toString()); + await getIt().set(KVKeys.kCloudType, 3.toString()); break; } } +const String kAppflowyCloudUrl = "https://beta.appflowy.cloud"; + /// Retrieves the currently set cloud type. /// /// This method fetches the cloud type setting from the key-value storage @@ -47,20 +50,24 @@ Future setAuthenticatorType(AuthenticatorType ty) async { /// Future getAuthenticatorType() async { final value = await getIt().get(KVKeys.kCloudType); - return value.fold(() => AuthenticatorType.local, (s) { - switch (s) { - case "0": - return AuthenticatorType.local; - case "1": - return AuthenticatorType.supabase; - case "2": - return AuthenticatorType.appflowyCloud; - case "3": - return AuthenticatorType.appflowyCloudSelfHost; - default: - return AuthenticatorType.local; - } - }); + if (value.isNone() && integrationMode().isRelease) { + await setAuthenticatorType(AuthenticatorType.appflowyCloud); + return AuthenticatorType.appflowyCloud; + } + + switch (value.getOrElse(() => "0")) { + case "0": + return AuthenticatorType.local; + case "1": + return AuthenticatorType.supabase; + case "2": + return AuthenticatorType.appflowyCloud; + case "3": + return AuthenticatorType.appflowyCloudSelfHost; + default: + await setAuthenticatorType(AuthenticatorType.appflowyCloud); + return AuthenticatorType.appflowyCloud; + } } /// Determines whether authentication is enabled. diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart index 1e600feb76..52729c0779 100644 --- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart +++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_appflowy_cloud.dart @@ -59,7 +59,7 @@ class AppFlowyCloudViewSetting extends StatelessWidget { title: LocaleKeys.settings_menu_restartAppTip.tr(), confirm: () async { await setAppFlowyCloudUrl( - const Some("https://beta.appflowy.cloud"), + const Some(kAppflowyCloudUrl), ); await setAuthenticatorType(AuthenticatorType.appflowyCloud);