mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 19:46:07 +01:00
modules/android-integration: termux-wake-lock and termux-wake-unlock
This commit is contained in:
parent
66031de5a7
commit
f12e0ef38b
6 changed files with 100 additions and 6 deletions
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
* New options under `android-integration`,
|
||||
offer some of the tools familiar to Termux users:
|
||||
`am`, `termux-open`, `termux-open-url`, `termux-setup-storage` and `xdg-open`.
|
||||
`am`, `termux-open`, `termux-open-url`,
|
||||
`termux-setup-storage`, `termux-wake-lock`, `termux-wake-unlock`
|
||||
and `xdg-open`.
|
||||
|
||||
### Compatibility considerations
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,27 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
termux-wake-lock.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
example = "true";
|
||||
description = lib.mdDoc ''
|
||||
Provide a `termux-wake-lock` command
|
||||
that tones down Android power saving measures.
|
||||
This is the same action that's available from the notification.
|
||||
'';
|
||||
};
|
||||
|
||||
termux-wake-unlock.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
example = "true";
|
||||
description = lib.mdDoc ''
|
||||
Provide a `termux-wake-unlock` command
|
||||
that undoes the effect of the `termux-wake-lock` one.
|
||||
'';
|
||||
};
|
||||
|
||||
xdg-open.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
|
|
@ -91,6 +112,8 @@ 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-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) ++
|
||||
(ifD cfg.unsupported.enable termux-tools.out);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,9 +28,13 @@ stdenvNoCC.mkDerivation rec {
|
|||
--replace @TERMUX_HOME@ /data/data/com.termux.nix/files/home/ \
|
||||
--replace @TERMUX_APP_PACKAGE@ com.termux.nix
|
||||
substituteInPlace scripts/termux-open.in \
|
||||
--replace @TERMUX_APP_PACKAGE@.app com.termux.app \
|
||||
--replace @TERMUX_APP_PACKAGE@ com.termux.nix \
|
||||
--replace 'getopt ' '${getopt}/bin/getopt '
|
||||
substituteInPlace \
|
||||
scripts/termux-open.in \
|
||||
scripts/termux-wake-lock.in \
|
||||
scripts/termux-wake-unlock.in \
|
||||
--replace @TERMUX_APP_PACKAGE@.app com.termux.app \
|
||||
--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
|
||||
|
|
@ -49,6 +53,8 @@ stdenvNoCC.mkDerivation rec {
|
|||
"setup_storage" # termux-setup-storage
|
||||
"open" # termux-open
|
||||
"open_url" # termux-open-url
|
||||
"wake_lock" # termux-wake-lock
|
||||
"wake_unlock" # termux-wake-unlock
|
||||
"xdg_open" # xdg-open
|
||||
];
|
||||
postInstall = ''
|
||||
|
|
@ -88,6 +94,12 @@ stdenvNoCC.mkDerivation rec {
|
|||
mkdir -p $open_url/bin
|
||||
mv $out/bin/termux-open-url $open_url/bin/
|
||||
|
||||
mkdir -p $wake_lock/bin
|
||||
mv $out/bin/termux-wake-lock $wake_lock/bin/
|
||||
|
||||
mkdir -p $wake_unlock/bin
|
||||
mv $out/bin/termux-wake-unlock $wake_unlock/bin/
|
||||
|
||||
mkdir -p $xdg_open/bin
|
||||
rm $out/bin/xdg-open
|
||||
ln -s $open/bin/termux-open $xdg_open/bin/xdg-open
|
||||
|
|
@ -98,8 +110,6 @@ stdenvNoCC.mkDerivation rec {
|
|||
echo ./bin >> expected
|
||||
echo ./bin/termux-backup >> expected # entirely untested
|
||||
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 ./share >> expected
|
||||
echo ./share/examples >> expected
|
||||
echo ./share/examples/termux >> expected
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ from common import screenshot, wait_for
|
|||
|
||||
def run(d):
|
||||
OPENERS = ['termux-open', 'termux-open-url', 'xdg-open']
|
||||
TOOLS = ['am', 'termux-setup-storage'] + OPENERS
|
||||
TOOLS = ['am', 'termux-setup-storage',
|
||||
'termux-wake-lock', 'termux-wake-unlock'] + OPENERS
|
||||
|
||||
nod = bootstrap_channels.run(d)
|
||||
|
||||
|
|
@ -111,3 +112,53 @@ def run(d):
|
|||
d.ui.press('back')
|
||||
screenshot(d, f'{opener}-back')
|
||||
wait_for(d, f'{opener} https://example.org')
|
||||
|
||||
# test termux-wake-lock/termux-wake-unlock
|
||||
d.ui.open_notification()
|
||||
screenshot(d, 'notification-opened')
|
||||
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
|
||||
screenshot(d, 'notification-expanded')
|
||||
wait_for(d, 'Acquire wakelock')
|
||||
screenshot(d, 'wakelock-initially-not-acquired')
|
||||
d.ui.press('back')
|
||||
|
||||
d('input text "termux-wake-lock"')
|
||||
d.ui.press('enter')
|
||||
time.sleep(3)
|
||||
screenshot(d, 'wake-lock-command')
|
||||
if 'Let app always run in background?' in d.ui.dump_hierarchy():
|
||||
screenshot(d, 'wake-lock-permission-asked')
|
||||
if 'text="Allow"' in d.ui.dump_hierarchy():
|
||||
d.ui(text='Allow').click()
|
||||
elif 'text="ALLOW"' in d.ui.dump_hierarchy():
|
||||
d.ui(text='ALLOW').click()
|
||||
screenshot(d, 'wake-lock-permission-granted')
|
||||
d.ui.open_notification()
|
||||
time.sleep(.5)
|
||||
screenshot(d, 'notification-opened')
|
||||
wait_for(d, '(wake lock held)')
|
||||
if 'Release wakelock' not in d.ui.dump_hierarchy():
|
||||
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
|
||||
screenshot(d, 'notification-expanded')
|
||||
wait_for(d, 'Release wakelock')
|
||||
screenshot(d, 'notification-with-wakelock')
|
||||
d.ui.press('back')
|
||||
screenshot(d, 'back')
|
||||
wait_for(d, 'termux-wake-lock')
|
||||
screenshot(d, 'really-back')
|
||||
|
||||
d('input text "termux-wake-unlock"')
|
||||
d.ui.press('enter')
|
||||
screenshot(d, 'wake-unlock-command')
|
||||
d.ui.open_notification()
|
||||
time.sleep(.5)
|
||||
screenshot(d, 'notification-opened')
|
||||
if 'Acquire wakelock' not in d.ui.dump_hierarchy():
|
||||
d.ui(text='Nix').right(resourceId='android:id/expand_button').click()
|
||||
screenshot(d, 'notification-expanded')
|
||||
wait_for(d, 'Acquire wakelock')
|
||||
screenshot(d, 'notification-without-wakelock')
|
||||
d.ui.press('back')
|
||||
screenshot(d, 'back')
|
||||
wait_for(d, 'termux-wake-unlock')
|
||||
screenshot(d, 'really-back')
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ load lib
|
|||
run ! command -v termux-setup-storage
|
||||
run ! command -v termux-open
|
||||
run ! command -v termux-open-url
|
||||
run ! command -v termux-wake-lock
|
||||
run ! command -v termux-wake-unlock
|
||||
run ! command -v xdg-open
|
||||
run ! command -v termux-backup
|
||||
|
||||
|
|
@ -20,6 +22,8 @@ load lib
|
|||
command -v termux-setup-storage
|
||||
command -v termux-open
|
||||
command -v termux-open-url
|
||||
command -v termux-wake-lock
|
||||
command -v termux-wake-unlock
|
||||
command -v xdg-open
|
||||
run ! command -v termux-backup
|
||||
|
||||
|
|
@ -32,6 +36,8 @@ load lib
|
|||
command -v termux-setup-storage
|
||||
command -v termux-open
|
||||
command -v termux-open-url
|
||||
command -v termux-wake-lock
|
||||
command -v termux-wake-unlock
|
||||
command -v xdg-open
|
||||
command -v termux-backup
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ _:
|
|||
termux-open.enable = true;
|
||||
termux-open-url.enable = true;
|
||||
termux-setup-storage.enable = true;
|
||||
termux-wake-lock.enable = true;
|
||||
termux-wake-unlock.enable = true;
|
||||
xdg-open.enable = true;
|
||||
# unsupported.enable = false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue