Class: WifiWand::Platforms::Mac::Helper::Setup

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

Defined Under Namespace

Classes: Result

Constant Summary collapse

SupportStatus =
Bundle::HelperSupportStatus

Instance Method Summary collapse

Constructor Details

#initialize(out_stream: $stdout, macos_version_reader: nil) ⇒ Setup

Returns a new instance of Setup.



67
68
69
70
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 67

def initialize(out_stream: $stdout, macos_version_reader: nil)
  @out_stream = out_stream
  @macos_version_reader = macos_version_reader || -> { Bundle.detect_macos_version }
end

Instance Method Details

#check_statusResult

Inspect the current installation and return a Result value object.

Returns:



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 80

def check_status
  support_status = helper_support_status
  return unsupported_result(support_status) if support_status.unsupported?

  helper_path = Bundle.installed_executable_path
  installed   = File.executable?(helper_path)
  valid       = installed && Bundle.helper_installed_and_valid?
  authorized, permission_message = check_authorization(helper_path, valid)

  Result.new(
    installed:          installed,
    valid:              valid,
    authorized:         authorized,
    permission_message: permission_message,
    helper_applicable:  true,
    macos_version:      support_status.macos_version
  )
end

#helper_support_statusObject



72
73
74
75
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 72

def helper_support_status
  macos_version = @macos_version_reader&.call
  Bundle.helper_support_status_for_macos_version(macos_version)
end

#install_helperObject

Install the helper for the first time (or skip if already valid). Delegates to Bundle.ensure_helper_installed so that the standard validation + concurrent-install safeguards are honoured.

Raises:

  • (RuntimeError)

    if installation fails validation



104
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 104

def install_helper = Bundle.ensure_helper_installed(out_stream: @out_stream)

#open_location_settingsObject

Open the macOS System Settings pane for Location Services so the user can grant permission to wifiwand-helper.



136
137
138
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 136

def open_location_settings
  system('open', 'x-apple.systempreferences:com.apple.preference.security?Privacy_LocationServices')
end

#reinstall_helperString

Force-replace the installed bundle regardless of current validity, then re-validate. Use this for the --reinstall path where the user knows the existing install is stale or macOS TCC has lost track of it.

Returns:

  • (String)

    installed bundle path on success

Raises:

  • (RuntimeError)

    if reinstallation fails validation



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

def reinstall_helper
  Bundle.install_helper_bundle(out_stream: @out_stream, force: true)

  unless Bundle.helper_installed_and_valid?
    raise 'Helper reinstallation failed validation. ' \
      'Try running wifiwand-macos-setup again.'
  end

  Bundle.installed_bundle_path
end

#remove_helperString

Remove the helper application files installed for the current WifiWand version. This intentionally does not try to mutate macOS TCC permission records; users can revoke Location Services access in System Settings.

Returns:

  • (String)

    removed installation directory path



128
129
130
131
132
# File 'lib/wifi_wand/platforms/mac/helper/setup.rb', line 128

def remove_helper
  install_dir = Bundle.versioned_install_dir
  FileUtils.rm_rf(install_dir)
  install_dir
end