From 67a68be2290b3af6e7d2897e52b3cd19d1f4450d Mon Sep 17 00:00:00 2001 From: Ruben Pollan Date: Fri, 26 Mar 2021 15:48:58 +0100 Subject: Location selection more responsive --- pkg/backend/api.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'pkg/backend/api.go') diff --git a/pkg/backend/api.go b/pkg/backend/api.go index f1fed57..d43751b 100644 --- a/pkg/backend/api.go +++ b/pkg/backend/api.go @@ -55,10 +55,31 @@ func SwitchOff() { go stopVPN() } -// TODO implement Reconnect - do not tear whole fw down in between - func UseLocation(label string) { + if ctx.ManualLocation && label == ctx.CurrentLocation { + return + } + ctx.bm.UseGateway(label) + go trigger(OnStatusChanged) + if label != ctx.CurrentLocation { + reconnect() + } +} + +func UseAutomaticGateway() { + if !ctx.ManualLocation { + return + } + + ctx.bm.UseAutomaticGateway() + go trigger(OnStatusChanged) + reconnect() +} + +// TODO implement Reconnect - do not tear whole fw down in between + +func reconnect() { time.Sleep(200 * time.Millisecond) SwitchOff() time.Sleep(500 * time.Millisecond) -- cgit v1.2.3