Skip to content

Commit

Permalink
modules/android-integration: termux-reload-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
t184256 committed Jul 7, 2024
1 parent 438cf8c commit e0216d3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

* New options under `android-integration`,
offer some of the tools familiar to Termux users:
`am`, `termux-open`, `termux-open-url`,
`am`, `termux-open`, `termux-open-url`, `termux-reload-settings`,
`termux-setup-storage`, `termux-wake-lock`, `termux-wake-unlock`
and `xdg-open`.

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

termux-reload-settings.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = "true";
description = lib.mdDoc ''
Provide a `termux-reload-settings` command
which applies changes to font, colorscheme or terminal
without the need to close all the sessions.
'';
};

termux-wake-lock.enable = lib.mkOption {
type = lib.types.bool;
default = false;
Expand Down Expand Up @@ -112,6 +123,7 @@ in
(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.termux-reload-settings.enable termux-tools.reload_settings) ++
(ifD cfg.termux-wake-lock.enable termux-tools.wake_lock) ++
(ifD cfg.termux-wake-unlock.enable termux-tools.wake_unlock) ++
(ifD cfg.xdg-open.enable termux-tools.xdg_open) ++
Expand Down
7 changes: 6 additions & 1 deletion pkgs/android-integration/termux-tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ stdenvNoCC.mkDerivation rec {
scripts/termux-wake-unlock.in \
--replace @[email protected] com.termux.app \
--replace @TERMUX_APP_PACKAGE@ com.termux.nix
substituteInPlace scripts/termux-reload-settings.in \
--replace @TERMUX_APP_PACKAGE@ com.termux.nix
${gnused}/bin/sed -i 's|^am |${termux-am}/bin/am |' scripts/*
rm -r doc # manpage is half misleading, pulling pandoc is not worth it
Expand All @@ -53,6 +55,7 @@ stdenvNoCC.mkDerivation rec {
"setup_storage" # termux-setup-storage
"open" # termux-open
"open_url" # termux-open-url
"reload_settings" # termux-reload-settings
"wake_lock" # termux-wake-lock
"wake_unlock" # termux-wake-unlock
"xdg_open" # xdg-open
Expand Down Expand Up @@ -94,6 +97,9 @@ stdenvNoCC.mkDerivation rec {
mkdir -p $open_url/bin
mv $out/bin/termux-open-url $open_url/bin/
mkdir -p $reload_settings/bin
mv $out/bin/termux-reload-settings $reload_settings/bin/
mkdir -p $wake_lock/bin
mv $out/bin/termux-wake-lock $wake_lock/bin/
Expand All @@ -109,7 +115,6 @@ stdenvNoCC.mkDerivation rec {
echo . >> expected
echo ./bin >> expected
echo ./bin/termux-backup >> expected # entirely untested
echo ./bin/termux-reload-settings >> expected # good candidate for fixing
echo ./share >> expected
echo ./share/examples >> expected
echo ./share/examples/termux >> expected
Expand Down
31 changes: 30 additions & 1 deletion tests/emulator/android_integration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
import time

import bootstrap_channels
Expand All @@ -7,7 +8,7 @@

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

nod = bootstrap_channels.run(d)
Expand Down Expand Up @@ -162,3 +163,31 @@ def run(d):
screenshot(d, 'back')
wait_for(d, 'termux-wake-unlock')
screenshot(d, 'really-back')

# Test termux-reload-settings
assert 'text="PGUP"' in d.ui.dump_hierarchy()
assert 'text="F12"' not in d.ui.dump_hierarchy()

d('input text "mkdir ~/.termux"')
d.ui.press('enter')
cmd = 'echo "extra-keys=[[\'F12\']]" > ~/.termux/termux.properties'
cmd_base64 = base64.b64encode(cmd.encode()).decode()
d(f'input text "echo {cmd_base64} | base64 -d | bash -s"')
d.ui.press('enter')
screenshot(d, 'pre-reload')
d('input text "termux-reload-settings"')
d.ui.press('enter')
time.sleep(1)
screenshot(d, 'post-reload')
assert 'text="PGUP"' not in d.ui.dump_hierarchy()
assert 'text="F12"' in d.ui.dump_hierarchy()

d('input text "rm -r ~/.termux"')
d.ui.press('enter')
screenshot(d, 'pre-reload-back')
d('input text "termux-reload-settings"')
d.ui.press('enter')
time.sleep(1)
screenshot(d, 'post-reload-back')
assert 'text="PGUP"' in d.ui.dump_hierarchy()
assert 'text="F12"' not in d.ui.dump_hierarchy()
3 changes: 3 additions & 0 deletions tests/on-device/config-android-integration.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ load lib
run ! command -v termux-setup-storage
run ! command -v termux-open
run ! command -v termux-open-url
run ! command -v termux-reload-settings
run ! command -v termux-wake-lock
run ! command -v termux-wake-unlock
run ! command -v xdg-open
Expand All @@ -22,6 +23,7 @@ load lib
command -v termux-setup-storage
command -v termux-open
command -v termux-open-url
command -v termux-reload-settings
command -v termux-wake-lock
command -v termux-wake-unlock
command -v xdg-open
Expand All @@ -36,6 +38,7 @@ load lib
command -v termux-setup-storage
command -v termux-open
command -v termux-open-url
command -v termux-reload-settings
command -v termux-wake-lock
command -v termux-wake-unlock
command -v xdg-open
Expand Down
1 change: 1 addition & 0 deletions tests/on-device/config-android-integration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ _:
am.enable = true;
termux-open.enable = true;
termux-open-url.enable = true;
termux-reload-settings.enable = true;
termux-setup-storage.enable = true;
termux-wake-lock.enable = true;
termux-wake-unlock.enable = true;
Expand Down

0 comments on commit e0216d3

Please sign in to comment.