Skip to content

#144: links and sign-in pages bring the browser in front on Linux - #167

Merged
benandez merged 6 commits into
mainfrom
browser-in-front
Oct 18, 2026
Merged

benandez merged 6 commits into
mainfrom
browser-in-front

Conversation

@benandez

@benandez benandez commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Closes #144

What changes

  • Every page MailCraft opens now goes through apps/mailcraft/src/browser.rs. That covers Microsoft's sign-in, consent and admin-approval pages, links in messages, the meeting Join link, contact websites, update/credits pages and egui hyperlinks. egui's OpenUrl output is taken out of each frame before eframe would open it itself.
  • On Linux and FreeBSD the window asks winit for an activation token: xdg-activation under Wayland, a startup-notification id under X11. It then starts xdg-open <url> with the token in XDG_ACTIVATION_TOKEN and DESKTOP_STARTUP_ID. eframe ignores winit's ActivationTokenDone event, so on these platforms the window runs on our own event loop (eframe::create_native), with a thin wrapper that catches the token and passes everything else through. There is no unsafe and no fork.
  • In these cases the page opens the old way, without a token, through the system opener (webbrowser):
    • no token arrives within 1 s, or the compositor doesn't support xdg-activation
    • the address isn't plain http(s)
    • $BROWSER is set
    • xdg-open can't be started or fails
  • The "no browser could be started" path still works.
  • Addresses are never logged.
  • Windows and macOS are unchanged: ShellExecute and Launch Services already bring the browser forward.

Tests: a fake launcher checks the following:

  • a page opens with the token whose serial matches
  • a page opens without a token at once, or after the 1 s wait
  • the number of pages waiting is capped
  • a background caller opens the page itself if the window never takes it
  • the window's OpenUrl output is taken and other commands are left alone
  • the xdg-open command carries both environment variables and rejects non-web or control-character addresses
  • a source scan finds no other place that opens a page

Owner to check on KDE Plasma (Wayland)

  1. Open a link in a message: the browser should come in front of MailCraft. Try once with the browser already running and once with it closed.
  2. Add Account with a Microsoft address, or re-sign in: the sign-in page should come in front.
  3. An egui link, e.g. Help ▸ About ▸ Contributors or Google's app-passwords link in Add Account.
  4. Optional: the same on an X11 session, and on GNOME.
  5. Sanity check on Windows and macOS: links still open as before.

Every page MailCraft opens (Microsoft's sign-in, consent and approval
pages, and every link the window follows) now goes through
apps/mailcraft/src/browser.rs. On Linux and FreeBSD the window asks winit
for an activation token (xdg-activation under Wayland, startup
notification under X11), and xdg-open is started with it in
XDG_ACTIVATION_TOKEN and DESKTOP_STARTUP_ID, so that the compositor lets
the browser come forward. eframe drops the token event, so the window
runs on an event loop of our own there (eframe::create_native) wrapped to
catch it. No token within a second, a plain-http(s)-only check failing,
$BROWSER set, or xdg-open missing: the page opens the old way.
Windows and macOS are unchanged.
@benandez

Copy link
Copy Markdown
Member Author

Held for the owner's hand test on KDE Wayland before merging: it changes how the window's event loop is started on Linux/FreeBSD. Also to review: on a start-up failure the app now exits with code 0; it should exit non-zero.

…n token with the latest click

KWin brings a program forward only for a token whose request names the user's input; winit
0.30.13 sends none, so the browser was only marked as wanting attention. winit comes from
UCS-Care-Group/winit at 0.30.13 with that one change until winit does it itself. A page's
opening logs whether it had a token (never its address).
@benandez
benandez enabled auto-merge October 18, 2026 09:15
@benandez
benandez merged commit c2ac501 into main Oct 18, 2026
10 checks passed
@benandez
benandez deleted the browser-in-front branch October 18, 2026 09:36
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.

Links and sign-in pages open in the browser behind MailCraft

1 participant