Display a loading spinner while adding a PC is in progress

This commit is contained in:
Cameron Gutman
2020-08-30 20:39:11 -07:00
parent dbab07838d
commit 6bf643968b

View File

@@ -536,30 +536,37 @@ static NSMutableSet* hostList;
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){ [alertController addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
NSString* hostAddress = ((UITextField*)[[alertController textFields] objectAtIndex:0]).text; NSString* hostAddress = ((UITextField*)[[alertController textFields] objectAtIndex:0]).text;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ [self showLoadingFrame:^{
[self->_discMan discoverHost:hostAddress withCallback:^(TemporaryHost* host, NSString* error){ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
if (host != nil) { [self->_discMan discoverHost:hostAddress withCallback:^(TemporaryHost* host, NSString* error){
dispatch_async(dispatch_get_main_queue(), ^{ if (host != nil) {
@synchronized(hostList) { dispatch_async(dispatch_get_main_queue(), ^{
[hostList addObject:host]; [self hideLoadingFrame:^{
@synchronized(hostList) {
[hostList addObject:host];
}
[self updateHosts];
}];
});
} else {
unsigned int portTestResults = LiTestClientConnectivity(CONN_TEST_SERVER, 443,
ML_PORT_FLAG_TCP_47984 | ML_PORT_FLAG_TCP_47989);
if (portTestResults != ML_TEST_RESULT_INCONCLUSIVE && portTestResults != 0) {
error = [error stringByAppendingString:@"\n\nYour device's network connection is blocking Moonlight. Streaming may not work while connected to this network."];
} }
[self updateHosts];
});
} else {
unsigned int portTestResults = LiTestClientConnectivity(CONN_TEST_SERVER, 443,
ML_PORT_FLAG_TCP_47984 | ML_PORT_FLAG_TCP_47989);
if (portTestResults != ML_TEST_RESULT_INCONCLUSIVE && portTestResults != 0) {
error = [error stringByAppendingString:@"\n\nYour device's network connection is blocking Moonlight. Streaming may not work while connected to this network."];
}
UIAlertController* hostNotFoundAlert = [UIAlertController alertControllerWithTitle:@"Add Host Manually" message:error preferredStyle:UIAlertControllerStyleAlert]; UIAlertController* hostNotFoundAlert = [UIAlertController alertControllerWithTitle:@"Add Host Manually" message:error preferredStyle:UIAlertControllerStyleAlert];
[Utils addHelpOptionToDialog:hostNotFoundAlert]; [Utils addHelpOptionToDialog:hostNotFoundAlert];
[hostNotFoundAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; [hostNotFoundAlert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[[self activeViewController] presentViewController:hostNotFoundAlert animated:YES completion:nil]; [self hideLoadingFrame:^{
}); [[self activeViewController] presentViewController:hostNotFoundAlert animated:YES completion:nil];
} }];
}];}); });
}
}];
});
}];
}]]; }]];
[alertController addTextFieldWithConfigurationHandler:nil]; [alertController addTextFieldWithConfigurationHandler:nil];
[[self activeViewController] presentViewController:alertController animated:YES completion:nil]; [[self activeViewController] presentViewController:alertController animated:YES completion:nil];