Skip to content

Commit 11851a8

Browse files
committed
Fixed use of FBApplicationLaunchMode for FBDevice
Previously, the app would be restarted for FBApplicationLaunchModeForegroundIfRunning and not fail if already running for FBApplicationLaunchModeFailIfRunning.
1 parent bf2a4f1 commit 11851a8

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

FBDeviceControl/Commands/FBDeviceApplicationCommands.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,26 @@ - (instancetype)initWithDevice:(FBDevice *)device
237237
}
238238

239239
- (FBFuture<id<FBLaunchedProcess>> *)launchApplication:(FBApplicationLaunchConfiguration *)configuration
240+
{
241+
if (configuration.launchMode == FBApplicationLaunchModeFailIfRunning) {
242+
return [[self processIDWithBundleID:configuration.bundleID] onQueue:self.device.asyncQueue chain:^ (FBFuture<NSNumber *>* processIdQueryResult) {
243+
if (processIdQueryResult.state == FBFutureStateDone) {
244+
return [[FBDeviceControlError
245+
describeFormat:@"Application %@ already running with pid %@", configuration.bundleID, processIdQueryResult.result]
246+
failFuture];
247+
} else if (processIdQueryResult.state == FBFutureStateFailed) {
248+
return (FBFuture*)[self launchApplicationIgnoreCurrentState:configuration];
249+
} else {
250+
return (FBFuture*)processIdQueryResult;
251+
}
252+
}];
253+
}
254+
return [self launchApplicationIgnoreCurrentState:configuration];
255+
}
256+
257+
#pragma mark Private
258+
259+
- (FBFuture<id<FBLaunchedProcess>> *)launchApplicationIgnoreCurrentState:(FBApplicationLaunchConfiguration *)configuration
240260
{
241261
return [[[self
242262
remoteInstrumentsClient]
@@ -248,8 +268,6 @@ - (instancetype)initWithDevice:(FBDevice *)device
248268
}];
249269
}
250270

251-
#pragma mark Private
252-
253271
- (FBFuture<NSNull *> *)killApplicationWithProcessIdentifier:(pid_t)processIdentifier
254272
{
255273
return [[self

FBDeviceControl/Management/FBInstrumentsClient.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ - (instancetype)initWithConnection:(FBAMDServiceConnection *)connection channels
140140
onQueue:self.queue resolveValue:^ NSNumber * (NSError **error) {
141141
NSDictionary<NSString *, NSNumber *> *options = @{
142142
@"StartSuspendedKey": @(configuration.waitForDebugger),
143-
@"KillExisting": @(configuration.launchMode != FBApplicationLaunchModeFailIfRunning),
143+
// FBApplicationLaunchModeFailIfRunning needs to be taken care of prior to this call.
144+
@"KillExisting": @(configuration.launchMode == FBApplicationLaunchModeRelaunchIfRunning),
144145
};
145146
ResponsePayload response = [self
146147
onChannelIdentifier:ProcessControlChannel

0 commit comments

Comments
 (0)