Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass simDevice to the shutdown method #561

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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