Skip to content

Commit bf22447

Browse files
Added: Add dynamic shortcuts docs to readme
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com> Co-authored-by: Fabian Thomas <fabian@fabianthomas.de>
1 parent a7c9044 commit bf22447

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ Once you have created the directories, you can then create scripts files as per
8686

8787
Once you have created script files, you can add a launcher widget for the `Termux:Widget` app that will show the list of the script files, which you can execute by clicking them. If you create/modify shortcuts files, you will have to press the refresh button on the widget for the updated list to be shown. You can also refresh a specific widget by running `am broadcast -n com.termux.widget/.TermuxWidgetProvider -a com.termux.widget.ACTION_REFRESH_WIDGET --ei appWidgetId <id>` from Termux terminal/scripts for version `>= 0.13.0`, where `id` is the number in the `Termux shortcuts reloaded (<id>)` flash shown when you press the refresh button.
8888

89-
You can also add a launcher shortcut for any script file with an optional custom icon as detailed in [Script Icon Directory](#script-icon-directory-optional).
89+
You can also add a launcher shortcut or dynamic shortcut for any script file with an optional custom icon as detailed in [Script Icon Directory](#script-icon-directory-optional).
9090

9191
<img src="termux-widget.png" alt="" width="50%"/>
9292

93+
9394
#### Script Icon Directory (Optional)
9495

9596
The `~/.shortcuts/icons` directory stores the icon that will be used for a script when a launcher shortcut is created for it for version `>= 0.12`. The icon file name must be equal to `<script_name>.png`, like `script.sh.png`. For a `1080p` `~6in` screen, something like `96x96px` `png` file should probably be fine, otherwise try `144px` or `196px` for higher resolution screens.
@@ -109,7 +110,61 @@ chmod -R a-x,u=rwX,go-rwx /data/data/com.termux/files/home/.shortcuts/icons
109110
The `chmod` command will set the `icons` directory permissions to `0700`, but any files already in the directory will be set to `0600` which is recommended.
110111

111112

112-
#### `Draw Over Apps` permission (Optional)
113+
#### Dynamic Shortcuts (Optional)
114+
115+
Dynamic shortcuts will normally show when long holding the `Termux:Widget` app launcher icon and in launcher searches results.
116+
117+
To create dynamic shortcuts, put desired scripts/binaries in `~/.termux/widget/dynamic_shortcuts` with the Termux app and then click the `CREATE SHORTCUTS` button in the `Termux:Widget` app in the dynamic shortcuts section. To remove published dynamic shortcuts, click the `REMOVE SHORTCUTS` button but this won't remove dynamic shortcuts already converted to launcher shortcuts.
118+
119+
For some launchers it might be necessary to regenerate the app shortcuts to display them correctly. Lookup the settings of your launcher to find such actions.
120+
121+
122+
#### Max Shortcuts Limit (Optional)
123+
124+
Android has a limit on how many static and dynamic shortcuts can be created per app/activity, which is controlled by the [`max_shortcuts`](https://cs.android.com/android/platform/superproject/+/android-13.0.0_r8:frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java;l=254) sub key of the [`shortcut_manager_constants`](https://cs.android.com/android/platform/superproject/+/android-13.0.0_r8:frameworks/base/core/java/android/provider/Settings.java;l=13799) key in `global` settings namespace. The default value is [`5` on Android `>= 7.0`](https://cs.android.com/android/platform/superproject/+/android-7.0.0_r36:frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java;l=141), [`10` on Android `>= 10`](https://cs.android.com/android/platform/superproject/+/android-10.0.0_r1:frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java;l=165) and [`15` on Android `>= 11`](https://cs.android.com/android/platform/superproject/+/android-11.0.0_r9:frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java;l=172).
125+
126+
To check `max_shortcuts` value currently being used by android `ShortcutService`, run:
127+
128+
- `adb`: `adb shell "dumpsys shortcut | grep -E 'maxShortcutsPerActivity|mMaxDynamicShortcuts'"`
129+
130+
- `root`: `su -c "dumpsys shortcut | grep -E 'maxShortcutsPerActivity|mMaxDynamicShortcuts'`
131+
132+
To change the limit, check below.
133+
134+
**Till Next Reboot**
135+
136+
You can change the limit till next reboot with the [`cmd shortcut override-config`](https://cs.android.com/android/platform/superproject/+/android-13.0.0_r8:frameworks/base/services/core/java/com/android/server/pm/ShortcutService.java;l=4943) command from an [`adb`] or [`root`] shell. For example to increase the limit to `25`, run:
137+
138+
- `adb`: `adb shell "cmd shortcut override-config max_shortcuts=25"`
139+
140+
- `root`: `su -c "cmd shortcut override-config max_shortcuts=25"`
141+
142+
To reset to default, run `cmd shortcut override-config max_shortcuts=`
143+
144+
**Permanently**
145+
146+
You can change the limit permanently with the [`settings put global`](https://cs.android.com/android/platform/superproject/+/android-12.0.0_r34:frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/SettingsService.java;l=465) command from an [`adb`] or [`root`] shell.
147+
148+
The `max_shortcuts` sub key is stored in `settings` `global` namespace under a single `shortcut_manager_constants` key as a comma separated list of `key=value` pairs. You can check the current/default values set with:
149+
150+
- `adb`: `adb shell "settings get global shortcut_manager_constants"`
151+
152+
- `root`: `su -c "settings get global shortcut_manager_constants"`
153+
154+
Now, since this is single key storing all the other sub keys, you can't just run `settings put` command to set a sub key value if the key value is already set, since it will overwrite all the existing values.
155+
156+
You should first get the default/current, then update or append `,max_shortcuts=25` to it and then put the joint value back with `settings get global shortcut_manager_constants '<joint_value>'`.
157+
158+
If the `shortcut_manager_constants` value is not set (by default it should be unset), then to increase the limit to `25` run:
159+
160+
- `adb`: `adb shell "settings put global shortcut_manager_constants 'max_shortcuts=25'"`
161+
162+
- `root`: `su -c "settings put global shortcut_manager_constants 'max_shortcuts=25'"`
163+
164+
To reset to default if no other sub keys set, run `settings delete global shortcut_manager_constants`
165+
166+
167+
#### Draw Over Apps permission (Optional)
113168

114169
For android `>= 10` there are new [restrictions](https://developer.android.com/guide/components/activities/background-starts) that prevent activities from starting from the background. This prevents the background `TermuxService` from starting a terminal session in the foreground and running the commands until the user manually clicks `Termux` notification in the status bar dropdown notifications list. This only affects plugin commands that are to be executed in a terminal session and not the background ones. `Termux` version `>= 0.100` requests the `Draw Over Apps` permission so that users can bypass this restriction so that commands can automatically start running without user intervention. You can grant `Termux` the `Draw Over Apps` permission from its `App Info` activity `Android Settings` -> `Apps` -> `Termux` -> `Advanced` -> `Draw over other apps`.
115170
##
@@ -174,9 +229,11 @@ Check [Forking](https://github.com/termux/termux-app#Forking) section of `termux
174229

175230

176231

232+
[`adb`]: https://developer.android.com/studio/command-line/adb
177233
[Termux]: https://termux.com
178234
[QuickEdit]: https://play.google.com/store/apps/details?id=com.rhmsoft.edit
179235
[QuickEdit Pro]: https://play.google.com/store/apps/details?id=com.rhmsoft.edit.pro
180236
[Acode editor]: https://github.com/deadlyjack/code-editor
181237
[Turbo Editor]: https://github.com/vmihalachi/turbo-editor
238+
[`root`]: https://topjohnwu.github.io/Magisk/tools.html#su
182239
[RUN_COMMAND Intent]: https://github.com/termux/termux-app/blob/master/app/src/main/java/com/termux/app/RunCommandService.java

0 commit comments

Comments
 (0)