Skip to content

Commit 13cf941

Browse files
authored
Handle mailto links properly (#1983)
* handle mailto links propertly * improve mailto link handling by using case-insensitive comparison for URL scheme
1 parent d533551 commit 13cf941

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

backend/FwLite/FwLiteMaui/MainPage.xaml.Android.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#if ANDROID
22

3+
using Android.Content;
34
using AndroidX.Activity;
45
using FwLiteMaui.Platforms.Android;
56
using Microsoft.AspNetCore.Components.WebView;
@@ -34,6 +35,17 @@ private partial void BlazorWebViewInitialized(object? sender, BlazorWebViewIniti
3435
e.WebView.Settings.SetGeolocationDatabasePath(e.WebView.Context?.FilesDir?.Path);
3536
e.WebView.SetWebChromeClient(new PermissionManagingBlazorWebChromeClient(e.WebView.WebChromeClient!, activity));
3637
}
38+
39+
private partial void BlazorWebViewOnUrlLoading(object? sender, UrlLoadingEventArgs e)
40+
{
41+
if ("mailto".Equals(e.Url?.Scheme, StringComparison.OrdinalIgnoreCase))
42+
{
43+
var intent = new Intent(action: Intent.ActionSendto, Android.Net.Uri.Parse(e.Url.ToString()));
44+
intent.AddFlags(ActivityFlags.NewTask);
45+
Platform.AppContext.StartActivity(intent);
46+
e.UrlLoadingStrategy = UrlLoadingStrategy.CancelLoad;
47+
}
48+
}
3749
}
3850

3951
#endif

backend/FwLite/FwLiteMaui/MainPage.xaml.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ public MainPage()
1212
InitializeComponent();
1313
blazorWebView.BlazorWebViewInitializing += BlazorWebViewInitializing;
1414
blazorWebView.BlazorWebViewInitialized += BlazorWebViewInitialized;
15+
blazorWebView.UrlLoading += BlazorWebViewOnUrlLoading;
1516
}
1617

18+
19+
1720
internal string StartPath
1821
{
1922
get => blazorWebView.StartPath;
@@ -32,4 +35,14 @@ private void BlazorWebViewInitialized(object? sender, BlazorWebViewInitializedEv
3235
{
3336
}
3437
#endif
38+
39+
#if ANDROID
40+
private partial void BlazorWebViewOnUrlLoading(object? sender, UrlLoadingEventArgs e);
41+
#else
42+
43+
private void BlazorWebViewOnUrlLoading(object? sender, UrlLoadingEventArgs e)
44+
{
45+
}
46+
47+
#endif
3548
}

frontend/viewer/src/lib/about/FeedbackDialog.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
</div>
3636
</div>
3737
</Button>
38-
<Button variant="ghost" href={mailtoUrl} class="gap-4 p-4 h-auto text-base justify-start whitespace-normal">
38+
<!-- need to use external because of how android handles links, if it's target _blank then the Blazor UrlLoading event will not fire-->
39+
<Button variant="ghost" href={mailtoUrl} external class="gap-4 p-4 h-auto text-base justify-start whitespace-normal">
3940
<Icon icon="i-mdi-email-outline" class="size-10"/>
4041
<div>
4142
<div class="font-semibold underline">

0 commit comments

Comments
 (0)