feat: convert WSL Linux paths to Windows UNC paths when opening binary files #215

Closed
opened 2026-03-11 19:11:55 -07:00 by hikari · 0 comments
Owner

Summary

Follow-up to #211. When clicking a binary file link (PDF, audio, Office doc, etc.) rendered by the MCP binary content handler, the frontend calls openPath(filePath) via the Tauri opener plugin.

This works correctly on Linux native, but fails on Windows/WSL because:

  • Claude Code (running inside WSL) saves files with Linux-style paths, e.g. /tmp/mcp_output_abc123.pdf
  • The Tauri app (running on Windows) cannot resolve /tmp/mcp_output_abc123.pdf — it needs the equivalent Windows UNC path, e.g. \\wsl.localhost\Ubuntu\tmp\mcp_output_abc123.pdf

The same limitation applies to the existing openPath usage in sessions.ts (PDF export).

Required Changes

Backend — new Tauri command open_binary_file

Add a Rust command that handles the path translation:

#[tauri::command]
pub async fn open_binary_file(path: String) -> Result<(), String> {
    #[cfg(target_os = "windows")]
    {
        // Convert Linux WSL path to Windows UNC path via `wslpath -w`
        let output = std::process::Command::new("wsl")
            .args(["wslpath", "-w", &path])
            .output()
            .map_err(|e| e.to_string())?;
        let windows_path = String::from_utf8_lossy(&output.stdout).trim().to_string();
        opener::open(&windows_path).map_err(|e| e.to_string())
    }
    #[cfg(not(target_os = "windows"))]
    {
        opener::open(&path).map_err(|e| e.to_string())
    }
}

Frontend — Markdown.svelte

Replace the direct openPath(filePath) call with an invoke("open_binary_file", { path: filePath }) call so the backend handles path translation.

Notes

  • wslpath -w is available wherever WSL is installed alongside the Tauri app
  • On non-Windows platforms the command falls through to opener::open unchanged
  • The same command could be used to fix sessions.ts PDF export on Windows/WSL

This issue was created with help from Hikari~ 🌸

## Summary Follow-up to #211. When clicking a binary file link (PDF, audio, Office doc, etc.) rendered by the MCP binary content handler, the frontend calls `openPath(filePath)` via the Tauri opener plugin. This works correctly on **Linux native**, but **fails on Windows/WSL** because: - Claude Code (running inside WSL) saves files with Linux-style paths, e.g. `/tmp/mcp_output_abc123.pdf` - The Tauri app (running on Windows) cannot resolve `/tmp/mcp_output_abc123.pdf` — it needs the equivalent Windows UNC path, e.g. `\\wsl.localhost\Ubuntu\tmp\mcp_output_abc123.pdf` The same limitation applies to the existing `openPath` usage in `sessions.ts` (PDF export). ## Required Changes ### Backend — new Tauri command `open_binary_file` Add a Rust command that handles the path translation: ```rust #[tauri::command] pub async fn open_binary_file(path: String) -> Result<(), String> { #[cfg(target_os = "windows")] { // Convert Linux WSL path to Windows UNC path via `wslpath -w` let output = std::process::Command::new("wsl") .args(["wslpath", "-w", &path]) .output() .map_err(|e| e.to_string())?; let windows_path = String::from_utf8_lossy(&output.stdout).trim().to_string(); opener::open(&windows_path).map_err(|e| e.to_string()) } #[cfg(not(target_os = "windows"))] { opener::open(&path).map_err(|e| e.to_string()) } } ``` ### Frontend — `Markdown.svelte` Replace the direct `openPath(filePath)` call with an `invoke("open_binary_file", { path: filePath })` call so the backend handles path translation. ## Notes - `wslpath -w` is available wherever WSL is installed alongside the Tauri app - On non-Windows platforms the command falls through to `opener::open` unchanged - The same command could be used to fix `sessions.ts` PDF export on Windows/WSL ✨ This issue was created with help from Hikari~ 🌸
naomi closed this issue 2026-03-13 01:34:46 -07:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nhcarrigan/hikari-desktop#215