Skip to content

Commit

Permalink
fix stop
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun committed Aug 10, 2022
1 parent 8d201a0 commit 6b4053a
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 25 deletions.
67 changes: 46 additions & 21 deletions cmd/app/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,58 @@ var listCmd = &cobra.Command{
Short: "show app list",
Long: "show app list",
RunE: func(cmd *cobra.Command, args []string) error {
device := util.GetDeviceByUdId(udid)
if device == nil {
os.Exit(0)
usbMuxClient, err := giDevice.NewUsbmux()
if err != nil {
return util.NewErrorPrint(util.ErrConnect, "usbMux", err)
}
result, errList := device.InstallationProxyBrowse(
giDevice.WithApplicationType(giDevice.ApplicationTypeUser),
giDevice.WithReturnAttributes("CFBundleVersion", "CFBundleDisplayName", "CFBundleIdentifier"))
if errList != nil {
return util.NewErrorPrint(util.ErrSendCommand, "appList", errList)
list, err1 := usbMuxClient.Devices()
if err1 != nil {
return util.NewErrorPrint(util.ErrSendCommand, "listDevices", err1)
}
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)
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)
}
}
appList.ApplicationList = append(appList.ApplicationList, a)
data := util.ResultData(appList)
fmt.Println(util.Format(data, isFormat, isJson))
} else {
fmt.Println("device no found")
os.Exit(0)
}
} else {
fmt.Println("no device connected")
os.Exit(0)
}
data := util.ResultData(appList)
fmt.Println(util.Format(data, isFormat, isJson))
return nil
},
}
Expand Down
1 change: 1 addition & 0 deletions cmd/app/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var uninstallCmd = &cobra.Command{
if device == nil {
os.Exit(0)
}
util.CheckMount(device)
errUninstall := device.AppUninstall(bundleId)
if errUninstall != nil {
fmt.Println("uninstall failed")
Expand Down
1 change: 1 addition & 0 deletions cmd/location/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ 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
45 changes: 45 additions & 0 deletions cmd/mount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) [SonicCloudOrg] Sonic Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package cmd

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

"github.com/spf13/cobra"
)

var mountCmd = &cobra.Command{
Use: "mount",
Short: "Mount device development disk",
Long: "Mount device development disk",
RunE: func(cmd *cobra.Command, args []string) error {
device := util.GetDeviceByUdId(udid)
if device == nil {
os.Exit(0)
}
util.CheckMount(device)
fmt.Println("mount successful!")
return nil
},
}

func init() {
rootCmd.AddCommand(mountCmd)
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "device's serialNumber ( default first device )")
}
1 change: 1 addition & 0 deletions cmd/run/wda.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var wdaCmd = &cobra.Command{
testEnv := make(map[string]interface{})
testEnv["USE_PORT"] = serverRemotePort
testEnv["MJPEG_SERVER_PORT"] = mjpegRemotePort
util.CheckMount(device)
output, stopTest, err2 := device.XCTest(wdaBundleID, giDevice.WithXCTestEnv(testEnv))
if err2 != nil {
fmt.Printf("WebDriverAgent server start failed: %s", err2)
Expand Down
2 changes: 2 additions & 0 deletions cmd/run/xctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ var xctestCmd = &cobra.Command{
}
log.Println("Read env:", testEnv)
}

util.CheckMount(device)
output, stopTest, err2 := device.XCTest(xcTestBundleID, giDevice.WithXCTestEnv(testEnv))
if err2 != nil {
fmt.Printf("xctest start failed: %s", err2)
Expand Down
1 change: 1 addition & 0 deletions cmd/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ 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/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.5")
fmt.Println("1.1.6")
},
}

Expand Down
3 changes: 0 additions & 3 deletions src/util/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ func GetDeviceByUdId(udId string) (device giDevice.Device) {
fmt.Println("no device connected")
return nil
}
if device != nil {
CheckMount(device)
}
return
}

Expand Down

0 comments on commit 6b4053a

Please sign in to comment.