()
| 82 | * @returns exit code (0 = success, 1 = error, null = not a URL launch) |
| 83 | */ |
| 84 | export async function handleUrlSchemeLaunch(): Promise<number | null> { |
| 85 | // LaunchServices overwrites __CFBundleIdentifier with the launching bundle's |
| 86 | // ID. This is a precise positive signal — it's set to our exact bundle ID |
| 87 | // if and only if macOS launched us via the URL handler .app bundle. |
| 88 | // (`open` from a terminal passes the caller's env through, so negative |
| 89 | // heuristics like !TERM don't work — the terminal's TERM leaks in.) |
| 90 | if (process.env.__CFBundleIdentifier !== MACOS_BUNDLE_ID) { |
| 91 | return null |
| 92 | } |
| 93 | |
| 94 | try { |
| 95 | const { waitForUrlEvent } = await import('url-handler-napi') |
| 96 | const url = waitForUrlEvent(5000) |
| 97 | if (!url) { |
| 98 | return null |
| 99 | } |
| 100 | return await handleDeepLinkUri(url) |
| 101 | } catch { |
| 102 | // NAPI module not available, or handleDeepLinkUri rejected — not a URL launch |
| 103 | return null |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Resolve the working directory for the launched Claude instance. |
no test coverage detected