Class: WifiWand::Platforms::Mac::Helper::WifiTransport
- Inherits:
-
Object
- Object
- WifiWand::Platforms::Mac::Helper::WifiTransport
- Includes:
- StringPredicates
- Defined in:
- lib/wifi_wand/platforms/mac/helper/wifi_transport.rb
Overview
Orchestrates the direct Swift-source runtime path for macOS connect/disconnect mutations. Query/read operations that need a stable app identity stay on the compiled helper path via Client.
Constant Summary collapse
- CONNECTION_FAILURE_PATTERNS =
[ /Failed to join network/i, /Error:\s*-3900/, /Could not connect/i, /Could not find network/i, ].freeze
- AUTHENTICATION_FAILURE_PATTERNS =
[ /invalid password/i, /incorrect password/i, /password.*incorrect/i, /authentication (?:failed|timeout|timed out)/i, /802\.1x authentication failed/i, /password required/i, ].freeze
- SWIFT_CONNECTION_FAILURE_PATTERNS =
[ /connection timeout/i, /connection attempt timed out/i, /out of range/i, /unreachable/i, ].freeze
- FAILURE_REASON_HEADER_PATTERNS =
[ /Failed to join network/i, /\AError:\s*Failed to join\b/i, ].freeze
- SUDO_IFCONFIG_TIMEOUT_SECONDS =
5- UNEXPECTED_SWIFT_ERROR =
StandardError excludes process-control and VM-level exceptions like Interrupt, SystemExit, and NoMemoryError.
StandardError
Instance Method Summary collapse
- #connect(network_name, password = nil) ⇒ Object
- #disconnect ⇒ Object
-
#initialize(swift_runtime:, command_runner:, wifi_interface_provider:, out_stream_provider:, err_stream_provider:, verbosity_provider:) ⇒ WifiTransport
constructor
A new instance of WifiTransport.
Methods included from StringPredicates
string_nil_or_blank?, string_nil_or_empty?
Constructor Details
#initialize(swift_runtime:, command_runner:, wifi_interface_provider:, out_stream_provider:, err_stream_provider:, verbosity_provider:) ⇒ WifiTransport
Returns a new instance of WifiTransport.
49 50 51 52 53 54 55 56 57 |
# File 'lib/wifi_wand/platforms/mac/helper/wifi_transport.rb', line 49 def initialize(swift_runtime:, command_runner:, wifi_interface_provider:, out_stream_provider:, err_stream_provider:, verbosity_provider:) @swift_runtime = swift_runtime @command_runner = command_runner @wifi_interface_provider = wifi_interface_provider @out_stream_provider = out_stream_provider @err_stream_provider = err_stream_provider @verbosity_provider = verbosity_provider end |
Instance Method Details
#connect(network_name, password = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/wifi_wand/platforms/mac/helper/wifi_transport.rb', line 59 def connect(network_name, password = nil) if swift_runtime.swift_and_corewlan_present? begin swift_runtime.connect(network_name, password) return rescue WifiWand::CommandExecutor::OsCommandError => e handle_swift_connect_command_error(network_name, e) rescue WifiWand::CommandTimeoutError, WifiWand::CommandNotFoundError, WifiWand::CommandSpawnError => e log_fallback( "Swift/CoreWLAN failed: #{e.}. Trying networksetup fallback..." ) rescue UNEXPECTED_SWIFT_ERROR => e log_unexpected_swift_error('connect', e) raise end end connect_using_networksetup(network_name, password) end |
#disconnect ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wifi_wand/platforms/mac/helper/wifi_transport.rb', line 80 def disconnect if swift_runtime.swift_and_corewlan_present? begin swift_runtime.disconnect return rescue WifiWand::CommandExecutor::OsCommandError, WifiWand::CommandTimeoutError, WifiWand::CommandNotFoundError, WifiWand::CommandSpawnError => e log_fallback( "Swift/CoreWLAN disconnect failed: #{e.}. Falling back to ifconfig..." ) rescue UNEXPECTED_SWIFT_ERROR => e log_unexpected_swift_error('disconnect', e) raise end elsif verbose? err_stream.puts 'Swift/CoreWLAN not available. Using ifconfig...' end disconnect_using_ifconfig end |