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