diff --git a/wap/cmd/main.go b/wap/cmd/main.go index 4f1bb71..9a0ecf0 100644 --- a/wap/cmd/main.go +++ b/wap/cmd/main.go @@ -229,8 +229,9 @@ func handleAppState(ctx context.Context, isConnected bool, stopServer chan struc // Execute the disconnect in the background disconnectWifiResponse := wifi.DisconnectNamedWifi(ctx, req) log.Infow("Disconnect Wifi with response", "res", disconnectWifiResponse) - - stopServer <- struct{}{} // stop the HTTP server + if wifi.CheckIfIsConnectedWifi(ctx, "") == nil { + stopServer <- struct{}{} // stop the HTTP server + } } else { log.Info("No config file found, activating the hotspot mode.") if !isHotspotStarted { diff --git a/wap/pkg/wifi/wifi.go b/wap/pkg/wifi/wifi.go index 4c7f2fd..1b39526 100644 --- a/wap/pkg/wifi/wifi.go +++ b/wap/pkg/wifi/wifi.go @@ -68,7 +68,7 @@ type Credentials struct { func CheckIfIsConnected(ctx context.Context, interfaceName string) error { switch runtime.GOOS { case "linux": - err := checkIfIsConnectedLinux(ctx, interfaceName) + err := CheckIfIsConnectedWifi(ctx, interfaceName) if err != nil { // If not connected via WiFi, try to ping a well-known website pingCmd := exec.CommandContext(ctx, "ping", "-c", "1", "-W", "5", "google.com") @@ -83,6 +83,15 @@ func CheckIfIsConnected(ctx context.Context, interfaceName string) error { } } +func CheckIfIsConnectedWifi(ctx context.Context, interfaceName string) error { + switch runtime.GOOS { + case "linux": + return checkIfIsConnectedLinux(ctx, interfaceName) + default: + return fmt.Errorf("unsupported platform") + } +} + func ConnectWifi(ctx context.Context, creds Credentials) error { switch runtime.GOOS { case "linux":