fix(open-external): support Termux (platform android) openers

On Termux — the dominant Node runtime that reports process.platform
'android' — both external-open actions fell through to xdg-open, which
does not exist there, so 'reveal in file manager' and custom-scheme URL
opens failed silently (the spawn error is swallowed by design).

- revealCommand: case 'android' → termux-open on the containing
  directory (no desktop file manager and no select protocol on Android;
  same parent-dir KISS as the Linux branch)
- urlCommand: case 'android' → termux-open-url (the URL intent
  dispatcher; termux-open would route URLs through the content chooser)

Command builders stay pure — the platform remains injectable and the new
branches are unit-tested like every other platform.
This commit is contained in:
240xu committed 2026-09-26 20:23:33 +08:00
1 parent d641d2e211
commit eb37f933d3
2 files changed
+21

No files matched your search

+12
View File
@@ -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 "" <url>` 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] }
}
+9
View File
@@ -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 <url>` 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 <url>` dispatches the Android intent', () => {
expect(urlCommand('vscode://file/x', 'android')).toEqual({ command: 'termux-open-url', args: ['vscode://file/x'] })
})
})
describe('validateExternalUrl', () => {