Skip to content

Commit

Permalink
Reset ax settings
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sauce committed Jan 14, 2025
1 parent f5b5d81 commit 9883cc2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
10 changes: 10 additions & 0 deletions ios/accessibility/accessibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ import (

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

// NewWithoutEventChangeListeners creates and connects to the given device, a new ControlInterface instance
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, nil
}

// New creates and connects to the given device, a new ControlInterface instance
func New(device ios.DeviceEntry) (ControlInterface, error) {
conn, err := dtx.NewUsbmuxdConnection(device, serviceName)
Expand Down
13 changes: 10 additions & 3 deletions ios/accessibility/accessibility_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func (a ControlInterface) readhostInspectorNotificationReceived() {
}
}

// Init wires up event receivers and gets Info from the device
func (a ControlInterface) init() error {
a.channel.RegisterMethodForRemote("hostInspectorCurrentElementChanged:")
a.channel.RegisterMethodForRemote("hostInspectorMonitoredEventTypeChanged:")
Expand Down Expand Up @@ -150,6 +149,14 @@ func (a ControlInterface) UpdateAccessibilitySetting(name string, val interface{
log.Info("Setting Updated", resp)
}

func (a ControlInterface) ResetToDefaultAccessibilitySettings() error {
err := a.channel.MethodCallAsync("deviceResetToDefaultAccessibilitySettings")
if err != nil {
return err
}
return nil
}

func (a ControlInterface) awaitHostInspectorCurrentElementChanged() map[string]interface{} {
msg := a.channel.ReceiveMethodCall("hostInspectorCurrentElementChanged:")
log.Info("received hostInspectorCurrentElementChanged")
Expand Down Expand Up @@ -194,15 +201,15 @@ func (a ControlInterface) deviceCapabilities() ([]string, error) {
if err != nil {
return nil, err
}
return convertToStringList(response.Payload), nil
return convertToStringList(response.Payload)
}

func (a ControlInterface) deviceAllAuditCaseIDs() ([]string, error) {
response, err := a.channel.MethodCall("deviceAllAuditCaseIDs")
if err != nil {
return nil, err
}
return convertToStringList(response.Payload), nil
return convertToStringList(response.Payload)
}

func (a ControlInterface) deviceAccessibilitySettings() (map[string]interface{}, error) {
Expand Down
9 changes: 7 additions & 2 deletions ios/accessibility/utils.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package accessibility

func convertToStringList(payload []interface{}) []string {
import "fmt"

func convertToStringList(payload []interface{}) ([]string, error) {
if len(payload) != 1 {
return nil, fmt.Errorf("invalid payload length %d", len(payload))
}
list := payload[0].([]interface{})
result := make([]string, len(list))
for i, v := range list {
result[i] = v.(string)
}
return result
return result, nil
}
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ Usage:
ios runxctest [--xctestrun-file-path=<xctestrunFilePath>] [--log-output=<file>] [options]
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--log-output=<file>] [--arg=<a>]... [--env=<e>]... [options]
ios ax [--font=<fontSize>] [options]
ios resetax [options]
ios debug [options] [--stop-at-entry] <app_path>
ios fsync (rm [--r] | tree | mkdir) --path=<targetPath>
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath>
Expand Down Expand Up @@ -238,6 +239,7 @@ The commands work as following:
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--log-output=<file>] [--arg=<a>]... [--env=<e>]...[options] runs WebDriverAgents
> specify runtime args and env vars like --env ENV_1=something --env ENV_2=else and --arg ARG1 --arg ARG2
ios ax [--font=<fontSize>] [options] Access accessibility inspector features.
ios resetax [options] Reset accessibility settings to defaults.
ios debug [--stop-at-entry] <app_path> Start debug with lldb
ios fsync (rm [--r] | tree | mkdir) --path=<targetPath> Remove | treeview | mkdir in target path. --r used alongside rm will recursively remove all files and directories from target path.
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath> Pull or Push file from srcPath to dstPath.
Expand Down Expand Up @@ -1046,6 +1048,12 @@ The commands work as following:
return
}

b, _ = arguments.Bool("resetax")
if b {
resetAx(device)
return
}

b, _ = arguments.Bool("debug")
if b {
appPath, _ := arguments.String("<app_path>")
Expand Down Expand Up @@ -1799,6 +1807,14 @@ func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
<-c
}

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

err = conn.ResetToDefaultAccessibilitySettings()
exitIfError("failed resetting ax", err)
}

func printVersion() {
versionMap := map[string]interface{}{
"version": version,
Expand Down

0 comments on commit 9883cc2

Please sign in to comment.