Class: WifiWand::Platforms::Mac::Helper::Client

Inherits:
Object
  • Object
show all
Includes:
StringPredicates, Timing
Defined in:
lib/wifi_wand/platforms/mac/helper/client.rb

Overview

Talks to the compiled macOS helper app used for permission-sensitive read/query operations such as current-network lookups and network scans. Connect/disconnect mutations still run through SwiftRuntime.

Constant Summary collapse

HELPER_READ_BOUNDARY_ERROR =

StandardError excludes process-control and VM-level exceptions like Interrupt, SystemExit, and NoMemoryError.

StandardError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Timing

monotonic_now, status_deadline, status_timeout_for

Methods included from StringPredicates

string_nil_or_blank?, string_nil_or_empty?

Constructor Details

#initialize(out_stream_provider:, verbosity_provider:, macos_version_reader:, err_stream_provider: nil, timeout_configuration: Bundle.default_timeout_configuration) ⇒ Client

Returns a new instance of Client.



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 99

def initialize(out_stream_provider:, verbosity_provider:, macos_version_reader:,
  err_stream_provider: nil, timeout_configuration: Bundle.default_timeout_configuration)
  @out_stream_provider = out_stream_provider
  @err_stream_provider = err_stream_provider
  @verbosity_provider = verbosity_provider
  @macos_version_reader = macos_version_reader
  @timeout_configuration = timeout_configuration
  @location_warning_emitted = false
  @helper_install_verified = false
  @disabled = false
  @last_error_message = nil
  @last_error_status = nil
end

Instance Attribute Details

#last_error_messageObject (readonly)

Returns the value of attribute last_error_message.



94
95
96
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 94

def last_error_message
  @last_error_message
end

Instance Method Details

#available?(timeout_seconds: nil) ⇒ Boolean

Returns:

  • (Boolean)


148
149
150
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 148

def available?(timeout_seconds: nil)
  helper_availability_status(timeout_seconds: timeout_seconds) == :available
end

#connected_network_bssid(timeout_seconds: nil) ⇒ Object



125
126
127
128
129
130
131
132
133
134
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 125

def connected_network_bssid(timeout_seconds: nil)
  result = execute('current-network', timeout_seconds: timeout_seconds)
  bssid = result.payload.fetch('bssid', nil) if result.payload.is_a?(Hash)
  Bundle::HelperQueryResult.new(
    payload:                   bssid,
    location_services_blocked: result.location_services_blocked,
    error_message:             result.error_message,
    status:                    connected_network_bssid_status(result)
  )
end

#connected_network_name(timeout_seconds: nil) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 113

def connected_network_name(timeout_seconds: nil)
  result = execute('current-network', timeout_seconds: timeout_seconds)
  ssid = result.payload.fetch('ssid', nil) if result.payload.is_a?(Hash)
  Bundle::HelperQueryResult.new(
    payload:                   ssid,
    location_services_blocked: result.location_services_blocked,
    error_message:             result.error_message,
    signal_quality:            signal_quality_from_payload(result.payload),
    status:                    connected_network_status(result)
  )
end

#location_services_blocked?Boolean

Returns:

  • (Boolean)


168
169
170
171
172
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 168

def location_services_blocked?
  return false unless @last_error_status

  Bundle::LOCATION_SERVICES_BLOCKING_STATUSES.include?(@last_error_status)
end

#scan_networksObject



136
137
138
139
140
141
142
143
144
145
146
# File 'lib/wifi_wand/platforms/mac/helper/client.rb', line 136

def scan_networks
  result = execute('scan-networks')
  payload = result.payload if result.payload.is_a?(Hash)
  networks = payload&.fetch('networks', []) || []
  Bundle::HelperQueryResult.new(
    payload:                   networks,
    location_services_blocked: result.location_services_blocked,
    error_message:             result.error_message,
    status:                    scan_network_status(result)
  )
end