Skip to content

Commit

Permalink
Pass simDevice to the shutdown method (#561)
Browse files Browse the repository at this point in the history
Signed-off-by: Nan Wang <[email protected]>
  • Loading branch information
nanwng authored Aug 30, 2023
1 parent 2576a78 commit 97ab3a0
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions bp/src/BPSimulator.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (NSString *)installApplicationWithHost:(NSString *)testHost withError:(NSError
}];
return nil;
} else {
[self shutdownSimulatorWithError:errPtr];
[self shutdownSimulator:simDevice withError:errPtr];
if(*errPtr) {
[BPUtils printInfo:ERROR withString:@"Shutdown simulator failed with error: %@", [*errPtr localizedDescription]];
[deviceSet deleteDeviceAsync:simDevice completionHandler:^(NSError *error) {
Expand Down Expand Up @@ -307,17 +307,20 @@ - (BOOL)useSimulatorWithDeviceUDID:(NSUUID *)deviceUDID {
return YES;
}

- (BOOL)shutdownSimulatorWithError:(id *)error {
[BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", self.device.UDID.UUIDString];
- (BOOL)shutdownSimulator:(SimDevice *)simDevice withError:(id *)error {
if (!simDevice) {
return NO;
}
[BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", simDevice.UDID.UUIDString];

// Calling shutdown when already shutdown should be avoided (if detected).
if ([self.device.stateString isEqualToString:@"Shutdown"]) {
[BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", self.device];
if ([simDevice.stateString isEqualToString:@"Shutdown"]) {
[BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", simDevice];
*error = nil;
return YES;
}

return [self.device shutdownWithError:error];
return [simDevice shutdownWithError:error];
}

- (void)bootWithCompletion:(void (^)(NSError *error))completion {
Expand All @@ -333,7 +336,7 @@ - (void)openSimulatorHeadlessWithCompletion:(void (^)(NSError *))completion {
[self.device bootAsyncWithOptions:options completionHandler:^(NSError *bootError){
NSError *error = [self waitForDeviceReady];
if (error) {
[self shutdownSimulatorWithError:&error];
[self shutdownSimulator:self.device withError:&error];
if (error) {
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
}
Expand Down Expand Up @@ -584,7 +587,7 @@ - (void)deleteSimulatorWithCompletion:(void (^)(NSError *error, BOOL success))co
}
if (self.device) {
[BPUtils printInfo:INFO withString:@"Shutting down Simulator"];
[self shutdownSimulatorWithError:&error];
[self shutdownSimulator:self.device withError:&error];
if (error) {
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
completion(error, NO);
Expand Down

0 comments on commit 97ab3a0

Please sign in to comment.