Skip to content

Commit

Permalink
Add --wait to ios launch (#205)
Browse files Browse the repository at this point in the history
adds new --wait switch to keep the command running and display application logs when an app is launched with ios launch [bundleID]
  • Loading branch information
danielpaulus authored Nov 21, 2022
1 parent 497b36a commit 5d52c24
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
12 changes: 8 additions & 4 deletions ios/dtx_codec/connection.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package dtx

import (
"github.com/danielpaulus/go-ios/ios"
"io"
"math"
"strings"
"sync"
"time"
"math"

ios "github.com/danielpaulus/go-ios/ios"
"github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
log "github.com/sirupsen/logrus"
)
Expand Down Expand Up @@ -73,9 +73,13 @@ func (g GlobalDispatcher) Dispatch(msg Message) {
}
//TODO: use the dispatchFunctions map
if "outputReceived:fromProcess:atTime:" == msg.Payload[0] {
msg, err := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
logmsg, err := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
if err == nil {
log.Info(msg[0])
log.WithFields(log.Fields{
"msg": logmsg[0],
"pid": msg.Auxiliary.GetArguments()[1],
"time": msg.Auxiliary.GetArguments()[2],
}).Info("outputReceived:fromProcess:atTime:")
}
return
}
Expand Down
18 changes: 12 additions & 6 deletions ios/instruments/processcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package instruments

import (
"fmt"

"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
log "github.com/sirupsen/logrus"
Expand All @@ -16,13 +15,20 @@ type ProcessControl struct {
//LaunchApp launches the app with the given bundleID on the given device.LaunchApp
//Use LaunchAppWithArgs for passing arguments and envVars. It returns the PID of the created app process.
func (p *ProcessControl) LaunchApp(bundleID string) (uint64, error) {
options := map[string]interface{}{}
options["StartSuspendedKey"] = uint64(0)
return p.StartProcess(bundleID, map[string]interface{}{}, []interface{}{}, options)
opts := map[string]interface{}{
"StartSuspendedKey": uint64(0),
}
// Xcode sends all these, no idea if we need them for sth. later.
//"CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
//"OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
// NSUnbufferedIO seems to make the app send its logs via instruments using the outputReceived:fromProcess:atTime: selector
// We'll supply per default to get logs
env := map[string]interface{}{"NSUnbufferedIO": "YES"}
return p.StartProcess(bundleID, env, []interface{}{}, opts)
}

func (p *ProcessControl) Close() {
p.conn.Close()
func (p *ProcessControl) Close() error {
return p.conn.Close()
}

func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) {
Expand Down
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Usage:
ios install --path=<ipaOrAppFolder> [options]
ios uninstall <bundleID> [options]
ios apps [--system] [--all] [--list] [options]
ios launch <bundleID> [options]
ios launch <bundleID> [--wait] [options]
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
ios runtest <bundleID> [options]
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
Expand Down Expand Up @@ -177,7 +177,7 @@ The commands work as following:
ios install --path=<ipaOrAppFolder> [options] Specify a .app folder or an installable ipa file that will be installed.
ios pcap [options] [--pid=<processID>] [--process=<processName>] Starts a pcap dump of network traffic, use --pid or --process to filter specific processes.
ios apps [--system] [--all] [--list] Retrieves a list of installed applications. --system prints out preinstalled system apps. --all prints all apps, including system, user, and hidden apps. --list only prints bundle ID, bundle name and version number.
ios launch <bundleID> Launch app with the bundleID on the device. Get your bundle ID from the apps command.
ios launch <bundleID> [--wait] Launch app with the bundleID on the device. Get your bundle ID from the apps command. --wait keeps the connection open if you want logs.
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options] Kill app with the specified bundleID, process id, or process name on the device.
ios runtest <bundleID> Run a XCUITest.
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]...[options] runs WebDriverAgents
Expand Down Expand Up @@ -515,6 +515,7 @@ The commands work as following:

b, _ = arguments.Bool("launch")
if b {
wait, _ := arguments.Bool("--wait")
bundleID, _ := arguments.String("<bundleID>")
if bundleID == "" {
log.Fatal("please provide a bundleID")
Expand All @@ -524,8 +525,13 @@ The commands work as following:

pid, err := pControl.LaunchApp(bundleID)
exitIfError("launch app command failed", err)

log.WithFields(log.Fields{"pid": pid}).Info("Process launched")
if wait {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
<-c
log.WithFields(log.Fields{"pid": pid}).Info("stop listening to logs")
}
}

b, _ = arguments.Bool("kill")
Expand Down

0 comments on commit 5d52c24

Please sign in to comment.