forked from electricbubble/gidevice
-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
springboard.go
67 lines (62 loc) · 1.67 KB
/
springboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package giDevice
import (
"bytes"
"fmt"
"github.com/SonicCloudOrg/sonic-gidevice/pkg/libimobiledevice"
)
func newSpringBoard(client *libimobiledevice.SpringBoardClient) *springboard {
return &springboard{
client: client,
}
}
type springboard struct {
client *libimobiledevice.SpringBoardClient
}
func (s springboard) GetIconPNGData(bundleId string) (raw *bytes.Buffer, err error) {
var pkt libimobiledevice.Packet
req := map[string]interface{}{
"command": "getIconPNGData",
"bundleId": bundleId,
}
if pkt, err = s.client.NewBinaryPacket(req); err != nil {
return
}
if err = s.client.SendPacket(pkt); err != nil {
return nil, err
}
var respPkt libimobiledevice.Packet
if respPkt, err = s.client.ReceivePacket(); err != nil {
return nil, err
}
var reply libimobiledevice.IconPNGDataResponse
raw = new(bytes.Buffer)
if err = respPkt.Unmarshal(&reply); err != nil {
return nil, fmt.Errorf("receive packet: %w", err)
}
if _, err = raw.Write(reply.PNGData); err != nil {
return nil, err
}
return
}
func (s springboard) GetInterfaceOrientation() (orientation libimobiledevice.OrientationState, err error) {
var pkt libimobiledevice.Packet
req := map[string]interface{}{
"command": "getInterfaceOrientation",
}
if pkt, err = s.client.NewBinaryPacket(req); err != nil {
return
}
if err = s.client.SendPacket(pkt); err != nil {
return 0, err
}
var respPkt libimobiledevice.Packet
if respPkt, err = s.client.ReceivePacket(); err != nil {
return 0, err
}
var reply libimobiledevice.InterfaceOrientationResponse
if err = respPkt.Unmarshal(&reply); err != nil {
return 0, fmt.Errorf("receive packet: %w", err)
}
orientation = reply.Orientation
return
}