* Register the protocol handler on Linux. * Creates a .desktop file and registers it with xdg-mime.
(claudePath: string)
| 142 | * Creates a .desktop file and registers it with xdg-mime. |
| 143 | */ |
| 144 | async function registerLinux(claudePath: string): Promise<void> { |
| 145 | await fs.mkdir(path.dirname(linuxDesktopPath()), { recursive: true }) |
| 146 | |
| 147 | const desktopEntry = `[Desktop Entry] |
| 148 | Name=${APP_NAME} |
| 149 | Comment=Handle ${DEEP_LINK_PROTOCOL}:// deep links for Claude Code |
| 150 | ${linuxExecLine(claudePath)} |
| 151 | Type=Application |
| 152 | NoDisplay=true |
| 153 | MimeType=x-scheme-handler/${DEEP_LINK_PROTOCOL}; |
| 154 | ` |
| 155 | |
| 156 | await fs.writeFile(linuxDesktopPath(), desktopEntry) |
| 157 | |
| 158 | // Register as the default handler for the scheme. On headless boxes |
| 159 | // (WSL, Docker, CI) xdg-utils isn't installed — not a failure: there's |
| 160 | // no desktop to click links from, and some apps read the .desktop |
| 161 | // MimeType line directly. The artifact check still short-circuits |
| 162 | // next session since the .desktop file is present. |
| 163 | const xdgMime = await which('xdg-mime') |
| 164 | if (xdgMime) { |
| 165 | const { code } = await execFileNoThrow( |
| 166 | xdgMime, |
| 167 | ['default', DESKTOP_FILE_NAME, `x-scheme-handler/${DEEP_LINK_PROTOCOL}`], |
| 168 | { useCwd: false }, |
| 169 | ) |
| 170 | if (code !== 0) { |
| 171 | throw Object.assign(new Error(`xdg-mime exited with code ${code}`), { |
| 172 | code: 'XDG_MIME_FAILED', |
| 173 | }) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | logForDebugging( |
| 178 | `Registered ${DEEP_LINK_PROTOCOL}:// protocol handler at ${linuxDesktopPath()}`, |
| 179 | ) |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Register the protocol handler on Windows via the registry. |
no test coverage detected