Open gXLg opened 3 years ago
I guess that would be android 10+ only implementation
I guess that would be android 10+ only implementation
Termux:API already provides some features, that are not able to run on some devices, which e.g. don't have a infrared emitter
I wonder is there any other way to detect current scheme of system from Termux. Really want to put it in my start script to auto-switch themes.
Grant termux DUMP
permission and run dumpsys uimode
and grep
output for mNightMode=
for current setting, which may be auto
. To get current state, grep
mCurUiMode=
for current flags.
Can get current setting with setting="$(cmd uimode night 2>&1 </dev/null)"
as well.
This indeed worked for me! (no root needed) To grant DUMP, use ADB and enter following:
adb shell pm grant com.termux android.permission.DUMP
I do also tried to get some info from getprop
, but it's very vendor-dependent. Here's how the values change depending on system color mode.
$ diff prop_light.dump prop_dark.dump
1205c1205
< [sys.oplus.display.uimode]: [17]
---
> [sys.oplus.display.uimode]: [33]
I have a termux-is-dark-mode
"polyfill" script in my ~/bin/
:
#!/usr/bin/bash
set -f
[[ "$(cmd uimode night 2>&1 < /dev/null)" == *yes ]]
It allows clean code like:
if termux-is-dark-mode
then echo 🌙
else echo ☀️
fi
BTW, if such a cmd is ever added, should it be a getter/setter or only getter?
Something like termux-ui-night-mode
can accept the get
and set
argument. However setting with cmd uimode night yes|no
will require root or adb as ui_night_mode
is a secure
setting, which technically can be handled as termux supports both.
@Rudxain I believe that the correct way of implementing this feature is a special API package CLI getter script (termux-theme
for example), that will use the API implementation for theme managing _(@TERMUX_PREFIX@/libexec/termux-api Theme
for example)_ and return the output like:
{
"mode": "DARK", // Or "LIGHT"
"some": "more",
"info": "data"
}
The next problem is Termux:API target SDK version:
It's 28, and system-wide themes API is only available starting from the SDK 29 (Android 10).
targetSdkVersion
!= compileSdkVersion
.
Feature Suugestion
Would be nice to be able to know, whether the device has currently dark mode enabled.
Could be useful for example in .bashrc: