Skip to content

Add dynamic shortcuts#80

Merged
agnostic-apollo merged 12 commits intotermux:masterfrom
fabian-thomas:master
Oct 30, 2022
Merged

Add dynamic shortcuts#80
agnostic-apollo merged 12 commits intotermux:masterfrom
fabian-thomas:master

Conversation

@fabian-thomas
Copy link
Contributor

@fabian-thomas fabian-thomas commented May 15, 2022

Closes #44
Closes termux/termux-app#1730

Current implementation:
Two new buttons in widget main view.

  • Create button: adds all shortcuts as dynamic shortcuts. Those can then be used in minimalistic launchers. (Icons supported as well)
  • Clear button: clears all shortcuts.

AOSP Android forces a limit of 10 shortcuts per app. One can change this limit with root permissions:
su -c 'settings put global shortcut_manager_constants max_shortcuts=1000'

Todo:

  • refactor/modularize code
  • add user feedback/logging
  • try to hide app name that gets displayed in front of shortcut name: probably not possible
  • add mention in readme (also on how to increase limit)
  • move those dynamic shortcuts to different folder than normal shortcuts (~/.shortcuts)
  • move FileFilter SHORTCUT_FILES_FILTER to enumerateShortcutFiles?

@fabian-thomas fabian-thomas changed the title Add dynamic shortcuts Draft: Add dynamic shortcuts May 16, 2022
@fabian-thomas fabian-thomas marked this pull request as draft May 16, 2022 09:09
@fabian-thomas fabian-thomas changed the title Draft: Add dynamic shortcuts Add dynamic shortcuts May 16, 2022
@fabian-thomas fabian-thomas marked this pull request as ready for review May 19, 2022 22:51
@fabian-thomas
Copy link
Contributor Author

This PR is basically ready from my side. The last two points in the TODO above still need to be discussed.

@xalexalex
Copy link

This had been on my wishlist for years. Thanks!
Tested: works and looks good to me.
However I'd rather have someone more knowledgeable take a look at this before merging.

A few things:

  1. I'm not an expert at java, but the code that shortens the shortcuts array when its size is > maximumShortcuts is a bit opaque. Assuming there isn't a way to directly slice an array in java, perhaps one could do something like
while (shortcuts.size() > maximumShortcuts)
    shortcuts.remove(shortcuts.size()-1)

which is theoretically slower than the for loop because shortcuts.size() is called shortcuts.size() - maximumShortcuts times instead of once, but I don't think anyone's ever going to have so many shortcuts as to make this difference relevant.

  1. I see you use static/dynamic/pinned shortcuts but there's no mention in the readme regarding this.

@fabian-thomas
Copy link
Contributor Author

  1. Your code is much more readable and mine is actually wrong 😅. I will apply that change. To understand why it's wrong you need to know that the break condition in the for loop is actually evaluated in each iteration of the loop. But even if the condition would only be executed once in for loops vs. multiple times in while loops we would have no real performance difference since ArrayList.size() is O(1). Take a look at the openjdk implementation of ArrayList.
  2. The pinned and static shortcuts are those that have been used for a while now on the home screen. I only added the dynamic ones. I would say we do not need a remark on them in the readme since they are somewhat "normal" for android.

@agnostic-apollo
Copy link
Member

Thanks for the pull request. Good work. I have made refactored the code to fix some issues and add improvements. It seems to be working fine on Android 11, and without it on Android 7.0. Nice idea on ShortcutFile and ShortcutUtils extraction, about time for that.

I have also changed the dynamic shortcuts directory to ~/.termux/widget/dynamic_shortcuts since shouldn't just add all shortcuts in shortcuts directory as dynamic and shortcuts default directory will be moved to under ~/.termux/widget in future from ~/.shortcuts, so should move for this now.

Also in future, please remove unused imports when you move around code before committing, had to spent time figuring out which import got removed when and fixing the commits. Also use same case for commit messages as being used in repo.

I will merge this soon since need these changes for other work.

@fabian-thomas
Copy link
Contributor Author

Nice, thanks for your work. 👍🏼
Glad to see this finally coming to master.

fabian-thomas and others added 12 commits October 30, 2022 13:03
Co-authored-by: Fabian Thomas <fabian@fabianthomas.de>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
…le enumeration to `ShortcutUtils`

Co-authored-by: Fabian Thomas <fabian@fabianthomas.de>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
…ctions to `ShortcutFile` and change shortcut path behaviour

The `ShortcutFile` will now store the path instead of the file object

This commit will also now pass absolute path of shortcuts when creating intents for shortcuts and widgets instead of canonical path. This will allow path expansion to be done during execution instead of at creation and if underlying symlink destination changes, new destination will be executed. There will still be a security check during execution to check if shortcut is under allowed directories. The shortcut label will now also be generated from absolute path instead of canonical path as mentioned in termux#59

Co-authored-by: Fabian Thomas <fabian@fabianthomas.de>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
Co-authored-by: agnostic-apollo <agnosticapollo@gmail.com>
Co-authored-by: Fabian Thomas <fabian@fabianthomas.de>
…`Flow.Publisher` used in `TermuxWidgetControlsProviderService`
…it existed in recent apps stack and a shortcut was run from launcher
…and passing `0` in `ACTION_REFRESH_WIDGET` broadcast

This also allows a way to fix occasional non-responsive widgets after app updates if `ACTION_APPWIDGET_UPDATE` was not sent/received by Termux:Widget app.

This commit also adds logging to widget callbacks for debugging issues.
@agnostic-apollo
Copy link
Member

You are welcome. Any issues that occur can be fixed in master.

@ipcjs
Copy link

ipcjs commented Dec 31, 2022

When will a new version be released that includes the feature?

@marbetschar
Copy link

Sorry for the necro bump - but I do have the same question: How/Where can we obtain a new version providing the dynamic_shortcuts feature?

@agnostic-apollo
Copy link
Member

You can use github action builds for now, github/fdroid release will be done in a few days.

https://github.com/termux/termux-widget?tab=readme-ov-file#github

@marbetschar
Copy link

The build artifact is not installable on my device - it claims that the *.apk was built for a too old Android version. Waiting for the F-Droid release then.

FWIW: I get the same error (too old Android version) for Termux:Boot from F-Droid. Hoping its different for this then 🤞

@sylirre
Copy link
Member

sylirre commented Sep 3, 2024

was built for a too old Android version

Termux has to target old SDK, otherwise it would be same as any other terminal apps without packages. Newer target SDK enables stricter SELinux with withdraws ability to run executables on internal storage, which means no packages and user programs can be executed.

You can dismiss dialog from Google Play Protect: tap on More details --> Install anyway

Screenshot_20240903-104434_Google_Play_Store_1

@marbetschar
Copy link

Thanks for the hint. Turned out I enabled the screen password on my Onyx Boox Note Air - which was interferring with the Install anyway and caused it to always fail.

Bioharzard

This comment was marked as spam.

@DHANAVATHgANESH

This comment was marked as spam.

@DHANAVATHgANESH

This comment was marked as spam.

@twaik
Copy link
Member

twaik commented Nov 26, 2024

And you decided to report it in a random PR of different plugin (unrelated to termux-boot) repo in the same organisation, right?

@termux termux deleted a comment from DHANAVATHgANESH Nov 26, 2024
@termux termux deleted a comment from DHANAVATHgANESH Nov 26, 2024
@termux termux locked as resolved and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands as app shortcut? support for minimalist launchers

9 participants