Skip to content

Commit

Permalink
only stop http server if it is through wifi that is connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Jul 19, 2024
1 parent 6807a46 commit 5cd3867
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions wap/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 10 additions & 1 deletion wap/pkg/wifi/wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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":
Expand Down

0 comments on commit 5cd3867

Please sign in to comment.