Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: custom share url, publish url and copy link to share (#7061)
Lucas91236006d44c
diff --git a/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/share_menu_test.dart b/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/share_menu_test.dartindex c2dc378386..70bb46279e 100644--- a/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/share_menu_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/cloud/workspace/share_menu_test.dart@@ -54,7 +54,7 @@ void main() {);final shareValues = plainText!- .replaceAll('https://${ShareConstants.shareBaseUrl}/', '')+ .replaceAll('${ShareConstants.defaultBaseWebDomain}/app/', '').split('/');final workspaceId = shareValues[0];expect(workspaceId, isNotEmpty);diff --git a/frontend/appflowy_flutter/integration_test/desktop/settings/sign_in_page_settings_test.dart b/frontend/appflowy_flutter/integration_test/desktop/settings/sign_in_page_settings_test.dartindex 1c952a129d..047e02da36 100644--- a/frontend/appflowy_flutter/integration_test/desktop/settings/sign_in_page_settings_test.dart+++ b/frontend/appflowy_flutter/integration_test/desktop/settings/sign_in_page_settings_test.dart@@ -23,7 +23,7 @@ void main() {.last;}- group('sign-in page settings: ', () {+ group('sign-in page settings:', () {testWidgets('change server type', (tester) async {await tester.initializeAppFlowy();@@ -45,18 +45,25 @@ void main() {// change the server type to self-hostawait tester.tapButton(appflowyCloudType);- final selfhostedButton = findServerType(+ final selfHostedButton = findServerType(AuthenticatorType.appflowyCloudSelfHost,);- await tester.tapButton(selfhostedButton);+ await tester.tapButton(selfHostedButton);// update server url- const serverUrl = 'https://test.appflowy.cloud';+ const serverUrl = 'https://self-hosted.appflowy.cloud';await tester.enterText(find.byKey(kSelfHostedTextInputFieldKey),serverUrl,);await tester.pumpAndSettle();+ // update the web url+ const webUrl = 'https://self-hosted.appflowy.com';+ await tester.enterText(+ find.byKey(kSelfHostedWebTextInputFieldKey),+ webUrl,+ );+ await tester.pumpAndSettle();await tester.tapButton(find.findTextInFlowyText(LocaleKeys.button_save.tr()),);@@ -79,6 +86,11 @@ void main() {find.text(serverUrl),findsOneWidget,);+ // check the web url+ expect(+ find.text(webUrl),+ findsOneWidget,+ );// reset to appflowy cloudawait tester.tapButton(diff --git a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart b/frontend/appflowy_flutter/lib/core/config/kv_keys.dartindex a80d08b76e..b9f59d6434 100644--- a/frontend/appflowy_flutter/lib/core/config/kv_keys.dart+++ b/frontend/appflowy_flutter/lib/core/config/kv_keys.dart@@ -58,6 +58,7 @@ class KVKeys {static const String kCloudType = 'kCloudType';static const String kAppflowyCloudBaseURL = 'kAppFlowyCloudBaseURL';+ static const String kAppFlowyBaseShareDomain = 'kAppFlowyBaseShareDomain';static const String kAppFlowyEnableSyncTrace = 'kAppFlowyEnableSyncTrace';/// The key for saving the text scale factor.diff --git a/frontend/appflowy_flutter/lib/env/backend_env.dart b/frontend/appflowy_flutter/lib/env/backend_env.dartindex a3f45f9f60..eb8a61d037 100644--- a/frontend/appflowy_flutter/lib/env/backend_env.dart+++ b/frontend/appflowy_flutter/lib/env/backend_env.dart@@ -1,6 +1,8 @@// ignore_for_file: non_constant_identifier_names+import 'package:appflowy/plugins/shared/share/constants.dart';import 'package:json_annotation/json_annotation.dart';+part 'backend_env.g.dart';@JsonSerializable()@@ -40,6 +42,7 @@ class AppFlowyCloudConfiguration {required this.ws_base_url,required this.gotrue_url,required this.enable_sync_trace,+ required this.base_web_domain,});factory AppFlowyCloudConfiguration.fromJson(Map<String, dynamic> json) =>@@ -50,6 +53,13 @@ class AppFlowyCloudConfiguration {final String gotrue_url;final bool enable_sync_trace;+ /// The base domain is used in+ ///+ /// - Share URL+ /// - Publish URL+ /// - Copy Link To Block+ final String base_web_domain;+Map<String, dynamic> toJson() => _$AppFlowyCloudConfigurationToJson(this);static AppFlowyCloudConfiguration defaultConfig() {@@ -58,6 +68,7 @@ class AppFlowyCloudConfiguration {ws_base_url: '',gotrue_url: '',enable_sync_trace: false,+ base_web_domain: ShareConstants.defaultBaseWebDomain,);}diff --git a/frontend/appflowy_flutter/lib/env/cloud_env.dart b/frontend/appflowy_flutter/lib/env/cloud_env.dartindex 86b9636a93..12042d066d 100644--- a/frontend/appflowy_flutter/lib/env/cloud_env.dart+++ b/frontend/appflowy_flutter/lib/env/cloud_env.dart@@ -2,6 +2,7 @@ import 'package:appflowy/core/config/kv.dart';import 'package:appflowy/core/config/kv_keys.dart';import 'package:appflowy/env/backend_env.dart';import 'package:appflowy/env/env.dart';+import 'package:appflowy/plugins/shared/share/constants.dart';import 'package:appflowy/startup/startup.dart';import 'package:appflowy_backend/log.dart';@@ -155,6 +156,13 @@ Future<void> _setAppFlowyCloudUrl(String? url) async {await getIt<KeyValueStorage>().set(KVKeys.kAppflowyCloudBaseURL, url ?? '');}+Future<void> useBaseWebDomain(String? url) async {+ await getIt<KeyValueStorage>().set(+ KVKeys.kAppFlowyBaseShareDomain,+ url ?? ShareConstants.baseWebDomain,+ );+}+Future<void> useSelfHostedAppFlowyCloudWithURL(String url) async {await _setAuthenticatorType(AuthenticatorType.appflowyCloudSelfHost);await _setAppFlowyCloudUrl(url);@@ -213,6 +221,7 @@ class AppFlowyCloudSharedEnv {ws_base_url: await _getAppFlowyCloudWSUrl(Env.afCloudUrl),gotrue_url: await _getAppFlowyCloudGotrueUrl(Env.afCloudUrl),enable_sync_trace: false,+ base_web_domain: Env.baseWebDomain,);return AppFlowyCloudSharedEnv(@@ -233,6 +242,7 @@ Future<AppFlowyCloudConfiguration> configurationFromUri(Uri baseUri,String baseUrl,AuthenticatorType authenticatorType,+ String baseShareDomain,) async {// In development mode, the app is configured to access the AppFlowy cloud server directly through specific ports.// This setup bypasses the need for Nginx, meaning that the AppFlowy cloud should be running without an Nginx server@@ -243,6 +253,7 @@ Future<AppFlowyCloudConfiguration> configurationFromUri(ws_base_url: "ws://${baseUri.host}:8000/ws/v1",gotrue_url: "$baseUrl:9999",enable_sync_trace: true,+ base_web_domain: ShareConstants.testBaseWebDomain,);} else {return AppFlowyCloudConfiguration(@@ -250,6 +261,9 @@ Future<AppFlowyCloudConfiguration> configurationFromUri(ws_base_url: await _getAppFlowyCloudWSUrl(baseUrl),gotrue_url: await _getAppFlowyCloudGotrueUrl(baseUrl),enable_sync_trace: await getSyncLogEnabled(),+ base_web_domain: authenticatorType == AuthenticatorType.appflowyCloud+ ? ShareConstants.defaultBaseWebDomain+ : baseShareDomain,);}}@@ -258,10 +272,16 @@ Future<AppFlowyCloudConfiguration> getAppFlowyCloudConfig(AuthenticatorType authenticatorType,) async {final baseURL = await getAppFlowyCloudUrl();+ final baseShareDomain = await getAppFlowyShareDomain();try {final uri = Uri.parse(baseURL);- return await configurationFromUri(uri, baseURL, authenticatorType);+ return await configurationFromUri(+ uri,+ baseURL,+ authenticatorType,+ baseShareDomain,+ );} catch (e) {Log.error("Failed to parse AppFlowy Cloud URL: $e");return AppFlowyCloudConfiguration.defaultConfig();@@ -274,6 +294,12 @@ Future<String> getAppFlowyCloudUrl() async {return result ?? kAppflowyCloudUrl;}+Future<String> getAppFlowyShareDomain() async {+ final result =+ await getIt<KeyValueStorage>().get(KVKeys.kAppFlowyBaseShareDomain);+ return result ?? ShareConstants.defaultBaseWebDomain;+}+Future<bool> getSyncLogEnabled() async {final result =await getIt<KeyValueStorage>().get(KVKeys.kAppFlowyEnableSyncTrace);diff --git a/frontend/appflowy_flutter/lib/env/env.dart b/frontend/appflowy_flutter/lib/env/env.dartindex cfd9837944..182139ed41 100644--- a/frontend/appflowy_flutter/lib/env/env.dart+++ b/frontend/appflowy_flutter/lib/env/env.dart@@ -1,5 +1,6 @@// lib/env/env.dartimport 'package:appflowy/env/cloud_env.dart';+import 'package:appflowy/plugins/shared/share/constants.dart';import 'package:envied/envied.dart';part 'env.g.dart';@@ -43,4 +44,11 @@ abstract class Env {defaultValue: '',)static const String sentryDsn = _Env.sentryDsn;++ @EnviedField(+ obfuscate: false,+ varName: 'BASE_WEB_DOMAIN',+ defaultValue: ShareConstants.baseWebDomain,+ )+ static const String baseWebDomain = _Env.baseWebDomain;}diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host/self_host_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host/self_host_bottom_sheet.dartindex ebc58290b9..dd19c2489d 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host/self_host_bottom_sheet.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host/self_host_bottom_sheet.dart@@ -6,13 +6,20 @@ import 'package:appflowy_backend/log.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flutter/material.dart';+enum SelfHostUrlBottomSheetType {+ shareDomain,+ cloudURL,+}+class SelfHostUrlBottomSheet extends StatefulWidget {const SelfHostUrlBottomSheet({super.key,required this.url,+ required this.type,});final String url;+ final SelfHostUrlBottomSheetType type;@overrideState<SelfHostUrlBottomSheet> createState() => _SelfHostUrlBottomSheetState();@@ -46,8 +53,10 @@ class _SelfHostUrlBottomSheetState extends State<SelfHostUrlBottomSheet> {controller: _textFieldController,keyboardType: TextInputType.text,validator: (value) {- if (value == null || value.isEmpty) {- return LocaleKeys.settings_mobile_usernameEmptyError.tr();+ if (value == null ||+ value.isEmpty ||+ validateUrl(value).isFailure) {+ return LocaleKeys.settings_menu_invalidCloudURLScheme.tr();}return null;},@@ -74,7 +83,12 @@ class _SelfHostUrlBottomSheetState extends State<SelfHostUrlBottomSheet> {if (value.isNotEmpty) {validateUrl(value).fold((url) async {- await useSelfHostedAppFlowyCloudWithURL(url);+ switch (widget.type) {+ case SelfHostUrlBottomSheetType.shareDomain:+ await useBaseWebDomain(url);+ case SelfHostUrlBottomSheetType.cloudURL:+ await useSelfHostedAppFlowyCloudWithURL(url);+ }await runAppFlowy();},(err) => Log.error(err),diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host_setting_group.dart b/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host_setting_group.dartindex 095214d6ef..da2e0c773e 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host_setting_group.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/setting/self_host_setting_group.dart@@ -3,6 +3,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';import 'package:appflowy/mobile/presentation/setting/self_host/self_host_bottom_sheet.dart';import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra_ui/style_widget/text.dart';import 'package:flutter/material.dart';import 'setting.dart';@@ -17,44 +18,106 @@ class SelfHostSettingGroup extends StatefulWidget {}class _SelfHostSettingGroupState extends State<SelfHostSettingGroup> {- final future = getAppFlowyCloudUrl();+ final future = Future.wait([+ getAppFlowyCloudUrl(),+ getAppFlowyShareDomain(),+ ]);@overrideWidget build(BuildContext context) {return FutureBuilder(future: future,builder: (context, snapshot) {- if (!snapshot.hasData) {+ final data = snapshot.data;+ if (!snapshot.hasData || data == null || data.length != 2) {return const SizedBox.shrink();}- final url = snapshot.data ?? '';+ final url = data[0];+ final shareDomain = data[1];return MobileSettingGroup(- groupTitle: LocaleKeys.settings_menu_cloudAppFlowySelfHost.tr(),+ groupTitle: LocaleKeys.settings_menu_cloudAppFlowy.tr(),settingItemList: [- MobileSettingItem(- name: url,- onTap: () {- showMobileBottomSheet(- context,- showHeader: true,- title: LocaleKeys.editor_urlHint.tr(),- showCloseButton: true,- showDivider: false,- padding: const EdgeInsets.symmetric(- horizontal: 16.0,- vertical: 8.0,- ),- builder: (_) {- return SelfHostUrlBottomSheet(- url: url,- );- },- );- },- ),+ _buildSelfHostField(url),+ _buildShareDomainField(shareDomain),],);},);}++ Widget _buildSelfHostField(String url) {+ return MobileSettingItem(+ title: Padding(+ padding: const EdgeInsets.only(bottom: 4.0),+ child: FlowyText(+ LocaleKeys.settings_menu_cloudURL.tr(),+ fontSize: 12.0,+ color: Theme.of(context).hintColor,+ ),+ ),+ subtitle: FlowyText(+ url,+ ),+ trailing: const Icon(+ Icons.chevron_right,+ ),+ onTap: () {+ showMobileBottomSheet(+ context,+ showHeader: true,+ title: LocaleKeys.editor_urlHint.tr(),+ showCloseButton: true,+ showDivider: false,+ padding: const EdgeInsets.symmetric(+ horizontal: 16.0,+ vertical: 8.0,+ ),+ builder: (_) {+ return SelfHostUrlBottomSheet(+ url: url,+ type: SelfHostUrlBottomSheetType.cloudURL,+ );+ },+ );+ },+ );+ }++ Widget _buildShareDomainField(String shareDomain) {+ return MobileSettingItem(+ title: Padding(+ padding: const EdgeInsets.only(bottom: 4.0),+ child: FlowyText(+ LocaleKeys.settings_menu_webURL.tr(),+ fontSize: 12.0,+ color: Theme.of(context).hintColor,+ ),+ ),+ subtitle: FlowyText(+ shareDomain,+ ),+ trailing: const Icon(+ Icons.chevron_right,+ ),+ onTap: () {+ showMobileBottomSheet(+ context,+ showHeader: true,+ title: LocaleKeys.editor_urlHint.tr(),+ showCloseButton: true,+ showDivider: false,+ padding: const EdgeInsets.symmetric(+ horizontal: 16.0,+ vertical: 8.0,+ ),+ builder: (_) {+ return SelfHostUrlBottomSheet(+ url: shareDomain,+ type: SelfHostUrlBottomSheetType.shareDomain,+ );+ },+ );+ },+ );+ }}diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/setting/widgets/mobile_setting_item_widget.dart b/frontend/appflowy_flutter/lib/mobile/presentation/setting/widgets/mobile_setting_item_widget.dartindex 6dc45c1c40..82c86065ae 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/setting/widgets/mobile_setting_item_widget.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/setting/widgets/mobile_setting_item_widget.dart@@ -4,41 +4,29 @@ import 'package:flutter/material.dart';class MobileSettingItem extends StatelessWidget {const MobileSettingItem({super.key,- required this.name,+ this.name,this.padding = const EdgeInsets.only(bottom: 4),this.trailing,this.leadingIcon,+ this.title,this.subtitle,this.onTap,});- final String name;+ final String? name;final EdgeInsets padding;final Widget? trailing;final Widget? leadingIcon;final Widget? subtitle;final VoidCallback? onTap;+ final Widget? title;@overrideWidget build(BuildContext context) {return Padding(padding: padding,child: ListTile(- title: Row(- children: [- if (leadingIcon != null) ...[- leadingIcon!,- const HSpace(8),- ],- Expanded(- child: FlowyText.medium(- name,- fontSize: 14.0,- overflow: TextOverflow.ellipsis,- ),- ),- ],- ),+ title: title ?? _buildDefaultTitle(name),subtitle: subtitle,trailing: trailing,onTap: onTap,@@ -47,4 +35,22 @@ class MobileSettingItem extends StatelessWidget {),);}++ Widget _buildDefaultTitle(String? name) {+ return Row(+ children: [+ if (leadingIcon != null) ...[+ leadingIcon!,+ const HSpace(8),+ ],+ Expanded(+ child: FlowyText.medium(+ name ?? '',+ fontSize: 14.0,+ overflow: TextOverflow.ellipsis,+ ),+ ),+ ],+ );+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/shared/share/constants.dart b/frontend/appflowy_flutter/lib/plugins/shared/share/constants.dartindex 2be63c5879..4027f41474 100644--- a/frontend/appflowy_flutter/lib/plugins/shared/share/constants.dart+++ b/frontend/appflowy_flutter/lib/plugins/shared/share/constants.dart@@ -1,20 +1,32 @@+import 'package:appflowy/env/cloud_env.dart';+import 'package:appflowy/startup/startup.dart';+class ShareConstants {- static const String publishBaseUrl = 'appflowy.com';- static const String shareBaseUrl = 'appflowy.com/app';+ static const String baseWebDomain = 'appflowy.com';+ static const String testBaseWebDomain = 'test.appflowy.com';+ static const String defaultBaseWebDomain = 'https://www.appflowy.com';static String buildPublishUrl({required String nameSpace,required String publishName,}) {- return 'https://$publishBaseUrl/$nameSpace/$publishName';+ final baseShareDomain =+ getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_web_domain;+ final url = '$baseShareDomain/$nameSpace/$publishName'.addSchemaIfNeeded();+ return url;}static String buildNamespaceUrl({required String nameSpace,bool withHttps = false,}) {- final url = withHttps ? 'https://$publishBaseUrl' : publishBaseUrl;- return '$url/$nameSpace';+ final baseShareDomain =+ getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_web_domain;+ String url = baseShareDomain.addSchemaIfNeeded();+ if (!withHttps) {+ url = url.replaceFirst('https://', '');+ }+ return '$url/app/$nameSpace';}static String buildShareUrl({@@ -22,10 +34,23 @@ class ShareConstants {required String viewId,String? blockId,}) {- final url = 'https://$shareBaseUrl/$workspaceId/$viewId';+ final baseShareDomain =+ getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_web_domain;+ final url = '$baseShareDomain/app/$workspaceId/$viewId'.addSchemaIfNeeded();if (blockId == null || blockId.isEmpty) {return url;}return '$url?blockId=$blockId';}}++extension on String {+ String addSchemaIfNeeded() {+ final schema = Uri.parse(this).scheme;+ // if the schema is empty, add https schema by default+ if (schema.isEmpty) {+ return 'https://$this';+ }+ return this;+ }+}diff --git a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dartindex 4b07db8c78..3edefb9855 100644--- a/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart+++ b/frontend/appflowy_flutter/lib/shared/patterns/common_patterns.dart@@ -37,7 +37,7 @@ const _macOSVolumesPattern = '^/Volumes/[^/]+';final macOSVolumesRegex = RegExp(_macOSVolumesPattern);const appflowySharePageLinkPattern =- r'^https://appflowy\.com/app/([^/]+)/([^?]+)(?:\?blockId=(.+))?$';+ r'^https://www\.appflowy\.com/app/([^/]+)/([^?]+)(?:\?blockId=(.+))?$';final appflowySharePageLinkRegex = RegExp(appflowySharePageLinkPattern);const _numberedListPattern = r'^(\d+)\.';diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/appflowy_cloud_urls_bloc.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/appflowy_cloud_urls_bloc.dartindex 998e6d632f..5652904180 100644--- a/frontend/appflowy_flutter/lib/workspace/application/settings/appflowy_cloud_urls_bloc.dart+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/appflowy_cloud_urls_bloc.dart@@ -24,6 +24,15 @@ class AppFlowyCloudURLsBloc),);},+ updateBaseWebDomain: (url) {+ emit(+ state.copyWith(+ updatedBaseWebDomain: url,+ urlError: null,+ showRestartHint: url.isNotEmpty,+ ),+ );+ },confirmUpdate: () async {if (state.updatedServerUrl.isEmpty) {emit(@@ -35,13 +44,27 @@ class AppFlowyCloudURLsBloc),);} else {- validateUrl(state.updatedServerUrl).fold(+ bool isSuccess = false;++ await validateUrl(state.updatedServerUrl).fold((url) async {await useSelfHostedAppFlowyCloudWithURL(url);- add(const AppFlowyCloudURLsEvent.didSaveConfig());+ isSuccess = true;+ },+ (err) async => emit(state.copyWith(urlError: err)),+ );++ await validateUrl(state.updatedBaseWebDomain).fold(+ (url) async {+ await useBaseWebDomain(url);+ isSuccess = true;},- (err) => emit(state.copyWith(urlError: err)),+ (err) async => emit(state.copyWith(urlError: err)),);++ if (isSuccess) {+ add(const AppFlowyCloudURLsEvent.didSaveConfig());+ }}},didSaveConfig: () {@@ -62,6 +85,8 @@ class AppFlowyCloudURLsEvent with _$AppFlowyCloudURLsEvent {const factory AppFlowyCloudURLsEvent.initial() = _Initial;const factory AppFlowyCloudURLsEvent.updateServerUrl(String text) =_ServerUrl;+ const factory AppFlowyCloudURLsEvent.updateBaseWebDomain(String text) =+ _UpdateBaseWebDomain;const factory AppFlowyCloudURLsEvent.confirmUpdate() = _UpdateConfig;const factory AppFlowyCloudURLsEvent.didSaveConfig() = _DidSaveConfig;}@@ -71,6 +96,7 @@ class AppFlowyCloudURLsState with _$AppFlowyCloudURLsState {const factory AppFlowyCloudURLsState({required AppFlowyCloudConfiguration config,required String updatedServerUrl,+ required String updatedBaseWebDomain,required String? urlError,required bool restartApp,required bool showRestartHint,@@ -81,6 +107,8 @@ class AppFlowyCloudURLsState with _$AppFlowyCloudURLsState {urlError: null,updatedServerUrl:getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_url,+ updatedBaseWebDomain:+ getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_web_domain,showRestartHint: getIt<AppFlowyCloudSharedEnv>().appflowyCloudConfig.base_urldiff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dartindex 24e1e52deb..760f358ee2 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/settings_dialog.dart@@ -1,5 +1,6 @@import 'package:appflowy/env/cloud_env.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/plugins/shared/share/constants.dart';import 'package:appflowy/shared/appflowy_cache_manager.dart';import 'package:appflowy/startup/startup.dart';import 'package:appflowy/util/share_log_files.dart';@@ -35,6 +36,9 @@ import 'widgets/setting_cloud.dart';@visibleForTestingconst kSelfHostedTextInputFieldKey =ValueKey('self_hosted_url_input_text_field');+@visibleForTesting+const kSelfHostedWebTextInputFieldKey =+ ValueKey('self_hosted_web_url_input_text_field');class SettingsDialog extends StatelessWidget {SettingsDialog(@@ -245,26 +249,22 @@ class _SelfHostSettings extends StatefulWidget {}class _SelfHostSettingsState extends State<_SelfHostSettings> {- final textController = TextEditingController();+ final cloudUrlTextController = TextEditingController();+ final webUrlTextController = TextEditingController();+AuthenticatorType type = AuthenticatorType.appflowyCloud;@overridevoid initState() {super.initState();- getAppFlowyCloudUrl().then((url) {- textController.text = url;- if (kAppflowyCloudUrl != url) {- setState(() {- type = AuthenticatorType.appflowyCloudSelfHost;- });- }- });+ _fetchUrls();}@overridevoid dispose() {- textController.dispose();+ cloudUrlTextController.dispose();+ webUrlTextController.dispose();super.dispose();}@@ -285,43 +285,54 @@ class _SelfHostSettingsState extends State<_SelfHostSettings> {}Widget _buildInputField() {- return Row(+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,children: [- Expanded(- child: SizedBox(- height: 36,- child: FlowyTextField(- key: kSelfHostedTextInputFieldKey,- controller: textController,- autoFocus: false,- textStyle: const TextStyle(- fontSize: 14,- fontWeight: FontWeight.w400,- ),- hintText: kAppflowyCloudUrl,- onEditingComplete: () => _saveUrl(- url: textController.text,- type: AuthenticatorType.appflowyCloudSelfHost,- ),- ),+ _SelfHostUrlField(+ textFieldKey: kSelfHostedTextInputFieldKey,+ textController: cloudUrlTextController,+ title: LocaleKeys.settings_menu_cloudURL.tr(),+ hintText: LocaleKeys.settings_menu_cloudURLHint.tr(),+ onSave: (url) => _saveUrl(+ cloudUrl: url,+ webUrl: webUrlTextController.text,+ type: AuthenticatorType.appflowyCloudSelfHost,),),- const HSpace(12.0),- Container(- height: 36,- constraints: const BoxConstraints(minWidth: 78),- child: OutlinedRoundedButton(- text: LocaleKeys.button_save.tr(),- onTap: () => _saveUrl(- url: textController.text,- type: AuthenticatorType.appflowyCloudSelfHost,- ),+ const VSpace(12.0),+ _SelfHostUrlField(+ textFieldKey: kSelfHostedWebTextInputFieldKey,+ textController: webUrlTextController,+ title: LocaleKeys.settings_menu_webURL.tr(),+ hintText: LocaleKeys.settings_menu_webURLHint.tr(),+ onSave: (url) => _saveUrl(+ cloudUrl: cloudUrlTextController.text,+ webUrl: url,+ type: AuthenticatorType.appflowyCloudSelfHost,),),+ const VSpace(12.0),+ _buildSaveButton(),],);}+ Widget _buildSaveButton() {+ return Container(+ height: 36,+ constraints: const BoxConstraints(minWidth: 78),+ child: OutlinedRoundedButton(+ text: LocaleKeys.button_save.tr(),+ onTap: () => _saveUrl(+ cloudUrl: cloudUrlTextController.text,+ webUrl: webUrlTextController.text,+ type: AuthenticatorType.appflowyCloudSelfHost,+ ),+ ),+ );+ }+void _onSelected(AuthenticatorType type) {if (type == this.type) {return;@@ -334,19 +345,22 @@ class _SelfHostSettingsState extends State<_SelfHostSettings> {});if (type == AuthenticatorType.appflowyCloud) {- textController.text = kAppflowyCloudUrl;+ cloudUrlTextController.text = kAppflowyCloudUrl;+ webUrlTextController.text = ShareConstants.defaultBaseWebDomain;_saveUrl(- url: textController.text,+ cloudUrl: kAppflowyCloudUrl,+ webUrl: ShareConstants.defaultBaseWebDomain,type: type,);}}- void _saveUrl({- required String url,+ Future<void> _saveUrl({+ required String cloudUrl,+ required String webUrl,required AuthenticatorType type,- }) {- if (url.isEmpty) {+ }) async {+ if (cloudUrl.isEmpty || webUrl.isEmpty) {showToastNotification(context,message: LocaleKeys.settings_menu_pleaseInputValidURL.tr(),@@ -355,27 +369,62 @@ class _SelfHostSettingsState extends State<_SelfHostSettings> {return;}- validateUrl(url).fold(- (url) async {+ final isValid = await _validateUrl(cloudUrl) && await _validateUrl(webUrl);++ if (mounted) {+ if (isValid) {showToastNotification(context,- message: LocaleKeys.settings_menu_changeUrl.tr(args: [url]),+ message: LocaleKeys.settings_menu_changeUrl.tr(args: [cloudUrl]),);Navigator.of(context).pop();- await useAppFlowyBetaCloudWithURL(url, type);++ await useBaseWebDomain(webUrl);+ await useAppFlowyBetaCloudWithURL(cloudUrl, type);+await runAppFlowy();- },- (err) {+ } else {showToastNotification(context,message: LocaleKeys.settings_menu_pleaseInputValidURL.tr(),type: ToastificationType.error,);+ }+ }+ }++ Future<bool> _validateUrl(String url) async {+ return await validateUrl(url).fold(+ (url) async {+ return true;+ },+ (err) {Log.error(err);+ return false;},);}++ Future<void> _fetchUrls() async {+ await Future.wait([+ getAppFlowyCloudUrl(),+ getAppFlowyShareDomain(),+ ]).then((values) {+ if (values.length != 2) {+ return;+ }++ cloudUrlTextController.text = values[0];+ webUrlTextController.text = values[1];++ if (kAppflowyCloudUrl != values[0]) {+ setState(() {+ type = AuthenticatorType.appflowyCloudSelfHost;+ });+ }+ });+ }}@visibleForTesting@@ -487,3 +536,45 @@ class _SupportSettings extends StatelessWidget {);}}++class _SelfHostUrlField extends StatelessWidget {+ const _SelfHostUrlField({+ required this.textController,+ required this.title,+ required this.hintText,+ required this.onSave,+ this.textFieldKey,+ });++ final TextEditingController textController;+ final String title;+ final String hintText;+ final ValueChanged<String> onSave;+ final Key? textFieldKey;++ @override+ Widget build(BuildContext context) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ FlowyText(title),+ const VSpace(6.0),+ SizedBox(+ height: 36,+ child: FlowyTextField(+ key: textFieldKey,+ controller: textController,+ autoFocus: false,+ textStyle: const TextStyle(+ fontSize: 14,+ fontWeight: FontWeight.w400,+ ),+ hintText: hintText,+ onEditingComplete: () => onSave(textController.text),+ ),+ ),+ ],+ );+ }+}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.dartindex d99a6cbf01..81d38dfe40 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@@ -1,11 +1,8 @@-import 'package:flutter/foundation.dart';-import 'package:flutter/gestures.dart';-import 'package:flutter/material.dart';-import 'package:appflowy/core/helpers/url_launcher.dart';import 'package:appflowy/env/cloud_env.dart';import 'package:appflowy/env/env.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/plugins/shared/share/constants.dart';import 'package:appflowy/workspace/application/settings/appflowy_cloud_setting_bloc.dart';import 'package:appflowy/workspace/application/settings/appflowy_cloud_urls_bloc.dart';import 'package:appflowy/workspace/presentation/settings/widgets/_restart_app_button.dart';@@ -22,6 +19,9 @@ import 'package:flowy_infra/size.dart';import 'package:flowy_infra/theme_extension.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flowy_infra_ui/widget/error_page.dart';+import 'package:flutter/foundation.dart';+import 'package:flutter/gestures.dart';+import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';class AppFlowyCloudViewSetting extends StatelessWidget {@@ -67,7 +67,9 @@ class AppFlowyCloudViewSetting extends StatelessWidget {builder: (context, state) {return Column(children: [+ const VSpace(8),const AppFlowyCloudEnableSync(),+ const VSpace(6),const AppFlowyCloudSyncLogEnabled(),const VSpace(12),RestartButton(@@ -75,6 +77,9 @@ class AppFlowyCloudViewSetting extends StatelessWidget {NavigatorAlertDialog(title: LocaleKeys.settings_menu_restartAppTip.tr(),confirm: () async {+ await useBaseWebDomain(+ ShareConstants.defaultBaseWebDomain,+ );await useAppFlowyBetaCloudWithURL(serverURL,authenticatorType,@@ -174,7 +179,7 @@ class AppFlowyCloudURLs extends StatelessWidget {builder: (context, state) {return Column(children: [- const AppFlowySelfhostTip(),+ const AppFlowySelfHostTip(),CloudURLInput(title: LocaleKeys.settings_menu_cloudURL.tr(),url: state.config.base_url,@@ -188,6 +193,19 @@ class AppFlowyCloudURLs extends StatelessWidget {},),const VSpace(8),+ CloudURLInput(+ title: LocaleKeys.settings_menu_webURL.tr(),+ url: state.config.base_web_domain,+ hint: LocaleKeys.settings_menu_webURLHint.tr(),+ onChanged: (text) {+ context.read<AppFlowyCloudURLsBloc>().add(+ AppFlowyCloudURLsEvent.updateBaseWebDomain(+ text,+ ),+ );+ },+ ),+ const VSpace(8),RestartButton(onClick: () {NavigatorAlertDialog(@@ -210,8 +228,8 @@ class AppFlowyCloudURLs extends StatelessWidget {}}-class AppFlowySelfhostTip extends StatelessWidget {- const AppFlowySelfhostTip({super.key});+class AppFlowySelfHostTip extends StatelessWidget {+ const AppFlowySelfHostTip({super.key});final url ="https://docs.appflowy.io/docs/guides/appflowy/self-hosting-appflowy#build-appflowy-with-a-self-hosted-server";diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_cloud.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_cloud.dartindex d937b47736..692be99baa 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_cloud.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/widgets/setting_cloud.dart@@ -1,5 +1,3 @@-import 'package:flutter/material.dart';-import 'package:appflowy/env/cloud_env.dart';import 'package:appflowy/env/env.dart';import 'package:appflowy/generated/flowy_svgs.g.dart';@@ -16,6 +14,7 @@ import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';import 'package:collection/collection.dart';import 'package:easy_localization/easy_localization.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';+import 'package:flutter/material.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:go_router/go_router.dart';import 'package:universal_platform/universal_platform.dart';@@ -47,23 +46,7 @@ class SettingCloud extends StatelessWidget {autoSeparate: false,children: [if (Env.enableCustomCloud)- Row(- children: [- Expanded(- child: FlowyText.medium(- LocaleKeys.settings_menu_cloudServerType.tr(),- ),- ),- Flexible(- child: CloudTypeSwitcher(- cloudType: state.cloudType,- onSelected: (type) => context- .read<CloudSettingBloc>()- .add(CloudSettingEvent.updateCloudType(type)),- ),- ),- ],- ),+ _CloudServerSwitcher(cloudType: state.cloudType),_viewFromCloudType(state.cloudType),],);@@ -137,7 +120,9 @@ class CloudTypeSwitcher extends StatelessWidget {.toList(),): FlowyButton(- text: FlowyText(titleFromCloudType(cloudType)),+ text: FlowyText(+ titleFromCloudType(cloudType),+ ),useIntrinsicWidth: true,rightIcon: const Icon(Icons.chevron_right,@@ -172,12 +157,12 @@ class CloudTypeItem extends StatelessWidget {const CloudTypeItem({super.key,required this.cloudType,- required this.currentCloudtype,+ required this.currentCloudType,required this.onSelected,});final AuthenticatorType cloudType;- final AuthenticatorType currentCloudtype;+ final AuthenticatorType currentCloudType;final Function(AuthenticatorType) onSelected;@override@@ -188,11 +173,11 @@ class CloudTypeItem extends StatelessWidget {text: FlowyText.medium(titleFromCloudType(cloudType),),- rightIcon: currentCloudtype == cloudType+ rightIcon: currentCloudType == cloudType? const FlowySvg(FlowySvgs.check_s): null,onTap: () {- if (currentCloudtype != cloudType) {+ if (currentCloudType != cloudType) {NavigatorAlertDialog(title: LocaleKeys.settings_menu_changeServerTip.tr(),confirm: () async {@@ -208,6 +193,50 @@ class CloudTypeItem extends StatelessWidget {}}+class _CloudServerSwitcher extends StatelessWidget {+ const _CloudServerSwitcher({+ required this.cloudType,+ });++ final AuthenticatorType cloudType;++ @override+ Widget build(BuildContext context) {+ return UniversalPlatform.isDesktopOrWeb+ ? Row(+ children: [+ Expanded(+ child: FlowyText.medium(+ LocaleKeys.settings_menu_cloudServerType.tr(),+ ),+ ),+ Flexible(+ child: CloudTypeSwitcher(+ cloudType: cloudType,+ onSelected: (type) => context+ .read<CloudSettingBloc>()+ .add(CloudSettingEvent.updateCloudType(type)),+ ),+ ),+ ],+ )+ : Row(+ mainAxisAlignment: MainAxisAlignment.spaceBetween,+ children: [+ FlowyText.medium(+ LocaleKeys.settings_menu_cloudServerType.tr(),+ ),+ CloudTypeSwitcher(+ cloudType: cloudType,+ onSelected: (type) => context+ .read<CloudSettingBloc>()+ .add(CloudSettingEvent.updateCloudType(type)),+ ),+ ],+ );+ }+}+String titleFromCloudType(AuthenticatorType cloudType) {switch (cloudType) {case AuthenticatorType.local:diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex d717a1f8b7..8df6426078 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -1062,6 +1062,7 @@"enableSyncLogWarning": "Thank you for helping diagnose sync issues. This will log your document edits to a local file. Please quit and reopen the app after enabling","enableEncrypt": "Encrypt data","cloudURL": "Base URL",+ "webURL": "Web URL","invalidCloudURLScheme": "Invalid Scheme","cloudServerType": "Cloud server","cloudServerTypeTip": "Please note that it might log out your current account after switching the cloud server",@@ -1076,6 +1077,7 @@"pleaseInputValidURL": "Please input a valid URL","changeUrl": "Change self-hosted url to {}","cloudURLHint": "Input the base URL of your server",+ "webURLHint": "Input the base URL of your web server","cloudWSURL": "Websocket URL","cloudWSURLHint": "Input the websocket address of your server","restartApp": "Restart",