Skip to content

Allows desktop apps to open mailto links #4282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 18, 2025
Merged

Conversation

jjvn84
Copy link
Contributor

@jjvn84 jjvn84 commented Jun 15, 2025

Added an option to the WebViewBuilder navigation handler to open links starting with "mailto:".

webview = webview
            .with_web_context(&mut web_context)
            .with_bounds(wry::Rect {
                position: wry::dpi::Position::Logical(wry::dpi::LogicalPosition::new(0.0, 0.0)),
                size: wry::dpi::Size::Physical(wry::dpi::PhysicalSize::new(
                    window.inner_size().width,
                    window.inner_size().height,
                )),
             })
            .with_transparent(cfg.window.window.transparent)
            .with_url("dioxus://index.html/")
            .with_ipc_handler(ipc_handler)
            .with_navigation_handler(|var| {
                // We don't want to allow any navigation
                // We only want to serve the index file and assets
                if var.starts_with("dioxus://") || var.starts_with("http://dioxus.") {
                    true
                 } else {
                    if var.starts_with("http://") || var.starts_with("https://") {
                        _ = webbrowser::open(&var);
                     } else if var.starts_with("mailto:") {
                        _ = open::that(&var);
                     }
                    false
                }
 })

This adds a dependency to the open crate.
We can also join the two if branches and use the open crate to open http, https, and mailto links. Is there a reason to keep them separated?

Fixes #2991

@jjvn84 jjvn84 requested a review from a team as a code owner June 15, 2025 22:50
@jkelleyrtp
Copy link
Member

It seems like open is the better of the two crates, so I switched your PR to just use open, removing the webbrowser dependency. Thanks for the PR!

@jkelleyrtp jkelleyrtp merged commit 1d3168d into DioxusLabs:main Jun 18, 2025
2 checks passed
@jjvn84 jjvn84 deleted the Issue2991 branch June 19, 2025 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'a' element with mailto link opens browser instead of mail program
2 participants