MCPcopy Index your code
hub / github.com/codeaashu/claude-code / registerLinux

Function registerLinux

src/utils/deepLink/registerProtocol.ts:144–180  ·  view source on GitHub ↗

* Register the protocol handler on Linux. * Creates a .desktop file and registers it with xdg-mime.

(claudePath: string)

Source from the content-addressed store, hash-verified

142 * Creates a .desktop file and registers it with xdg-mime.
143 */
144async function registerLinux(claudePath: string): Promise<void> {
145 await fs.mkdir(path.dirname(linuxDesktopPath()), { recursive: true })
146
147 const desktopEntry = `[Desktop Entry]
148Name=${APP_NAME}
149Comment=Handle ${DEEP_LINK_PROTOCOL}:// deep links for Claude Code
150${linuxExecLine(claudePath)}
151Type=Application
152NoDisplay=true
153MimeType=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.

Callers 1

registerProtocolHandlerFunction · 0.85

Calls 4

linuxDesktopPathFunction · 0.85
linuxExecLineFunction · 0.85
execFileNoThrowFunction · 0.85
logForDebuggingFunction · 0.85

Tested by

no test coverage detected