Skip to content

Commit

Permalink
fix: launch app with options (#445)
Browse files Browse the repository at this point in the history
Adds launch options to ios launch
Co-authored-by: sam80180 <[email protected]>
  • Loading branch information
sam80180 authored Aug 5, 2024
1 parent b51df98 commit 5403671
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion ios/instruments/processcontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package instruments

import (
"fmt"
"maps"

"github.com/danielpaulus/go-ios/ios"
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
Expand All @@ -15,10 +16,12 @@ 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) {
func (p *ProcessControl) LaunchApp(bundleID string, my_opts map[string]any) (uint64, error) {
opts := map[string]interface{}{
"StartSuspendedKey": uint64(0),
"KillExisting": uint64(0),
}
maps.Copy(opts, my_opts)
// 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"
Expand Down
2 changes: 1 addition & 1 deletion ios/instruments/processcontrol_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestLaunchAndKill(t *testing.T) {
if !assert.NoError(t, err) {
t.Fatal(err)
}
pid, err := pControl.LaunchApp(weatherAppBundleID)
pid, err := pControl.LaunchApp(weatherAppBundleID, nil)
if !assert.NoError(t, err) {
return
}
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Usage:
ios install --path=<ipaOrAppFolder> [options]
ios uninstall <bundleID> [options]
ios apps [--system] [--all] [--list] [--filesharing] [options]
ios launch <bundleID> [--wait] [options]
ios launch <bundleID> [--wait] [--kill-existing] [options]
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
ios runtest [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testrunnerbundleid>] [--xctest-config=<xctestconfig>] [--log-output=<file>] [--test-to-run=<tests>]... [--test-to-skip=<tests>]... [--env=<e>]... [options]
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
Expand Down Expand Up @@ -219,7 +219,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] [--filesharing] 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. --filesharing only prints apps which enable documents sharing.
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 launch <bundleID> [--wait] [--kill-existing] [options] 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 [--bundle-id=<bundleid>] [--test-runner-bundle-id=<testbundleid>] [--xctest-config=<xctestconfig>] [--log-output=<file>] [--test-to-run=<tests>]... [--test-to-skip=<tests>]... [--env=<e>]... [options] Run a XCUITest. If you provide only bundle-id go-ios will try to dynamically create test-runner-bundle-id and xctest-config.
> If you provide '-' as log output, it prints resuts to stdout.
Expand Down Expand Up @@ -789,14 +789,18 @@ The commands work as following:
b, _ = arguments.Bool("launch")
if b {
wait, _ := arguments.Bool("--wait")
bKillExisting, _ := arguments.Bool("--kill-existing")
bundleID, _ := arguments.String("<bundleID>")
if bundleID == "" {
log.Fatal("please provide a bundleID")
}
pControl, err := instruments.NewProcessControl(device)
exitIfError("processcontrol failed", err)

pid, err := pControl.LaunchApp(bundleID)
opts := map[string]any{}
if bKillExisting {
opts["KillExisting"] = 1
} // end if
pid, err := pControl.LaunchApp(bundleID, opts)
exitIfError("launch app command failed", err)
log.WithFields(log.Fields{"pid": pid}).Info("Process launched")
if wait {
Expand Down
2 changes: 1 addition & 1 deletion restapi/api/app_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func LaunchApp(c *gin.Context) {
return
}

_, err = pControl.LaunchApp(bundleID)
_, err = pControl.LaunchApp(bundleID, nil)
if err != nil {
c.JSON(http.StatusInternalServerError, GenericResponse{Error: err.Error()})
return
Expand Down

0 comments on commit 5403671

Please sign in to comment.