Enable VPN when app is open, but only disable VPN when the app is force quit, not just closed

Basically I have a Jellyfish (Plex equivalent) that I need a VPN to access. I use it to listen to music so I want to have the VPN to remain on even if I switch apps/go back to the home screen. This makes the app opened/closed automation irrelevant.

Any clue on how to achieve this?

The disconnect part is not possible

I just simply created an On/Off shortcut for this to connect to my home with VPN.

Enable it → watch move/tv show → disable it if not needed anymore.

If your concern is forgetting to turn off VPN after some time, you could use an app like Actions, which comes with a shortcut action “Is VPN on?,” together with a few scheduled automations that check if you’re connected, and if “yes,” go ahead and disconnect.

I can only get my VPN on/off shortcuts to work with TunnelBear for a time or two, after that they just don’t do anything.

I thought so but just wanted to make sure. Guess I’ll just have to stick with a toggle shortcut on my home screen. Thanks !

I have a quick settings shortcut from where I can toggle the VPN quickly, but I always forget to disable it… That’s why I wanted to automate, but not possible apparently. Thanks !

That could be a solution, but if I’m using the app during the automation it might cut the audio off. And running it at night is not much use as I turn off my phone at night. I use Toolbox Pro already and wanted to use the « is media playing » action to counter this, but it is a premium tool.

Could you please share this?

It seems to be working for me right now with Tailscale. It’s not always instantaneous but honestly still way more convenient than activating it manually.

Actually I’ve just thought about this again:
The app actions does have an action called „is audio playing“.
You could check against that (on app closure through automations) and if it returns true, you won’t do anything, but if it returns false, you cut the vpn.

Haven’t tested this yet, but in theory this could work.

Yes, it happens to me also to forget to disconnect the VPN, but if you have set split tunnel you shouldn’t be worried about consuming mobile data. Maybe just the battery life would be affected.

Gotcha. Well, Actions is free and it too has an “is audio playing?” action. Just sayin’

Edit: No disrespect to TBP, which is also awesome. I have it and Actions installed.

Yes this works! I tried to do exactly that but the same action in TBP was paid. I did not know about Actions. Thanks a lot!

This works very well! My 13 mini sometimes skips the automation but I just have to wait a bit. For some reason I thought Actions would be paid too! Thanks

Can you tell me the steps for your shortcut I’m currently trying to do this same exact thing?

I have since decided to keep the VPN on at all times. However, when I had it set up, it was a very simple shortcut. You need to install the Actions app, and then create 2 automations.

  • If Media Playing is yes, do nothing. If no, connect to VPN (run when opening your app).

  • If Media Playing is yes, do nothing. If no, disconnect from VPN (run when closing the app).

Make sure you have VPN on demand enabled in both the app settings and VPN configurations in Settings. It might not work as intended otherwise.