Skip to content

Commit

Permalink
Fixed use of FBApplicationLaunchMode for FBDevice
Browse files Browse the repository at this point in the history
Previously, the app would be restarted for FBApplicationLaunchModeForegroundIfRunning and not fail if already running for FBApplicationLaunchModeFailIfRunning.
  • Loading branch information
AndreasReich committed Mar 25, 2021
1 parent 7e6664d commit aadaad9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
22 changes: 20 additions & 2 deletions FBDeviceControl/Commands/FBDeviceApplicationCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,26 @@ - (instancetype)initWithDevice:(FBDevice *)device
}

- (FBFuture<id<FBLaunchedApplication>> *)launchApplication:(FBApplicationLaunchConfiguration *)configuration
{
if (configuration.launchMode == FBApplicationLaunchModeFailIfRunning) {
return [[self processIDWithBundleID:configuration.bundleID] onQueue:self.device.asyncQueue chain:^ (FBFuture<NSNumber *>* processIdQueryResult) {
if (processIdQueryResult.state == FBFutureStateDone) {
return [[FBDeviceControlError
describeFormat:@"Application %@ already running with pid %@", configuration.bundleID, processIdQueryResult.result]
failFuture];
} else if (processIdQueryResult.state == FBFutureStateFailed) {
return (FBFuture*)[self launchApplicationIgnoreCurrentState:configuration];
} else {
return (FBFuture*)processIdQueryResult;
}
}];
}
return [self launchApplicationIgnoreCurrentState:configuration];
}

#pragma mark Private

- (FBFuture<id<FBLaunchedProcess>> *)launchApplicationIgnoreCurrentState:(FBApplicationLaunchConfiguration *)configuration
{
return [[[self
remoteInstrumentsClient]
Expand All @@ -248,8 +268,6 @@ - (instancetype)initWithDevice:(FBDevice *)device
}];
}

#pragma mark Private

- (FBFuture<NSNull *> *)killApplicationWithProcessIdentifier:(pid_t)processIdentifier
{
return [[self
Expand Down
3 changes: 2 additions & 1 deletion FBDeviceControl/Management/FBInstrumentsClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ - (instancetype)initWithConnection:(FBAMDServiceConnection *)connection channels
onQueue:self.queue resolveValue:^ NSNumber * (NSError **error) {
NSDictionary<NSString *, NSNumber *> *options = @{
@"StartSuspendedKey": @(configuration.waitForDebugger),
@"KillExisting": @(configuration.launchMode != FBApplicationLaunchModeFailIfRunning),
// FBApplicationLaunchModeFailIfRunning needs to be taken care of prior to this call.
@"KillExisting": @(configuration.launchMode == FBApplicationLaunchModeRelaunchIfRunning),
};
ResponsePayload response = [self
onChannelIdentifier:ProcessControlChannel
Expand Down

0 comments on commit aadaad9

Please sign in to comment.