mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-18 06:30:55 +00:00
Display status messages for failed app launch
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
@interface HttpManager : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate>
|
@interface HttpManager : NSObject <NSURLConnectionDelegate, NSURLConnectionDataDelegate>
|
||||||
|
|
||||||
+ (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag;
|
+ (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag;
|
||||||
|
+ (NSString*) getStatusStringFromXML:(NSData*)xml;
|
||||||
|
|
||||||
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert;
|
- (id) initWithHost:(NSString*) host uniqueId:(NSString*) uniqueId deviceName:(NSString*) deviceName cert:(NSData*) cert;
|
||||||
- (NSURLRequest*) newPairRequest:(NSData*)salt;
|
- (NSURLRequest*) newPairRequest:(NSData*)salt;
|
||||||
|
|||||||
@@ -25,6 +25,24 @@
|
|||||||
|
|
||||||
static const NSString* PORT = @"47984";
|
static const NSString* PORT = @"47984";
|
||||||
|
|
||||||
|
+ (NSString*) getStatusStringFromXML:(NSData*)xml {
|
||||||
|
xmlDocPtr docPtr = xmlParseMemory([xml bytes], (int)[xml length]);
|
||||||
|
|
||||||
|
if (docPtr == NULL) {
|
||||||
|
NSLog(@"ERROR: An error occured trying to parse xml.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSString* string;
|
||||||
|
xmlNodePtr rootNode = xmlDocGetRootElement(docPtr);
|
||||||
|
|
||||||
|
string = [HttpManager getStatusMessage: rootNode];
|
||||||
|
xmlFree(rootNode);
|
||||||
|
xmlFree(docPtr);
|
||||||
|
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
+ (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag {
|
+ (NSString*) getStringFromXML:(NSData*)xml tag:(NSString*)tag {
|
||||||
xmlDocPtr docPtr = xmlParseMemory([xml bytes], (int)[xml length]);
|
xmlDocPtr docPtr = xmlParseMemory([xml bytes], (int)[xml length]);
|
||||||
|
|
||||||
@@ -61,6 +79,13 @@ static const NSString* PORT = @"47984";
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (NSString*) getStatusMessage:(xmlNodePtr)docRoot {
|
||||||
|
xmlChar* statusMsgXml = xmlGetProp(docRoot, (const xmlChar*)"status_message");
|
||||||
|
NSString* statusMsg = [NSString stringWithUTF8String:(const char*)statusMsgXml];
|
||||||
|
xmlFree(statusMsgXml);
|
||||||
|
return statusMsg;
|
||||||
|
}
|
||||||
|
|
||||||
+ (bool) verifyStatus:(xmlNodePtr)docRoot {
|
+ (bool) verifyStatus:(xmlNodePtr)docRoot {
|
||||||
xmlChar* statusStr = xmlGetProp(docRoot, (const xmlChar*)"status_code");
|
xmlChar* statusStr = xmlGetProp(docRoot, (const xmlChar*)"status_code");
|
||||||
NSLog(@"status: %s", statusStr);
|
NSLog(@"status: %s", statusStr);
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
- (void) stageStarting:(char*)stageName;
|
- (void) stageStarting:(char*)stageName;
|
||||||
- (void) stageComplete:(char*)stageName;
|
- (void) stageComplete:(char*)stageName;
|
||||||
- (void) stageFailed:(char*)stageName withError:(long)errorCode;
|
- (void) stageFailed:(char*)stageName withError:(long)errorCode;
|
||||||
- (void) launchFailed;
|
- (void) launchFailed:(NSString*)message;
|
||||||
- (void) displayMessage:(char*)message;
|
- (void) displayMessage:(char*)message;
|
||||||
- (void) displayTransientMessage:(char*)message;
|
- (void) displayTransientMessage:(char*)message;
|
||||||
|
|
||||||
|
|||||||
@@ -43,27 +43,25 @@
|
|||||||
NSString* currentGame = [HttpManager getStringFromXML:serverInfoResp tag:@"currentgame"];
|
NSString* currentGame = [HttpManager getStringFromXML:serverInfoResp tag:@"currentgame"];
|
||||||
NSString* pairStatus = [HttpManager getStringFromXML:serverInfoResp tag:@"PairStatus"];
|
NSString* pairStatus = [HttpManager getStringFromXML:serverInfoResp tag:@"PairStatus"];
|
||||||
if (currentGame == NULL || pairStatus == NULL) {
|
if (currentGame == NULL || pairStatus == NULL) {
|
||||||
[_callbacks launchFailed];
|
[_callbacks launchFailed:@"Failed to connect to PC"];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (![pairStatus isEqualToString:@"1"]) {
|
if (![pairStatus isEqualToString:@"1"]) {
|
||||||
// Not paired
|
// Not paired
|
||||||
// TODO: Display better error message
|
[_callbacks launchFailed:@"Device not paired to PC"];
|
||||||
[_callbacks launchFailed];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// resumeApp and launchApp handle calling launchFailed
|
||||||
if (![currentGame isEqualToString:@"0"]) {
|
if (![currentGame isEqualToString:@"0"]) {
|
||||||
// App already running, resume it
|
// App already running, resume it
|
||||||
if (![self resumeApp:hMan]) {
|
if (![self resumeApp:hMan]) {
|
||||||
[_callbacks launchFailed];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Start app
|
// Start app
|
||||||
if (![self launchApp:hMan]) {
|
if (![self launchApp:hMan]) {
|
||||||
[_callbacks launchFailed];
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +86,11 @@
|
|||||||
rikey:[Utils bytesToHex:_config.riKey]
|
rikey:[Utils bytesToHex:_config.riKey]
|
||||||
rikeyid:_config.riKeyId]];
|
rikeyid:_config.riKeyId]];
|
||||||
NSString *gameSession = [HttpManager getStringFromXML:launchResp tag:@"gamesession"];
|
NSString *gameSession = [HttpManager getStringFromXML:launchResp tag:@"gamesession"];
|
||||||
if (gameSession == NULL || [gameSession isEqualToString:@"0"]) {
|
if (launchResp == NULL) {
|
||||||
|
[_callbacks launchFailed:@"Failed to launch app"];
|
||||||
|
return FALSE;
|
||||||
|
} else if (gameSession == NULL || [gameSession isEqualToString:@"0"]) {
|
||||||
|
[_callbacks launchFailed:[HttpManager getStatusStringFromXML:launchResp]];
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,7 +102,11 @@
|
|||||||
[hMan newResumeRequestWithRiKey:[Utils bytesToHex:_config.riKey]
|
[hMan newResumeRequestWithRiKey:[Utils bytesToHex:_config.riKey]
|
||||||
riKeyId:_config.riKeyId]];
|
riKeyId:_config.riKeyId]];
|
||||||
NSString *resume = [HttpManager getStringFromXML:resumeResp tag:@"resume"];
|
NSString *resume = [HttpManager getStringFromXML:resumeResp tag:@"resume"];
|
||||||
if (resume == NULL || [resume isEqualToString:@"0"]) {
|
if (resumeResp == NULL) {
|
||||||
|
[_callbacks launchFailed:@"Failed to resume app"];
|
||||||
|
return FALSE;
|
||||||
|
} else if (resume == NULL || [resume isEqualToString:@"0"]) {
|
||||||
|
[_callbacks launchFailed:[HttpManager getStatusStringFromXML:resumeResp]];
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,9 +91,9 @@
|
|||||||
[self presentViewController:alert animated:YES completion:nil];
|
[self presentViewController:alert animated:YES completion:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) launchFailed {
|
- (void) launchFailed:(NSString*)message {
|
||||||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Connection Failed"
|
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Connection Failed"
|
||||||
message:@"Failed to start app"
|
message:message
|
||||||
preferredStyle:UIAlertControllerStyleAlert];
|
preferredStyle:UIAlertControllerStyleAlert];
|
||||||
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
[alert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
||||||
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
|
[self performSegueWithIdentifier:@"returnToMainFrame" sender:self];
|
||||||
|
|||||||
Reference in New Issue
Block a user