Skip to content

Commit

Permalink
Add another constructor for ax audit
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sauce committed Jan 14, 2025
1 parent 730b071 commit c06859e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
25 changes: 22 additions & 3 deletions ios/accessibility/accessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,31 @@ import (

const serviceName string = "com.apple.accessibility.axAuditDaemon.remoteserver"

// New creates and connects to the given device, a new ControlInterface instance
func New(device ios.DeviceEntry) (ControlInterface, error) {
// NewWithoutEventChangeListeners creates and connects to the given device, a new ControlInterface instance,
// no accessibility events changes will be tracked.
func NewWithoutEventChangeListeners(device ios.DeviceEntry) (ControlInterface, error) {
conn, err := dtx.NewUsbmuxdConnection(device, serviceName)
if err != nil {
return ControlInterface{}, err
}
control := ControlInterface{conn.GlobalChannel()}
return control, err

return control, nil
}

// NewWithEventChangeListeners creates and connects to the given device, a new ControlInterface instance with
// a setup of listeners to track accessibility events changes
func NewWithEventChangeListeners(device ios.DeviceEntry) (ControlInterface, error) {
conn, err := dtx.NewUsbmuxdConnection(device, serviceName)
if err != nil {
return ControlInterface{}, err
}
control := ControlInterface{conn.GlobalChannel()}

err = control.init()
if err != nil {
return ControlInterface{}, err
}

return control, nil
}
3 changes: 1 addition & 2 deletions ios/accessibility/accessibility_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func (a ControlInterface) readhostInspectorNotificationReceived() {
}
}

// Init wires up event receivers and gets Info from the device
func (a ControlInterface) Init() error {
func (a ControlInterface) init() error {
a.channel.RegisterMethodForRemote("hostInspectorCurrentElementChanged:")
a.channel.RegisterMethodForRemote("hostInspectorMonitoredEventTypeChanged:")
a.channel.RegisterMethodForRemote("hostAppStateChanged:")
Expand Down
7 changes: 2 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,12 +1778,9 @@ func timeFormat(device ios.DeviceEntry, operation string, force bool) {

func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
go func() {
conn, err := accessibility.New(device)
conn, err := accessibility.NewWithEventChangeListeners(device)
exitIfError("failed creating ax service", err)

err = conn.Init()
exitIfError("failed init ax", err)

conn.SwitchToDevice()

conn.EnableSelectionMode()
Expand Down Expand Up @@ -1811,7 +1808,7 @@ func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
}

func resetAx(device ios.DeviceEntry) {
conn, err := accessibility.New(device)
conn, err := accessibility.NewWithoutEventChangeListeners(device)
exitIfError("failed creating ax service", err)

err = conn.ResetToDefaultAccessibilitySettings()
Expand Down

0 comments on commit c06859e

Please sign in to comment.