Skip to content

Commit 5403671

Browse files
authored
fix: launch app with options (#445)
Adds launch options to ios launch Co-authored-by: sam80180 <sam80180@gmail.com>
1 parent b51df98 commit 5403671

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

ios/instruments/processcontrol.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package instruments
22

33
import (
44
"fmt"
5+
"maps"
56

67
"github.com/danielpaulus/go-ios/ios"
78
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
@@ -15,10 +16,12 @@ type ProcessControl struct {
1516

1617
// LaunchApp launches the app with the given bundleID on the given device.LaunchApp
1718
// Use LaunchAppWithArgs for passing arguments and envVars. It returns the PID of the created app process.
18-
func (p *ProcessControl) LaunchApp(bundleID string) (uint64, error) {
19+
func (p *ProcessControl) LaunchApp(bundleID string, my_opts map[string]any) (uint64, error) {
1920
opts := map[string]interface{}{
2021
"StartSuspendedKey": uint64(0),
22+
"KillExisting": uint64(0),
2123
}
24+
maps.Copy(opts, my_opts)
2225
// Xcode sends all these, no idea if we need them for sth. later.
2326
//"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",
2427
//"OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"

ios/instruments/processcontrol_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestLaunchAndKill(t *testing.T) {
2222
if !assert.NoError(t, err) {
2323
t.Fatal(err)
2424
}
25-
pid, err := pControl.LaunchApp(weatherAppBundleID)
25+
pid, err := pControl.LaunchApp(weatherAppBundleID, nil)
2626
if !assert.NoError(t, err) {
2727
return
2828
}

main.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Usage:
110110
ios install --path=<ipaOrAppFolder> [options]
111111
ios uninstall <bundleID> [options]
112112
ios apps [--system] [--all] [--list] [--filesharing] [options]
113-
ios launch <bundleID> [--wait] [options]
113+
ios launch <bundleID> [--wait] [--kill-existing] [options]
114114
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
115115
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]
116116
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
@@ -219,7 +219,7 @@ The commands work as following:
219219
ios install --path=<ipaOrAppFolder> [options] Specify a .app folder or an installable ipa file that will be installed.
220220
ios pcap [options] [--pid=<processID>] [--process=<processName>] Starts a pcap dump of network traffic, use --pid or --process to filter specific processes.
221221
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.
222-
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.
222+
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.
223223
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options] Kill app with the specified bundleID, process id, or process name on the device.
224224
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.
225225
> If you provide '-' as log output, it prints resuts to stdout.
@@ -789,14 +789,18 @@ The commands work as following:
789789
b, _ = arguments.Bool("launch")
790790
if b {
791791
wait, _ := arguments.Bool("--wait")
792+
bKillExisting, _ := arguments.Bool("--kill-existing")
792793
bundleID, _ := arguments.String("<bundleID>")
793794
if bundleID == "" {
794795
log.Fatal("please provide a bundleID")
795796
}
796797
pControl, err := instruments.NewProcessControl(device)
797798
exitIfError("processcontrol failed", err)
798-
799-
pid, err := pControl.LaunchApp(bundleID)
799+
opts := map[string]any{}
800+
if bKillExisting {
801+
opts["KillExisting"] = 1
802+
} // end if
803+
pid, err := pControl.LaunchApp(bundleID, opts)
800804
exitIfError("launch app command failed", err)
801805
log.WithFields(log.Fields{"pid": pid}).Info("Process launched")
802806
if wait {

restapi/api/app_endpoints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func LaunchApp(c *gin.Context) {
5353
return
5454
}
5555

56-
_, err = pControl.LaunchApp(bundleID)
56+
_, err = pControl.LaunchApp(bundleID, nil)
5757
if err != nil {
5858
c.JSON(http.StatusInternalServerError, GenericResponse{Error: err.Error()})
5959
return

0 commit comments

Comments
 (0)