Skip to content

Commit

Permalink
Update wifi.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan6sha committed Jul 19, 2024
1 parent 6764760 commit 6807a46
Showing 1 changed file with 10 additions and 1 deletion.
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,16 @@ type Credentials struct {
func CheckIfIsConnected(ctx context.Context, interfaceName string) error {
switch runtime.GOOS {
case "linux":
return checkIfIsConnectedLinux(ctx, interfaceName)
err := checkIfIsConnectedLinux(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")
if err := pingCmd.Run(); err != nil {
return fmt.Errorf("wifi not connected and unable to reach internet: %v", err)
}
log.Info("Not connected to WiFi, but can access internet via other means")
}
return nil
default:
return fmt.Errorf("unsupported platform")
}
Expand Down

0 comments on commit 6807a46

Please sign in to comment.