fix(desktop): claim the t3code:// scheme default on Linux at startup - #5054
fix(desktop): claim the t3code:// scheme default on Linux at startup#5054juliusmarminge wants to merge 3 commits into
Conversation
The AppImage's integrated .desktop entry now advertises MimeType=x-scheme-handler/t3code, so the app shows up in the browser's "Choose an application" dialog — but nothing records it as the default handler, so every OAuth callback prompts the user again (and the entry's filename is decided by the integration tool, e.g. AppImageLauncher's appimagekit_<hash>-….desktop, so Electron's setAsDefaultProtocolClient cannot claim it via setDesktopName). Write a dedicated t3code-url-handler.desktop into $XDG_DATA_HOME/applications pointing at the current $APPIMAGE and set it as the scheme default via xdg-mime — the same association the file manager's "set as default" checkbox records. Registration is best-effort and never blocks startup. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
There was a problem hiding this comment.
Reviewed the new DesktopLinuxUrlHandler service against the Effect service conventions. The service/tag/make/layer shape, namespace imports, dependency acquisition (yield* Foo.Foo), and Effect.catch on a fully-handled channel all look right. Two error-modeling issues below.
Posted via Macroscope — Effect Service Conventions
…on errors Add desktopEntryPath and exitCode fields to DesktopLinuxUrlHandlerRegistrationError so failures log the resolved entry path and the xdg-mime exit status instead of burying them in a synthetic Error cause; cause is now optional for the domain failure. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implementations unescape a desktop entry's Exec value twice: the general string-value rules first, then the Exec quoting rules. Writing therefore has to apply Exec quoting first and general string escaping on top, so a literal backslash in the AppImage path lands as four backslashes in the file, a double quote as \\" and a dollar sign as \\$. The previous single-layer escaping produced a malformed command for paths containing those characters. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
ApprovabilityVerdict: Needs human review This PR introduces a new Linux-specific feature that writes .desktop files and executes xdg-mime commands at startup to claim URL scheme defaults. While well-scoped and defensive (failures don't block startup), new features with filesystem/process interactions warrant human review. You can customize Macroscope's approvability policy. Learn more. |
Summary
Follow-up to #5015. Linux users still get the "Choose an application to open 't3code'" prompt on every OAuth callback (and Firefox flows keep failing), even though the scheme registration from #5015 shipped — the app now appears in the chooser but is never recorded as the default handler for
x-scheme-handler/t3code.Why the OS keeps prompting
Linux ships as an AppImage, so the integrated
.desktopentry's filename is decided by whatever integration tool the user runs (AppImageLauncher names itappimagekit_<hash>-….desktop). Electron'sapp.setAsDefaultProtocolClientresolves the desktop id fromsetDesktopName(t3code.desktop), which can never match those files — so there is no reliable built-in way to claim the default.The fix
On packaged Linux startup, the new
DesktopLinuxUrlHandlerservice:t3code-url-handler.desktopinto$XDG_DATA_HOME/applications(default~/.local/share/applications) withExec="$APPIMAGE" %U,MimeType=x-scheme-handler/t3code;, andNoDisplay=true. Pointing at$APPIMAGEmatters:process.execPathlives in the transient/tmp/.mount_*squashfs (it is used only as a fallback outside an AppImage). Exec values use freedesktop quoting (%doubled,"`$\escaped).xdg-mime default t3code-url-handler.desktop x-scheme-handler/t3code— the same association the file manager's "set as default app" checkbox records inmimeapps.list.Registration is best-effort: any failure (missing
xdg-utils, read-only home) logs a warning and never blocks startup; the OS chooser remains as fallback. Re-running on every launch keeps theExecpath current when the AppImage moves, and lets whichever channel (stable/nightly) launched last own the scheme — matching macOS semantics.Supporting changes:
DesktopConfigreadsXDG_DATA_HOME, andDesktopEnvironmentexposeslinuxApplicationsDir+appImagePath(already parsed from$APPIMAGE).User impact
After updating and launching the app once, browser OAuth redirects open T3 Code directly — no chooser dialog in Chrome/Chromium, and Firefox shows its standard one-time confirmation with T3 Code preselected instead of failing.
Test plan
DesktopLinuxUrlHandler.test.ts: desktop-entry rendering incl. Exec quoting, AppImage vs. executable fallback, xdg-mime invocation, platform/packaged gating, and that write/xdg-mime failures never fail startup🤖 Generated with Claude Code
Note
Low Risk
Linux-only, packaged-only startup side effect with swallowed errors; no auth or shared-backend changes, though it modifies user mimeapps associations for the custom scheme.
Overview
Packaged Linux builds now register the custom
t3code://scheme as the OS default so OAuth redirects stop opening the “choose an application” dialog on every callback.A new
DesktopLinuxUrlHandlerservice runs during startup (after Electron is ready): it writes a hiddent3code-url-handler.desktopunder the XDG applications dir (fromXDG_DATA_HOME, default~/.local/share/applications) withExecpointing at$APPIMAGE(not the transient/tmp/.mount_*process.execPath), then runsxdg-mime defaultforx-scheme-handler/t3code. This sidesteps Electron’ssetAsDefaultProtocolClient, which cannot match AppImageLauncher-generated desktop entry names.Registration is best-effort—write or
xdg-mimefailures log structured warnings and never block startup.DesktopEnvironmentnow exposeslinuxApplicationsDirandappImagePath; tests cover Exec quoting, platform gating, and failure paths.Reviewed by Cursor Bugbot for commit be4a826. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Claim the
t3code://URL scheme on Linux at startup by registering a.desktophandlerDesktopLinuxUrlHandlerwhich writes at3code-url-handler.desktopfile and runsxdg-mime defaultto register the app as the default handler for thet3code://scheme.appImagePathwhen available as theExectarget, falling back toprocess.execPath; resolves the output directory fromXDG_DATA_HOME, defaulting to~/.local/share/applications.Macroscope summarized be4a826.