Skip to content

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.

fix: only adding http(s) scheme if needed (#4871)

Lucas.Xudd3f8b247a97
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<bool> 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<bool> afLaunchUrl(
return result;
}
-Future<bool> afLaunchUrlString(String url) async {
+Future<bool> afLaunchUrlString(
+ String url, {
+ bool addingHttpSchemeWhenFailed = false,
+}) async {
final Uri uri;
try {
uri = Uri.parse(url);
@@ -53,7 +67,10 @@ Future<bool> 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<EditorState>();
if (editorState.selection == null) {
- afLaunchUrlString(href);
+ afLaunchUrlString(
+ href,
+ addingHttpSchemeWhenFailed: true,
+ );
return;
}