Class: WifiWand::Platforms::Mac::Helper::SwiftRuntime

Inherits:
Object
  • Object
show all
Defined in:
lib/wifi_wand/platforms/mac/helper/swift_runtime.rb

Overview

Runs the direct Swift-source runtime path used for macOS connect/disconnect operations. Read/query operations that need a stable app identity flow through Client and the compiled helper app instead.

Constant Summary collapse

SWIFT_CONNECT_FALLBACK_PATTERNS =
[
  /code:\s*-3900/i,
  /code:\s*-3905/i,
  /corewlan generic error/i,
  /possible keychain access or authentication issue/i,
  /network not found/i,
  /tmpErr\s*\(code:\s*82\)/i,
  /couldn(?:\?\?\?|['’])t be completed.*tmpErr/i,
].freeze
UNEXPECTED_SWIFT_PROBE_ERROR =

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

StandardError

Instance Method Summary collapse

Constructor Details

#initialize(command_runner:, out_stream_provider:, err_stream_provider:, verbosity_provider:) ⇒ SwiftRuntime

Returns a new instance of SwiftRuntime.



25
26
27
28
29
30
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 25

def initialize(command_runner:, out_stream_provider:, err_stream_provider:, verbosity_provider:)
  @command_runner = command_runner
  @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



69
70
71
72
73
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 69

def connect(network_name, password = nil)
  args = [network_name]
  args << password if password
  run_swift_command('WifiNetworkConnector', *args)
end

#disconnectObject



75
76
77
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 75

def disconnect
  run_swift_command('WifiNetworkDisconnector')
end

#fallback_connect_error?(error_text) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 79

def fallback_connect_error?(error_text)
  SWIFT_CONNECT_FALLBACK_PATTERNS.any? { |pattern| pattern.match?(error_text.to_s) }
end

#run_swift_command(basename, *args) ⇒ Object



65
66
67
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 65

def run_swift_command(basename, *args)
  run_command(['swift', swift_filespec_for(basename)] + args)
end

#swift_and_corewlan_present?(timeout_in_secs: nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/wifi_wand/platforms/mac/helper/swift_runtime.rb', line 32

def swift_and_corewlan_present?(timeout_in_secs: nil)
  return @swift_and_corewlan_present if defined?(@swift_and_corewlan_present)

  skip_memoize = false
  available = begin
    result = run_command(
      ['swift', '-e', 'import CoreWLAN'],
      **swift_probe_options(timeout_in_secs)
    )
    log_swift_probe_failure(result) if !result.success? && verbose?
    result.success?
  rescue WifiWand::CommandTimeoutError => e
    err_stream.puts "Swift/CoreWLAN check timed out: #{e.message}" if verbose?
    skip_memoize = true
    false
  rescue WifiWand::CommandSpawnError => e
    err_stream.puts "Swift/CoreWLAN check could not start: #{e.message}" if verbose?
    skip_memoize = true
    false
  rescue WifiWand::CommandNotFoundError
    log_swift_command_not_found if verbose?
    false
  rescue WifiWand::CommandExecutor::OsCommandError => e
    log_swift_probe_failure(e) if verbose?
    false
  rescue UNEXPECTED_SWIFT_PROBE_ERROR => e
    err_stream.puts "Unexpected error checking Swift/CoreWLAN: #{e.class}: #{e.message}" if verbose?
    raise
  end

  skip_memoize ? false : @swift_and_corewlan_present = available
end