Skip to content

Commit

Permalink
feat: show server url (AppFlowy-IO#3956)
Browse files Browse the repository at this point in the history
* chore: data folder for cloud

* chore: display server url

* chore: fix test
  • Loading branch information
appflowy authored Nov 17, 2023
1 parent 4a1a143 commit 8179419
Show file tree
Hide file tree
Showing 42 changed files with 425 additions and 313 deletions.
31 changes: 13 additions & 18 deletions frontend/appflowy_flutter/dev.env
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Initial Setup
# Copy the 'dev.env' file to '.env':
# Use the command 'cp dev.env .env' to create a copy of 'dev.env' named '.env'.
# After copying, update the '.env' file with the necessary environment parameters.

# 1. Copy the dev.env file to .env:
# cp dev.env .env
# Update the environment parameters as needed.

# 2. Generate the env.dart from this .env file:
# You can use the "Generate Env File" task in VSCode.
# Alternatively, execute the following commands:
# Generate the 'env.dart' from this '.env' file:
# Option 1: Use the "Generate Env File" task in VSCode.
# Option 2: Execute the commands in the appflowy_flutter directory:
# cd appflowy_flutter
# dart run build_runner clean && dart run build_runner build --delete-conflicting-outputs

# Note on Configuration Priority:
# If both Supabase config and AppFlowy cloud config are provided in the '.env' file,
# the AppFlowy cloud config will be prioritized and the Supabase config ignored.
# Ensure only one of these configurations is active at any given time.


# Cloud Type Configuration
# Use this configuration file to specify the cloud type and its associated settings. The available cloud types are:
Expand All @@ -25,17 +28,9 @@ SUPABASE_URL=
SUPABASE_ANON_KEY=

# AppFlowy Cloud Configuration
# If using AppFlowy Cloud (CLOUD_TYPE=2), provide the following details:
# For instance:
# APPFLOWY_CLOUD_BASE_URL=https://xxxxxxxxx
# APPFLOWY_CLOUD_WS_BASE_URL=wss://xxxxxxxxx
# APPFLOWY_CLOUD_GOTRUE_URL=https://xxxxxxxxx
#
# When using localhost for development, you must run AppFlowy Cloud locally
# first. Plese Please follow the instructions below:
# https://github.com/AppFlowy-IO/AppFlowy-Cloud#development
# If using Supabase (CLOUD_TYPE=2), provide the following details:
#
# After running AppFlowy Cloud locally, you can use the following settings:
# When using localhost for development. you can use the following settings:
# APPFLOWY_CLOUD_BASE_URL=http://localhost:8000
# APPFLOWY_CLOUD_WS_BASE_URL=ws://localhost:8000/ws
# APPFLOWY_CLOUD_GOTRUE_URL=http://localhost:9998
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void main() {

// should not see the sync setting page when sign in as annoymous
await tester.openSettings();
await tester.expectNoSettingsPage(SettingsPage.syncSetting);
await tester.expectNoSettingsPage(SettingsPage.cloud);
});

testWidgets('enable encryption', (tester) async {
Expand All @@ -48,7 +48,7 @@ void main() {

// Open the setting page and sign out
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.syncSetting);
await tester.openSettingsPage(SettingsPage.cloud);

// the switch should be off by default
tester.assertEnableEncryptSwitchValue(false);
Expand All @@ -68,7 +68,7 @@ void main() {

// Open the setting page and sign out
await tester.openSettings();
await tester.openSettingsPage(SettingsPage.syncSetting);
await tester.openSettingsPage(SettingsPage.cloud);

// the switch should be on by default
tester.assertEnableSyncSwitchValue(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:appflowy/user/presentation/screens/sign_in_screen/widgets/widgets.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/sync_setting_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/setting_cloud_view.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

Expand Down
19 changes: 5 additions & 14 deletions frontend/appflowy_flutter/lib/core/config/kv.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,22 @@ class DartKeyValue implements KeyValueStorage {

/// Key-value store
/// The data is stored in the local storage of the device.
class RustKeyValue implements KeyValueStorage {
@override
Future<void> set(String key, String value) async {
class RustKeyValue {
static Future<void> set(String key, String value) async {
await ConfigEventSetKeyValue(
KeyValuePB.create()
..key = key
..value = value,
).send();
}

@override
Future<Either<FlowyError, String>> get(String key) async {
static Future<Either<FlowyError, String>> get(String key) async {
final payload = KeyPB.create()..key = key;
final response = await ConfigEventGetKeyValue(payload).send();
return response.swap().map((r) => r.value);
}

@override
Future<Either<FlowyError, T>> getWithFormat<T>(
static Future<Either<FlowyError, T>> getWithFormat<T>(
String key,
T Function(String value) formatter,
) async {
Expand All @@ -99,15 +96,9 @@ class RustKeyValue implements KeyValueStorage {
);
}

@override
Future<void> remove(String key) async {
static Future<void> remove(String key) async {
await ConfigEventRemoveKeyValue(
KeyPB.create()..key = key,
).send();
}

@override
Future<void> clear() async {
// TODO(Lucas): implement clear
}
}
7 changes: 0 additions & 7 deletions frontend/appflowy_flutter/lib/core/config/kv_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ class KVKeys {
/// The key for the path location of the local data for the whole app.
static const String pathLocation = '$prefix.path_location';

/// The key for the last time login type.
///
/// The value is one of the following:
/// - local
/// - supabase
static const String loginType = '$prefix.login_type';

/// The key for saving the window size
///
/// The value is a json string with the following format:
Expand Down
4 changes: 2 additions & 2 deletions frontend/appflowy_flutter/lib/env/backend_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ part 'backend_env.g.dart';

@JsonSerializable()
class AppFlowyEnv {
final int cloud_type;
final SupabaseConfiguration supabase_config;
final AppFlowyCloudConfiguration appflowy_cloud_config;

AppFlowyEnv({
required this.cloud_type,
required this.supabase_config,
required this.appflowy_cloud_config,
});
Expand All @@ -22,12 +24,10 @@ class AppFlowyEnv {
@JsonSerializable()
class SupabaseConfiguration {
/// Indicates whether the sync feature is enabled.
final bool enable_sync;
final String url;
final String anon_key;

SupabaseConfiguration({
this.enable_sync = true,
required this.url,
required this.anon_key,
});
Expand Down
44 changes: 30 additions & 14 deletions frontend/appflowy_flutter/lib/startup/tasks/rust_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,38 @@ class InitRustSDKTask extends LaunchTask {
}

AppFlowyEnv getAppFlowyEnv() {
final supabaseConfig = SupabaseConfiguration(
enable_sync: true,
url: Env.supabaseUrl,
anon_key: Env.supabaseAnonKey,
);
if (isCloudEnabled) {
final supabaseConfig = SupabaseConfiguration(
url: Env.supabaseUrl,
anon_key: Env.supabaseAnonKey,
);

final appflowyCloudConfig = AppFlowyCloudConfiguration(
base_url: Env.afCloudBaseUrl,
ws_base_url: Env.afCloudWSBaseUrl,
gotrue_url: Env.afCloudGoTrueUrl,
);
final appflowyCloudConfig = AppFlowyCloudConfiguration(
base_url: Env.afCloudBaseUrl,
ws_base_url: Env.afCloudWSBaseUrl,
gotrue_url: Env.afCloudGoTrueUrl,
);

return AppFlowyEnv(
supabase_config: supabaseConfig,
appflowy_cloud_config: appflowyCloudConfig,
);
return AppFlowyEnv(
cloud_type: Env.cloudType,
supabase_config: supabaseConfig,
appflowy_cloud_config: appflowyCloudConfig,
);
} else {
// Use the default configuration if the cloud feature is disabled
final supabaseConfig = SupabaseConfiguration(url: '', anon_key: '');
final appflowyCloudConfig = AppFlowyCloudConfiguration(
base_url: '',
ws_base_url: '',
gotrue_url: '',
);

return AppFlowyEnv(
cloud_type: 0,
supabase_config: supabaseConfig,
appflowy_cloud_config: appflowyCloudConfig,
);
}
}

/// The default directory to store the user data. The directory can be
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/historical_user_bloc.dart';
Expand Down Expand Up @@ -41,7 +39,6 @@ class SignInAnonymousButton extends StatelessWidget {
: LocaleKeys.signIn_continueAnonymousUser.tr();
final onTap = state.historicalUsers.isEmpty
? () {
getIt<KeyValueStorage>().set(KVKeys.loginType, 'local');
context
.read<SignInBloc>()
.add(const SignInEvent.signedInAsGuest());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import 'package:appflowy/core/config/kv.dart';
import 'package:appflowy/core/config/kv_keys.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/user/application/sign_in_bloc.dart';
import 'package:appflowy/user/presentation/presentation.dart';
import 'package:appflowy/util/platform_extension.dart';
Expand Down Expand Up @@ -165,19 +162,16 @@ class _ThirdPartySignInButton extends StatelessWidget {
}

void _signInWithGoogle(BuildContext context) {
getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
context.read<SignInBloc>().add(
const SignInEvent.signedInWithOAuth('google'),
);
}

void _signInWithGithub(BuildContext context) {
getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
context.read<SignInBloc>().add(const SignInEvent.signedInWithOAuth('github'));
}

void _signInWithDiscord(BuildContext context) {
getIt<KeyValueStorage>().set(KVKeys.loginType, 'supabase');
context
.read<SignInBloc>()
.add(const SignInEvent.signedInWithOAuth('discord'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import '../../../core/notification/user_notification.dart';
class UserCloudConfigListener {
final String userId;
StreamSubscription<SubscribeObject>? _subscription;
void Function(Either<UserCloudConfigPB, FlowyError>)? _onSettingChanged;
void Function(Either<CloudSettingPB, FlowyError>)? _onSettingChanged;

UserNotificationParser? _userParser;
UserCloudConfigListener({
required this.userId,
});

void start({
void Function(Either<UserCloudConfigPB, FlowyError>)? onSettingChanged,
void Function(Either<CloudSettingPB, FlowyError>)? onSettingChanged,
}) {
_onSettingChanged = onSettingChanged;
_userParser = UserNotificationParser(
Expand All @@ -45,8 +45,8 @@ class UserCloudConfigListener {
switch (ty) {
case UserNotification.DidUpdateCloudConfig:
result.fold(
(payload) => _onSettingChanged
?.call(left(UserCloudConfigPB.fromBuffer(payload))),
(payload) =>
_onSettingChanged?.call(left(CloudSettingPB.fromBuffer(payload))),
(error) => _onSettingChanged?.call(right(error)),
);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CloudSettingBloc extends Bloc<CloudSettingEvent, CloudSettingState> {

CloudSettingBloc({
required String userId,
required UserCloudConfigPB config,
required CloudSettingPB config,
}) : _listener = UserCloudConfigListener(userId: userId),
super(CloudSettingState.initial(config)) {
on<CloudSettingEvent>((event, emit) async {
Expand All @@ -38,7 +38,7 @@ class CloudSettingBloc extends Bloc<CloudSettingEvent, CloudSettingState> {
final update = UpdateCloudConfigPB.create()..enableSync = enable;
updateCloudConfig(update);
},
didReceiveConfig: (UserCloudConfigPB config) {
didReceiveConfig: (CloudSettingPB config) {
emit(
state.copyWith(
config: config,
Expand All @@ -64,7 +64,7 @@ class CloudSettingBloc extends Bloc<CloudSettingEvent, CloudSettingState> {
class CloudSettingEvent with _$CloudSettingEvent {
const factory CloudSettingEvent.initial() = _Initial;
const factory CloudSettingEvent.didReceiveConfig(
UserCloudConfigPB config,
CloudSettingPB config,
) = _DidSyncSupabaseConfig;
const factory CloudSettingEvent.enableSync(bool enable) = _EnableSync;
const factory CloudSettingEvent.enableEncrypt(bool enable) = _EnableEncrypt;
Expand All @@ -73,13 +73,12 @@ class CloudSettingEvent with _$CloudSettingEvent {
@freezed
class CloudSettingState with _$CloudSettingState {
const factory CloudSettingState({
required UserCloudConfigPB config,
required CloudSettingPB config,
required Either<Unit, String> successOrFailure,
required LoadingState loadingState,
}) = _CloudSettingState;

factory CloudSettingState.initial(UserCloudConfigPB config) =>
CloudSettingState(
factory CloudSettingState.initial(CloudSettingPB config) => CloudSettingState(
config: config,
successOrFailure: left(unit),
loadingState: LoadingState.finish(left(unit)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum SettingsPage {
files,
user,
notifications,
syncSetting,
cloud,
shortcuts,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/settings/application_data_storage.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
import 'package:appflowy_backend/log.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
Expand Down Expand Up @@ -32,7 +34,13 @@ class SettingsLocationCubit extends Cubit<SettingsLocationState> {
}

Future<void> _init() async {
final path = await getIt<ApplicationDataStorage>().getPath();
emit(SettingsLocationState.didReceivedPath(path));
// The backend might change the real path that storge the data. So it needs
// to get the path from the backend instead of the KeyValueStorage
await UserEventGetUserSetting().send().then((result) {
result.fold(
(l) => emit(SettingsLocationState.didReceivedPath(l.userFolder)),
(r) => Log.error(r),
);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_notifications_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/sync_setting_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/setting_cloud_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_appearance_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_customize_shortcuts_view.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/settings_file_system_view.dart';
Expand Down Expand Up @@ -104,8 +104,8 @@ class SettingsDialog extends StatelessWidget {
);
case SettingsPage.notifications:
return const SettingsNotificationsView();
case SettingsPage.syncSetting:
return SyncSettingView(userId: user.id.toString());
case SettingsPage.cloud:
return SettingCloudView(userId: user.id.toString());
case SettingsPage.shortcuts:
return const SettingsCustomizeShortcutsWrapper();
default:
Expand Down
Loading

0 comments on commit 8179419

Please sign in to comment.