Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dynamic Shortcuts integration #48

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

gergely-sallai
Copy link

Added support for Android Dynamic Shortcuts. Dynamic Shortcuts is a standard Android feature that is supported by most of the launchers.

How does this work for users?

Now users can request the app to add shortcuts to their favourite tunnels. When the user enables this for a specific tunnel, 2 dynamic shortcuts are created, one to UP the tunnel, other is to DOWN it.

Additionally this functionality enables users to use certain automation apps to automatically toggle tunnels. For example the built-in Bixby Routines on Samsung devices. (This was my original motivation for adding this feature, but I was trying to incorporate it in a way that could benefit all users.)

What changes were made to previous components to support this?

  1. TunnelToggleActivity is now more broadly used. Previously it seemed to be only called from TileService in certain situations.
  2. A new button has been added next to the tunnel toggle switch for each tunnel item.
  3. Added androidx shortcuts library

Limitations and possible points for future improvement

To my best knowledge all of these -- expect the first point -- were there previous to my PR, and I can help to sort these out if needed.

  1. Tooltip popup for the "add shortcuts" button is only available for devices running API 26 and up. This could be solved generally via TooltipCompat, but I didn't want to complicate the code because of this. As doing this with the compat lib can not be done purely from XML..
  2. TunnelToggleActivity can be shown briefly when a tunnel is toggled, and it can look weird. This could possibly be solved by adding some design to the activity and showing it a bit longer in a controlled manner, maybe with some animation.
  3. There may be some misconfigurations around material colors, it caused me some rendering differences on certain OS version with the button colors. I believe this could be solved with a refactor to support Material You (M3) and its dynamic colors, and fall back to a default on older versions. I do not know what is the intended design language of the app, so I didn't dare to refactor it just yet. :)

- `tunnel_list_item` got a new checkbox to toggle shortcut display for specific tunnel
- `ObservableTunnel` got updated to support querying and setting shortcuts. Responsibility delegated to `TunnelManager`
- `TunnelManager` got updated to handle shortcuts when a tunnel changes. Actual shortcut logic will be handled by `ShortcutManager`
- Added skeleton for `ShortcutManager`
- `strings.xml` updated with tooltip text for the shortcut checkbox. This tooltip only works for API 26+
- `ShortcutManager` now able to add 2 kinds of dynamic shortcuts for a specific tunnel (tunnel up and tunnel down).
- Modified `TunnelToggleActivity` so that it can be called from the shortcuts. Instead of only being able to toggle last used tunnel, now it can be instructed to 'up' or 'down' any specified tunnel.
Previously it was API 24+, because TileService is only available there. But now `TunnelToggleActivity` can also be used from shortcuts, meaning we need it to work on older APIs too.
Also, `colorOnPrimary` was "white" on my physical device (Samsung S21 API 31) and blended into the background, but looked fine in emulator (API29). I did not investigate further.
The above should look the same as the ToggleSwitch next to it.

As far as I could test this will look "secondary blue" on older devices, and adhere to Material You dynamic colors on newer devices.
@swiffer
Copy link

swiffer commented Sep 5, 2022

Would be great to see this merged / released.

Looking for a solution to auto-toggle via Samsung Bixby Routines as soon as I leave my Home-WiFi.

@gergely-sallai
Copy link
Author

Just to be completely transparent regarding this feature.
I've been actively using it with Bixby Routines for the exact same use-case as you want since I've pushed the changes.
The feature works nicely, no problems there.

However the idea of using the shortcut as a way to toggle automatically with Bixby Routines does have its drawbacks.
Namely it only works flawlessly if the phone is unlocked/awake. This is due to the fact that it's using an Android Activity to do the actual toggling, which does not work with a locked phone. Don't know how this could be better solved.

In my eyes this is a Bixby limitation. Bixby Routines should enable toggling of custom VPN tunnels or let us use custom broadcast messages (to toggle the tunnel in this case). Nevertheless I still use it and it's better than always having to do this manually..

@swiffer
Copy link

swiffer commented Sep 9, 2022

Thanks for the updated Info - without going to much offtopic: do you know If Bixby Routines gained functionality with OneUI 5 so toggling VPNs defined via 3rd Party Apps Work Out of the Box?

@gergely-sallai
Copy link
Author

Don't know yet, haven't checked.

@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@WireGuard WireGuard deleted a comment from cliuff Dec 6, 2022
@WireGuard WireGuard deleted a comment from zzb-zzb Dec 6, 2022
@alexsahka
Copy link

Added support for Android Dynamic Shortcuts. Dynamic Shortcuts is a standard Android feature that is supported by most of the launchers.

How does this work for users?

Now users can request the app to add shortcuts to their favourite tunnels. When the user enables this for a specific tunnel, 2 dynamic shortcuts are created, one to UP the tunnel, other is to DOWN it.

Additionally this functionality enables users to use certain automation apps to automatically toggle tunnels. For example the built-in Bixby Routines on Samsung devices. (This was my original motivation for adding this feature, but I was trying to incorporate it in a way that could benefit all users.)

What changes were made to previous components to support this?

  1. TunnelToggleActivity is now more broadly used. Previously it seemed to be only called from TileService in certain situations.
  2. A new button has been added next to the tunnel toggle switch for each tunnel item.
  3. Added androidx shortcuts library

Limitations and possible points for future improvement

To my best knowledge all of these -- expect the first point -- were there previous to my PR, and I can help to sort these out if needed.

  1. Tooltip popup for the "add shortcuts" button is only available for devices running API 26 and up. This could be solved generally via TooltipCompat, but I didn't want to complicate the code because of this. As doing this with the compat lib can not be done purely from XML..
  2. TunnelToggleActivity can be shown briefly when a tunnel is toggled, and it can look weird. This could possibly be solved by adding some design to the activity and showing it a bit longer in a controlled manner, maybe with some animation.
  3. There may be some misconfigurations around material colors, it caused me some rendering differences on certain OS version with the button colors. I believe this could be solved with a refactor to support Material You (M3) and its dynamic colors, and fall back to a default on older versions. I do not know what is the intended design language of the app, so I didn't dare to refactor it just yet. :)

Please, is it possible to post the compiled android app with Dynamic Shortcuts? Thank you!

@nschwing
Copy link

@alexsahka https://github.com/nschwing/wireguard-android/releases/tag/ui-signed

Thanks gergely-sallai!

@zx2c4-bot zx2c4-bot force-pushed the master branch 4 times, most recently from 581ab92 to ec126a9 Compare March 28, 2023 14:04
@zx2c4-bot zx2c4-bot force-pushed the master branch 3 times, most recently from 5692307 to ee16d13 Compare March 28, 2023 16:32
@nibytes
Copy link

nibytes commented Apr 2, 2023

Could it merged / released? Very useful feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants