diff --git a/lib/common/system_utils.dart b/lib/common/system_utils.dart index a5409528..d38afa66 100644 --- a/lib/common/system_utils.dart +++ b/lib/common/system_utils.dart @@ -237,7 +237,9 @@ class SystemUtils { } /// Opens the [url] of a link in a note, if it can be parsed. - void openLink(String? url) { + /// + /// The failures are logged, without the [url] which can contain private information. + Future openLink(String? url) async { if (url == null) { return; } @@ -249,6 +251,13 @@ class SystemUtils { return; } - launchUrl(uri); + try { + if (!await launchUrl(uri)) { + logger.w('The link in a note could not be opened'); + } + } catch (exception, stackTrace) { + // The exception itself is not logged, since it can contain the URL + logger.e('The link in a note could not be opened (${exception.runtimeType})', null, stackTrace); + } } } diff --git a/lib/pages/editor/widgets/editors/markdown_editor.dart b/lib/pages/editor/widgets/editors/markdown_editor.dart index b0b297d9..bc6cd13b 100644 --- a/lib/pages/editor/widgets/editors/markdown_editor.dart +++ b/lib/pages/editor/widgets/editors/markdown_editor.dart @@ -1,3 +1,5 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; @@ -60,7 +62,7 @@ class _MarkdownEditorState extends ConsumerState { widget.onChanged(note); } - void onOpenLink(String text, String? href, String title) => SystemUtils().openLink(href); + void onOpenLink(String text, String? href, String title) => unawaited(SystemUtils().openLink(href)); @override Widget build(BuildContext context) { diff --git a/lib/pages/editor/widgets/editors/rich_text_editor.dart b/lib/pages/editor/widgets/editors/rich_text_editor.dart index d61f32f4..057e4242 100644 --- a/lib/pages/editor/widgets/editors/rich_text_editor.dart +++ b/lib/pages/editor/widgets/editors/rich_text_editor.dart @@ -60,7 +60,7 @@ class _RichTextEditorState extends ConsumerState { changes = widget.fleatherController.document.changes.listen((_) => onChanged()); } - void onLaunchUrl(String? url) => SystemUtils().openLink(url); + void onLaunchUrl(String? url) => unawaited(SystemUtils().openLink(url)); /// Updates whether the undo and redo actions are available. void updateUndoRedo() {