Skip to content

Commit

Permalink
fix mount
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Aug 14, 2022
1 parent 6b4053a commit c790fab
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 72 deletions.
3 changes: 1 addition & 2 deletions cmd/app/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ var installCmd = &cobra.Command{
}
errInstall := device.AppInstall(path)
if errInstall != nil {
fmt.Printf("install failed: %s", errInstall)
os.Exit(0)
return util.NewErrorPrint(util.ErrSendCommand, "install", errInstall)
}
fmt.Println("install successful")
return nil
Expand Down
4 changes: 1 addition & 3 deletions cmd/app/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package app

import (
"fmt"
"github.com/SonicCloudOrg/sonic-ios-bridge/src/util"
"os"

Expand All @@ -35,8 +34,7 @@ var launchCmd = &cobra.Command{
}
_, errLaunch := device.AppLaunch(bundleId)
if errLaunch != nil {
fmt.Println("launch failed")
os.Exit(0)
return util.NewErrorPrint(util.ErrSendCommand, "launch", errLaunch)
}
return nil
},
Expand Down
67 changes: 21 additions & 46 deletions cmd/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,58 +33,33 @@ var listCmd = &cobra.Command{
Short: "show app list",
Long: "show app list",
RunE: func(cmd *cobra.Command, args []string) error {
usbMuxClient, err := giDevice.NewUsbmux()
if err != nil {
return util.NewErrorPrint(util.ErrConnect, "usbMux", err)
device := util.GetDeviceByUdId(udid)
if device == nil {
os.Exit(0)
}
list, err1 := usbMuxClient.Devices()
if err1 != nil {
return util.NewErrorPrint(util.ErrSendCommand, "listDevices", err1)
result, errList := device.InstallationProxyBrowse(
giDevice.WithApplicationType(giDevice.ApplicationTypeUser),
giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if errList != nil {
return util.NewErrorPrint(util.ErrSendCommand, "app list", errList)
}
if len(list) != 0 {
var device giDevice.Device
if len(udid) != 0 {
for i, d := range list {
if d.Properties().SerialNumber == udid {
device = list[i]
break
}
}
} else {
device = list[0]
}
if device.Properties().SerialNumber != "" {
result, errList := device.InstallationProxyBrowse(
giDevice.WithApplicationType(giDevice.ApplicationTypeUser),
giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if errList != nil {
return util.NewErrorPrint(util.ErrSendCommand, "appList", errList)
}
var appList entity.AppList
for _, app := range result {
a := entity.Application{}
mapstructure.Decode(app, &a)
if a.CFBundleIdentifier != "" && a.CFBundleDisplayName != "" && a.CFBundleVersion != "" {
if showIcon {
icon, errIcon := device.GetIconPNGData(a.CFBundleIdentifier)
if errIcon == nil {
data, _ := ioutil.ReadAll(icon)
a.IconBase64 = base64.StdEncoding.EncodeToString(data)
}
}
appList.ApplicationList = append(appList.ApplicationList, a)
var appList entity.AppList
for _, app := range result {
a := entity.Application{}
mapstructure.Decode(app, &a)
if a.CFBundleIdentifier != "" && a.CFBundleDisplayName != "" && a.CFBundleVersion != "" {
if showIcon {
icon, errIcon := device.GetIconPNGData(a.CFBundleIdentifier)
if errIcon == nil {
data, _ := ioutil.ReadAll(icon)
a.IconBase64 = base64.StdEncoding.EncodeToString(data)
}
}
data := util.ResultData(appList)
fmt.Println(util.Format(data, isFormat, isJson))
} else {
fmt.Println("device no found")
os.Exit(0)
appList.ApplicationList = append(appList.ApplicationList, a)
}
} else {
fmt.Println("no device connected")
os.Exit(0)
}
data := util.ResultData(appList)
fmt.Println(util.Format(data, isFormat, isJson))
return nil
},
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/app/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ var uninstallCmd = &cobra.Command{
if device == nil {
os.Exit(0)
}
util.CheckMount(device)
errUninstall := device.AppUninstall(bundleId)
if errUninstall != nil {
fmt.Println("uninstall failed")
os.Exit(0)
return util.NewErrorPrint(util.ErrSendCommand, "uninstall", errUninstall)
}
fmt.Println("uninstall successful")
return nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/crash.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var crashCmd = &cobra.Command{
}),
)
if err != nil {
fmt.Println("move crash files failed.")
return util.NewErrorPrint(util.ErrUnknown, "move crash files", err)
}
fmt.Println("All done.")
return nil
Expand Down
1 change: 0 additions & 1 deletion cmd/location/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ var locationSetCmd = &cobra.Command{
if device == nil {
os.Exit(0)
}
util.CheckMount(device)
err := device.SimulateLocationUpdate(long, lat, giDevice.CoordinateSystemBD09)
if err != nil {
return util.NewErrorPrint(util.ErrSendCommand, "location set", err)
Expand Down
3 changes: 1 addition & 2 deletions cmd/reboot.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ var rebootCmd = &cobra.Command{
errReboot = device.Reboot()
}
if errReboot != nil {
fmt.Println("reboot failed")
os.Exit(0)
return util.NewErrorPrint(util.ErrSendCommand, "reboot", errReboot)
}
fmt.Println("reboot successful")
return nil
Expand Down
7 changes: 5 additions & 2 deletions cmd/run/wda.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"net"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
Expand All @@ -49,13 +50,15 @@ var wdaCmd = &cobra.Command{
giDevice.WithApplicationType(giDevice.ApplicationTypeUser),
giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if errList != nil {
return util.NewErrorPrint(util.ErrSendCommand, "appList", errList)
return util.NewErrorPrint(util.ErrSendCommand, "app list", errList)
}
var hasWda = false
re, _ := regexp.Compile(strings.ReplaceAll(wdaBundleID, "*", "/*"))
for _, d := range appList {
a := entity.Application{}
mapstructure.Decode(d, &a)
if a.CFBundleIdentifier == wdaBundleID {
if re.MatchString(a.CFBundleIdentifier) {
wdaBundleID = a.CFBundleIdentifier
hasWda = true
break
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/run/xctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"log"
"os"
"os/signal"
"regexp"
"strings"
"syscall"

Expand All @@ -44,13 +45,15 @@ var xctestCmd = &cobra.Command{
giDevice.WithApplicationType(giDevice.ApplicationTypeUser),
giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if errList != nil {
return util.NewErrorPrint(util.ErrSendCommand, "appList", errList)
return util.NewErrorPrint(util.ErrSendCommand, "app list", errList)
}
var hasApp = false
re, _ := regexp.Compile(strings.ReplaceAll(wdaBundleID, "*", "/*"))
for _, d := range appList {
a := entity.Application{}
mapstructure.Decode(d, &a)
if a.CFBundleIdentifier == xcTestBundleID {
if re.MatchString(a.CFBundleIdentifier) {
wdaBundleID = a.CFBundleIdentifier
hasApp = true
break
}
Expand Down
1 change: 0 additions & 1 deletion cmd/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var screenshotCmd = &cobra.Command{
if device == nil {
os.Exit(0)
}
util.CheckMount(device)
bytes, err := device.Screenshot()
if err != nil {
return util.NewErrorPrint(util.ErrSendCommand, "screenshot", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var syslogCmd = &cobra.Command{
}
output, err := device.Syslog()
if err != nil {
fmt.Printf("Get syslog failed: %s", err)
return util.NewErrorPrint(util.ErrSendCommand, "syslog", err)
}
defer device.SyslogStop()
done := make(chan os.Signal, syscall.SIGTERM)
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var versionCmd = &cobra.Command{
Short: "Version code of sib",
Long: "Version code of sib",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("1.1.6")
fmt.Println("1.1.7")
},
}

Expand Down
15 changes: 8 additions & 7 deletions src/util/errprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ package util
import "fmt"

const (
ErrConnect = "failed connecting to "
ErrReadingMsg = "failed reading msg "
ErrSendCommand = "failed send the command "
ErrConnect = "failed connecting to"
ErrReadingMsg = "failed reading msg"
ErrSendCommand = "failed send the command"
ErrMissingArgs = "missing arg(s)"
ErrUnknown = "unknown error"
MountTips = "you use [sib mount] command to fix it and retry"
)

func NewErrorPrint(t string, msg string, err error) error {
if len(msg) == 0 && err == nil {
return fmt.Errorf("%s", t)
return fmt.Errorf("%s, %s", t, MountTips)
}
if len(msg) == 0 {
return fmt.Errorf("%s : %w", t, err)
return fmt.Errorf("%s, %s : %w", t, MountTips, err)
}
if err == nil {
return fmt.Errorf("%s %s", t, msg)
return fmt.Errorf("%s [%s], %s", t, msg, MountTips)
}
return fmt.Errorf("%s %s : %w", t, msg, err)
return fmt.Errorf("%s [%s], %s, err : %w", t, msg, MountTips, err)
}

0 comments on commit c790fab

Please sign in to comment.