Skip to content

Commit b8c3463

Browse files
authored
Reset ax settings (danielpaulus#546)
Authored-by: fish-sauce <[email protected]>
1 parent 0c06384 commit b8c3463

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

ios/accessibility/accessibility.go

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ import (
77

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

10+
// NewWithoutEventChangeListeners creates and connects to the given device, a new ControlInterface instance
11+
// without setting accessibility event change listeners to avoid keeping constant connection.
12+
func NewWithoutEventChangeListeners(device ios.DeviceEntry) (ControlInterface, error) {
13+
conn, err := dtx.NewUsbmuxdConnection(device, serviceName)
14+
if err != nil {
15+
return ControlInterface{}, err
16+
}
17+
control := ControlInterface{conn.GlobalChannel()}
18+
return control, nil
19+
}
20+
1021
// New creates and connects to the given device, a new ControlInterface instance
1122
func New(device ios.DeviceEntry) (ControlInterface, error) {
1223
conn, err := dtx.NewUsbmuxdConnection(device, serviceName)

ios/accessibility/accessibility_control.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (a ControlInterface) readhostInspectorNotificationReceived() {
3838
}
3939
}
4040

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

153+
func (a ControlInterface) ResetToDefaultAccessibilitySettings() error {
154+
err := a.channel.MethodCallAsync("deviceResetToDefaultAccessibilitySettings")
155+
if err != nil {
156+
return err
157+
}
158+
return nil
159+
}
160+
153161
func (a ControlInterface) awaitHostInspectorCurrentElementChanged() map[string]interface{} {
154162
msg := a.channel.ReceiveMethodCall("hostInspectorCurrentElementChanged:")
155163
log.Info("received hostInspectorCurrentElementChanged")
@@ -194,15 +202,15 @@ func (a ControlInterface) deviceCapabilities() ([]string, error) {
194202
if err != nil {
195203
return nil, err
196204
}
197-
return convertToStringList(response.Payload), nil
205+
return convertToStringList(response.Payload)
198206
}
199207

200208
func (a ControlInterface) deviceAllAuditCaseIDs() ([]string, error) {
201209
response, err := a.channel.MethodCall("deviceAllAuditCaseIDs")
202210
if err != nil {
203211
return nil, err
204212
}
205-
return convertToStringList(response.Payload), nil
213+
return convertToStringList(response.Payload)
206214
}
207215

208216
func (a ControlInterface) deviceAccessibilitySettings() (map[string]interface{}, error) {

ios/accessibility/utils.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package accessibility
22

3-
func convertToStringList(payload []interface{}) []string {
3+
import "fmt"
4+
5+
func convertToStringList(payload []interface{}) ([]string, error) {
6+
if len(payload) != 1 {
7+
return nil, fmt.Errorf("invalid payload length %d", len(payload))
8+
}
49
list := payload[0].([]interface{})
510
result := make([]string, len(list))
611
for i, v := range list {
712
result[i] = v.(string)
813
}
9-
return result
14+
return result, nil
1015
}

main.go

+16
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Usage:
117117
ios runxctest [--xctestrun-file-path=<xctestrunFilePath>] [--log-output=<file>] [options]
118118
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--log-output=<file>] [--arg=<a>]... [--env=<e>]... [options]
119119
ios ax [--font=<fontSize>] [options]
120+
ios resetax [options]
120121
ios debug [options] [--stop-at-entry] <app_path>
121122
ios fsync (rm [--r] | tree | mkdir) --path=<targetPath>
122123
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath>
@@ -238,6 +239,7 @@ The commands work as following:
238239
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--log-output=<file>] [--arg=<a>]... [--env=<e>]...[options] runs WebDriverAgents
239240
> specify runtime args and env vars like --env ENV_1=something --env ENV_2=else and --arg ARG1 --arg ARG2
240241
ios ax [--font=<fontSize>] [options] Access accessibility inspector features.
242+
ios resetax [options] Reset accessibility settings to defaults.
241243
ios debug [--stop-at-entry] <app_path> Start debug with lldb
242244
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.
243245
ios fsync (pull | push) --srcPath=<srcPath> --dstPath=<dstPath> Pull or Push file from srcPath to dstPath.
@@ -1047,6 +1049,12 @@ The commands work as following:
10471049
return
10481050
}
10491051

1052+
b, _ = arguments.Bool("resetax")
1053+
if b {
1054+
resetAx(device)
1055+
return
1056+
}
1057+
10501058
b, _ = arguments.Bool("debug")
10511059
if b {
10521060
appPath, _ := arguments.String("<app_path>")
@@ -1800,6 +1808,14 @@ func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
18001808
<-c
18011809
}
18021810

1811+
func resetAx(device ios.DeviceEntry) {
1812+
conn, err := accessibility.NewWithoutEventChangeListeners(device)
1813+
exitIfError("failed creating ax service", err)
1814+
1815+
err = conn.ResetToDefaultAccessibilitySettings()
1816+
exitIfError("failed resetting ax", err)
1817+
}
1818+
18031819
func printVersion() {
18041820
versionMap := map[string]interface{}{
18051821
"version": version,

0 commit comments

Comments
 (0)