Merge PR #769: fix(open-external): support Termux (platform android) openers

This commit is contained in:
HuanLinOTO committed 2026-10-01 17:18:31 +08:00
commit d23bbde0f7
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', () => {