mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-18 06:31:05 +00:00
Add failure handling for quitting apps
This commit is contained in:
@@ -269,15 +269,42 @@ static NSArray* appList;
|
|||||||
Log(LOG_I, @"Quitting application: %@", currentApp.appName);
|
Log(LOG_I, @"Quitting application: %@", currentApp.appName);
|
||||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestWithUrlRequest:[hMan newQuitAppRequest]]];
|
HttpResponse* quitResponse = [[HttpResponse alloc] init];
|
||||||
// TODO: handle failure to quit app
|
HttpRequest* quitRequest = [HttpRequest requestForResponse: quitResponse withUrlRequest:[hMan newQuitAppRequest]];
|
||||||
currentApp.isRunning = NO;
|
[hMan executeRequestSynchronously:quitRequest];
|
||||||
|
|
||||||
|
UIAlertController* alert;
|
||||||
|
|
||||||
|
// If it fails, display an error and stop the current operation
|
||||||
|
if (quitResponse.statusCode != 200) {
|
||||||
|
alert = [UIAlertController alertControllerWithTitle:@"Quitting App Failed"
|
||||||
|
message:@"Failed to quit app. If this app was started by "
|
||||||
|
"another device, you'll need to quit from that device."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
}
|
||||||
|
// If it succeeds and we're to start streaming, segue to the stream and return
|
||||||
|
else if (![app.appId isEqualToString:currentApp.appId]) {
|
||||||
|
currentApp.isRunning = NO;
|
||||||
|
|
||||||
if (![app.appId isEqualToString:currentApp.appId]) {
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
// Otherwise, display a dialog to notify the user that the app was quit
|
||||||
|
else {
|
||||||
|
currentApp.isRunning = NO;
|
||||||
|
|
||||||
|
alert = [UIAlertController alertControllerWithTitle:@"Quitting App"
|
||||||
|
message:@"The app was quit successfully."
|
||||||
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
}
|
||||||
|
|
||||||
|
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:nil]];
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self presentViewController:alert animated:YES completion:nil];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}]];
|
}]];
|
||||||
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
||||||
|
|||||||
Reference in New Issue
Block a user