Skip to content

Commit 929c727

Browse files
authored
Feature/mobilegestalt (danielpaulus#60)
adds mobilegestalt support. You can get your result in JSON or the PLIST format. The default is JSON. ios mobilegestalt MainScreenCanvasSizes ArtworkTraits if you need plists call it like this: ios mobilegestalt MainScreenCanvasSizes ArtworkTraits --plist
1 parent 4354e90 commit 929c727

File tree

4 files changed

+61
-18
lines changed

4 files changed

+61
-18
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Options:
2222
--udid=<udid> UDID of the device.
2323
2424
The commands work as following:
25-
The default output of all commands is JSON. Should you prefer human readable outout, specify the --nojson option with your command.
26-
By default, the first device found will be used for a command unless you specify a --udid=some_udid switch.
27-
Specify -v for debug logging and -t for dumping every message.
25+
The default output of all commands is JSON. Should you prefer human readable outout, specify the --nojson option with your command.
26+
By default, the first device found will be used for a command unless you specify a --udid=some_udid switch.
27+
Specify -v for debug logging and -t for dumping every message.
2828
2929
ios listen [options] Keeps a persistent connection open and notifies about newly connected or disconnected devices.
3030
ios list [options] [--details] Prints a list of all connected device's udids. If --details is specified, it includes version, name and model of each device.
@@ -40,6 +40,9 @@ The commands work as following:
4040
ios devicestate enable <profileTypeId> <profileId> [options] Enables a profile with ids (use the list command to see options). It will only stay active until the process is terminated.
4141
> Ex. "ios devicestate enable SlowNetworkCondition SlowNetwork3GGood"
4242
ios lang [--setlocale=<locale>] [--setlang=<newlang>] [options] Sets or gets the Device language
43+
ios mobilegestalt <key>... [--plist] [options] Lets you query mobilegestalt keys. Standard output is json but if desired you can get
44+
> it in plist format by adding the --plist param.
45+
> Ex.: "ios mobilegestalt MainScreenCanvasSizes ArtworkTraits --plist"
4346
ios diagnostics list [options] List diagnostic infos
4447
ios pair [--p12file=<orgid>] [--password=<p12password>] [options] Pairs the device. If the device is supervised, specify the path to the p12 file
4548
> to pair without a trust dialog. Specify the password either with the argument or
@@ -65,5 +68,4 @@ The commands work as following:
6568
ios reboot [options] Reboot the given device
6669
ios -h | --help Prints this screen.
6770
ios --version | version [options] Prints the version
68-
6971
```

ios/diagnostics/diagnostics.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ func (diagnosticsConn *Connection) Reboot() error {
5757
return fmt.Errorf("Could not reboot, response: %+v", plist)
5858
}
5959

60+
func (diagnosticsConn *Connection) MobileGestaltQuery(keys []string) (interface{}, error) {
61+
err := diagnosticsConn.deviceConn.Send(gestaltRequest(keys))
62+
if err != nil {
63+
return "", err
64+
}
65+
respBytes, err := diagnosticsConn.plistCodec.Decode(diagnosticsConn.deviceConn.Reader())
66+
if err != nil {
67+
return "", err
68+
}
69+
err = diagnosticsConn.deviceConn.Send(goodBye())
70+
if err != nil {
71+
return "", err
72+
}
73+
plist, err := ios.ParsePlist(respBytes)
74+
return plist, err
75+
}
76+
6077
func (diagnosticsConn *Connection) AllValues() (allDiagnosticsResponse, error) {
6178
allReq := diagnosticsRequest{"All"}
6279
reader := diagnosticsConn.deviceConn.Reader()

ios/diagnostics/request.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package diagnostics
22

33
import (
44
"bytes"
5+
"github.com/danielpaulus/go-ios/ios"
56

67
plist "howett.net/plist"
78
)
@@ -10,22 +11,27 @@ type diagnosticsRequest struct {
1011
Request string
1112
}
1213

13-
type diagnosticsStatus struct {
14-
Status string
14+
func gestaltRequest(keys []string) []byte {
15+
goodbyeMap := map[string]interface{}{
16+
"Request": "MobileGestalt",
17+
"MobileGestaltKeys": keys,
18+
}
19+
bt, err := ios.PlistCodec{}.Encode(goodbyeMap)
20+
if err != nil {
21+
panic("gestalt request encoding should never fail")
22+
}
23+
return bt
1524
}
1625

17-
func diagnosticsStatusfromBytes(plistBytes []byte) diagnosticsStatus {
18-
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
19-
var data diagnosticsStatus
20-
_ = decoder.Decode(&data)
21-
return data
22-
}
23-
24-
func diagnosticsRequestfromBytes(plistBytes []byte) diagnosticsRequest {
25-
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
26-
var data diagnosticsRequest
27-
_ = decoder.Decode(&data)
28-
return data
26+
func goodBye() []byte {
27+
goodbyeMap := map[string]interface{}{
28+
"Request": "Goodbye",
29+
}
30+
bt, err := ios.PlistCodec{}.Encode(goodbyeMap)
31+
if err != nil {
32+
panic("goodbye request encoding should never fail")
33+
}
34+
return bt
2935
}
3036

3137
func diagnosticsfromBytes(plistBytes []byte) allDiagnosticsResponse {

main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Usage:
6161
ios devicestate list [options]
6262
ios devicestate enable <profileTypeId> <profileId> [options]
6363
ios lang [--setlocale=<locale>] [--setlang=<newlang>] [options]
64+
ios mobilegestalt <key>... [--plist] [options]
6465
ios diagnostics list [options]
6566
ios pair [--p12file=<orgid>] [--password=<p12password>] [options]
6667
ios ps [options]
@@ -106,6 +107,9 @@ The commands work as following:
106107
ios devicestate enable <profileTypeId> <profileId> [options] Enables a profile with ids (use the list command to see options). It will only stay active until the process is terminated.
107108
> Ex. "ios devicestate enable SlowNetworkCondition SlowNetwork3GGood"
108109
ios lang [--setlocale=<locale>] [--setlang=<newlang>] [options] Sets or gets the Device language
110+
ios mobilegestalt <key>... [--plist] [options] Lets you query mobilegestalt keys. Standard output is json but if desired you can get
111+
> it in plist format by adding the --plist param.
112+
> Ex.: "ios mobilegestalt MainScreenCanvasSizes ArtworkTraits --plist"
109113
ios diagnostics list [options] List diagnostic infos
110114
ios pair [--p12file=<orgid>] [--password=<p12password>] [options] Pairs the device. If the device is supervised, specify the path to the p12 file
111115
> to pair without a trust dialog. Specify the password either with the argument or
@@ -185,6 +189,20 @@ The commands work as following:
185189
udid, _ := arguments.String("--udid")
186190
device, err := ios.GetDevice(udid)
187191
exitIfError("error getting devicelist", err)
192+
conn, _ := diagnostics.New(device)
193+
b, _ = arguments.Bool("mobilegestalt")
194+
if b {
195+
keys := arguments["<key>"].([]string)
196+
plist, _ := arguments.Bool("--plist")
197+
resp, _ := conn.MobileGestaltQuery(keys)
198+
if plist {
199+
fmt.Printf("%s", ios.ToPlist(resp))
200+
return
201+
}
202+
jb, _ := json.Marshal(resp)
203+
fmt.Printf("%s", jb)
204+
return
205+
}
188206

189207
if deviceStateCommand {
190208
if listCommand {

0 commit comments

Comments
 (0)