From e0216d3e47d195aadf4ec3e7aa991a7b90504a08 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sat, 6 Jul 2024 18:26:18 +0200 Subject: [PATCH] modules/android-integration: termux-reload-settings --- CHANGELOG.md | 2 +- modules/environment/android-integration.nix | 12 +++++++ pkgs/android-integration/termux-tools.nix | 7 ++++- tests/emulator/android_integration.py | 31 ++++++++++++++++++- .../on-device/config-android-integration.bats | 3 ++ .../on-device/config-android-integration.nix | 1 + 6 files changed, 53 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0bcff2d..ac6df52d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/modules/environment/android-integration.nix b/modules/environment/android-integration.nix index 36ba05c9..c8ba13e9 100644 --- a/modules/environment/android-integration.nix +++ b/modules/environment/android-integration.nix @@ -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; @@ -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) ++ diff --git a/pkgs/android-integration/termux-tools.nix b/pkgs/android-integration/termux-tools.nix index ead83fa5..7a4bf519 100644 --- a/pkgs/android-integration/termux-tools.nix +++ b/pkgs/android-integration/termux-tools.nix @@ -35,6 +35,8 @@ stdenvNoCC.mkDerivation rec { scripts/termux-wake-unlock.in \ --replace @TERMUX_APP_PACKAGE@.app 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 @@ -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 @@ -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/ @@ -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 diff --git a/tests/emulator/android_integration.py b/tests/emulator/android_integration.py index b301c6f3..df4e2e36 100644 --- a/tests/emulator/android_integration.py +++ b/tests/emulator/android_integration.py @@ -1,3 +1,4 @@ +import base64 import time import bootstrap_channels @@ -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) @@ -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() diff --git a/tests/on-device/config-android-integration.bats b/tests/on-device/config-android-integration.bats index 85b51465..5340d537 100644 --- a/tests/on-device/config-android-integration.bats +++ b/tests/on-device/config-android-integration.bats @@ -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 @@ -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 @@ -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 diff --git a/tests/on-device/config-android-integration.nix b/tests/on-device/config-android-integration.nix index 70a33337..dd30d5e4 100644 --- a/tests/on-device/config-android-integration.nix +++ b/tests/on-device/config-android-integration.nix @@ -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;