diff --git a/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart b/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart index 91e1beac39..c01d72a7fd 100644 --- a/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart +++ b/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart @@ -15,23 +15,34 @@ Future afLaunchUrl( OnFailureCallback? onFailure, launcher.LaunchMode mode = launcher.LaunchMode.platformDefault, String? webOnlyWindowName, + bool addingHttpSchemeWhenFailed = false, }) async { // try to launch the uri directly bool result; try { - result = await launcher.launchUrl(uri); + result = await launcher.launchUrl( + uri, + mode: mode, + webOnlyWindowName: webOnlyWindowName, + ); } on PlatformException catch (e) { Log.error('Failed to open uri: $e'); } finally { result = false; } - // if the uri is not a valid url, try to launch it with https scheme + // if the uri is not a valid url, try to launch it with http scheme final url = uri.toString(); - if (!result && !isURL(url, {'require_protocol': true})) { + if (addingHttpSchemeWhenFailed && + !result && + !isURL(url, {'require_protocol': true})) { try { - final uriWithScheme = Uri.parse('https://$url'); - result = await launcher.launchUrl(uriWithScheme); + final uriWithScheme = Uri.parse('http://$url'); + result = await launcher.launchUrl( + uriWithScheme, + mode: mode, + webOnlyWindowName: webOnlyWindowName, + ); } on PlatformException catch (e) { Log.error('Failed to open uri: $e'); if (context != null && context.mounted) { @@ -43,7 +54,10 @@ Future afLaunchUrl( return result; } -Future afLaunchUrlString(String url) async { +Future afLaunchUrlString( + String url, { + bool addingHttpSchemeWhenFailed = false, +}) async { final Uri uri; try { uri = Uri.parse(url); @@ -53,7 +67,10 @@ Future afLaunchUrlString(String url) async { } // try to launch the uri directly - return afLaunchUrl(uri); + return afLaunchUrl( + uri, + addingHttpSchemeWhenFailed: addingHttpSchemeWhenFailed, + ); } void _errorHandler( diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart index 9095f1841e..ad851ed839 100644 --- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart +++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart @@ -1,8 +1,5 @@ import 'dart:math'; -import 'package:flutter/gestures.dart'; -import 'package:flutter/material.dart'; - import 'package:appflowy/core/helpers/url_launcher.dart'; import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart'; import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart'; @@ -15,6 +12,8 @@ import 'package:appflowy/workspace/application/settings/appearance/appearance_cu import 'package:appflowy/workspace/application/settings/appearance/base_appearance.dart'; import 'package:appflowy_editor/appflowy_editor.dart' hide Log; import 'package:collection/collection.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:go_router/go_router.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -294,7 +293,10 @@ class EditorStyleCustomizer { ..onTap = () { final editorState = context.read(); if (editorState.selection == null) { - afLaunchUrlString(href); + afLaunchUrlString( + href, + addingHttpSchemeWhenFailed: true, + ); return; }