diff --git a/src/open-external.ts b/src/open-external.ts index 6a1ef67f..bd3f7b11 100644 --- a/src/open-external.ts +++ b/src/open-external.ts @@ -32,6 +32,14 @@ export function revealCommand(path: string, platform: NodeJS.Platform = process. // shell-free: a command shell would reinterpret valid path characters. case 'win32': return { command: 'explorer.exe', args: [`/select,${path}`] } + // Termux (the dominant Node runtime reporting platform "android") has no + // desktop file manager and no xdg-open; `termux-open` hands the path to + // Android's system open-with chooser. Fall through to the parent dir like + // Linux: Android has no select protocol either. + case 'android': { + const parent = parentOf(path) + return { command: 'termux-open', args: [parent ?? path] } + } default: { const parent = parentOf(path) return { command: 'xdg-open', args: [parent ?? path] } @@ -48,6 +56,10 @@ export function urlCommand(url: string, platform: NodeJS.Platform = process.plat // `cmd /c start "" ` is the fallback if rundll32 misbehaves. case 'win32': return { command: 'rundll32.exe', args: ['url.dll,FileProtocolHandler', url] } + // Termux: `termux-open-url` is the Android intent dispatcher for URLs + // (termux-open would route through the content chooser first). + case 'android': + return { command: 'termux-open-url', args: [url] } default: return { command: 'xdg-open', args: [url] } } diff --git a/tests/open-external.spec.ts b/tests/open-external.spec.ts index d83477ce..e17d28f7 100644 --- a/tests/open-external.spec.ts +++ b/tests/open-external.spec.ts @@ -24,6 +24,11 @@ describe('revealCommand', () => { expect(revealCommand('/a/b.txt', 'linux')).toEqual({ command: 'xdg-open', args: ['/a'] }) expect(revealCommand('/', 'linux')).toEqual({ command: 'xdg-open', args: ['/'] }) }) + + it('android (Termux): `termux-open` hands the parent dir to the Android chooser', () => { + expect(revealCommand('/a/b.txt', 'android')).toEqual({ command: 'termux-open', args: ['/a'] }) + expect(revealCommand('/', 'android')).toEqual({ command: 'termux-open', args: ['/'] }) + }) }) describe('urlCommand', () => { @@ -41,6 +46,10 @@ describe('urlCommand', () => { it('linux: `xdg-open ` launches the registered protocol handler', () => { expect(urlCommand('zed://file/x', 'linux')).toEqual({ command: 'xdg-open', args: ['zed://file/x'] }) }) + + it('android (Termux): `termux-open-url ` dispatches the Android intent', () => { + expect(urlCommand('vscode://file/x', 'android')).toEqual({ command: 'termux-open-url', args: ['vscode://file/x'] }) + }) }) describe('validateExternalUrl', () => {