Skip to content

Commit

Permalink
modules/android-integration: termux-open, termux-open-url, xdg-open
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed Jul 6, 2024
1 parent f7eafb6 commit 168cba6
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
### New Options

* New options under `android-integration`,
offer some of the tools familiar to Termux users.
Currently only `am` and `termux-setup-storage` are provided.
offer some of the tools familiar to Termux users:
`am`, `termux-open`, `termux-open-url`, `termux-setup-storage` and `xdg-open`.

### Compatibility considerations

Expand Down
34 changes: 34 additions & 0 deletions modules/environment/android-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,28 @@ in
'';
};

termux-open.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide a `termux-open` command
that opens files or urls in external apps
(uses `com.termux.app.TermuxOpenReceiver`).
'';
};

termux-open-url.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide a `termux-open-url` command
that opens files or urls in external apps
(uses `android.intent.action.VIEW`).
'';
};

termux-setup-storage.enable = lib.mkOption {
type = lib.types.bool;
default = false;
Expand All @@ -40,6 +62,15 @@ in
'';
};

xdg-open.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide an `xdg-open` alias to `termux-open` command.
'';
};

unsupported.enable = lib.mkOption {
type = lib.types.bool;
default = false;
Expand All @@ -58,6 +89,9 @@ in
environment.packages =
(ifD cfg.am.enable termux-am) ++
(ifD cfg.termux-setup-storage.enable termux-tools.setup_storage) ++
(ifD cfg.termux-open.enable termux-tools.open) ++
(ifD cfg.termux-open-url.enable termux-tools.open_url) ++
(ifD cfg.xdg-open.enable termux-tools.xdg_open) ++
(ifD cfg.unsupported.enable termux-tools.out);
};
}
16 changes: 13 additions & 3 deletions pkgs/android-integration/termux-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ stdenvNoCC.mkDerivation rec {
outputs = [
"out" # all the unsupported unsorted stuff
"setup_storage" # termux-setup-storage
"open" # termux-open
"open_url" # termux-open-url
"xdg_open" # xdg-open
];
postInstall = ''
rm $out/etc/termux-login.sh
Expand Down Expand Up @@ -79,17 +82,24 @@ stdenvNoCC.mkDerivation rec {
mkdir -p $setup_storage/bin
mv $out/bin/termux-setup-storage $setup_storage/bin/
mkdir -p $open/bin
mv $out/bin/termux-open $open/bin/
mkdir -p $open_url/bin
mv $out/bin/termux-open-url $open_url/bin/
mkdir -p $xdg_open/bin
rm $out/bin/xdg-open
ln -s $open/bin/termux-open $xdg_open/bin/xdg-open
# check that we didn't package we didn't want to
find $out | ${gnused}/bin/sed "s|^$out|.|" | sort > effective
echo . >> expected
echo ./bin >> expected
echo ./bin/termux-backup >> expected # entirely untested
echo ./bin/termux-open >> expected # good candidate for fixing
echo ./bin/termux-open-url >> expected # good candidate for fixing
echo ./bin/termux-reload-settings >> expected # good candidate for fixing
echo ./bin/termux-wake-lock >> expected # good candidate for fixing
echo ./bin/termux-wake-unlock >> expected # good candidate for fixing
echo ./bin/xdg-open >> expected # good candidate for fixing
echo ./share >> expected
echo ./share/examples >> expected
echo ./share/examples/termux >> expected
Expand Down
27 changes: 19 additions & 8 deletions tests/emulator/android_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@


def run(d):
OPENERS = ['termux-open', 'termux-open-url', 'xdg-open']
TOOLS = ['am', 'termux-setup-storage'] + OPENERS

nod = bootstrap_channels.run(d)

# Verify that android-integration tools aren't installed by default
d('input text "am"')
d.ui.press('enter')
wait_for(d, 'bash: am: command not found')
screenshot(d, 'no-am')
d('input text "termux-setup-storage"')
d.ui.press('enter')
wait_for(d, 'bash: termux-setup-storage: command not found')
screenshot(d, 'no-termux-setup-storage')
for toolname in TOOLS:
d(f'input text "{toolname}"')
d.ui.press('enter')
wait_for(d, f'bash: {toolname}: command not found')
screenshot(d, f'no-{toolname}')

# Apply a config that enables android-integration tools
cfg = ('/data/local/tmp/n-o-d/unpacked/tests/on-device/'
Expand Down Expand Up @@ -100,3 +100,14 @@ def run(d):
wait_for(d, 'Do you want to continue?')
d.ui.press('enter')
wait_for(d, 'Aborting configuration and leaving')

# Verify that *-open* commands work
for opener in OPENERS:
d(f'input text "{opener} https://example.org"')
d.ui.press('enter')
screenshot(d, f'{opener}-opened')
wait_for(d, 'This domain is for use in illustrative')
screenshot(d, f'{opener}-waited')
d.ui.press('back')
screenshot(d, f'{opener}-back')
wait_for(d, f'{opener} https://example.org')
11 changes: 10 additions & 1 deletion tests/on-device/config-android-integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ load lib
bats_require_minimum_version 1.5.0
run ! command -v am
run ! command -v termux-setup-storage
run ! command -v termux-open
run ! command -v termux-open-url
run ! command -v xdg-open
run ! command -v termux-backup

cp \
"$ON_DEVICE_TESTS_DIR/config-android-integration.nix" \
Expand All @@ -15,7 +18,10 @@ load lib

command -v am
command -v termux-setup-storage
run ! command -v termux-open-url
command -v termux-open
command -v termux-open-url
command -v xdg-open
run ! command -v termux-backup

_sed \
-e "s|# unsupported.enable = false;|unsupported.enable = true;|" \
Expand All @@ -24,7 +30,10 @@ load lib
nix-on-droid switch
run ! command -v am
command -v termux-setup-storage
command -v termux-open
command -v termux-open-url
command -v xdg-open
command -v termux-backup

switch_to_default_config
}
3 changes: 3 additions & 0 deletions tests/on-device/config-android-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ _:
system.stateVersion = "23.11";
android-integration = {
am.enable = true;
termux-open.enable = true;
termux-open-url.enable = true;
termux-setup-storage.enable = true;
xdg-open.enable = true;
# unsupported.enable = false;
};
}

0 comments on commit 168cba6

Please sign in to comment.