Auto reconnect to last server used

Would it be possible to have it try reconnecting only when you connect to a network?
That’s how I’m trying to automate it now with Tasker. Because for me it only disconnects, when I walk to far from the WiFi AP.
With Tasker, I would have to use touch inputs to start connection. Unless I can do it with a shell command? Not familiar with these things.

I already have it set up to automatically connect to WiFi ADB whenever I connect to my network, so having the audio come over ADB (I think I saw you mention you might implement that in a different post), would be great for me.