Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/common/system_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> openLink(String? url) async {
if (url == null) {
return;
}
Expand All @@ -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);
}
}
}
4 changes: 3 additions & 1 deletion lib/pages/editor/widgets/editors/markdown_editor.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -60,7 +62,7 @@ class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/editor/widgets/editors/rich_text_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _RichTextEditorState extends ConsumerState<RichTextEditor> {
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() {
Expand Down
Loading