Fix detection of running apps on GFE 3.1

This commit is contained in:
Cameron Gutman 2016-10-21 11:41:42 -07:00
parent 39ab472cf6
commit fd50b71b16
8 changed files with 17 additions and 17 deletions

View File

@ -15,7 +15,6 @@
@property (nullable, nonatomic, retain) NSString *id; @property (nullable, nonatomic, retain) NSString *id;
@property (nullable, nonatomic, retain) NSData *image; @property (nullable, nonatomic, retain) NSData *image;
@property (nullable, nonatomic, retain) NSString *name; @property (nullable, nonatomic, retain) NSString *name;
@property (nonatomic) BOOL isRunning;
@property (nullable, nonatomic, retain) TemporaryHost *host; @property (nullable, nonatomic, retain) TemporaryHost *host;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

View File

@ -15,6 +15,7 @@
@property (nonatomic) BOOL online; @property (nonatomic) BOOL online;
@property (nonatomic) PairState pairState; @property (nonatomic) PairState pairState;
@property (nonatomic, nullable) NSString * activeAddress; @property (nonatomic, nullable) NSString * activeAddress;
@property (nonatomic, nullable) NSString * currentGame;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN

View File

@ -17,6 +17,7 @@
- (id) init { - (id) init {
self = [super init]; self = [super init];
self.appList = [[NSMutableSet alloc] init]; self.appList = [[NSMutableSet alloc] init];
self.currentGame = @"0";
return self; return self;
} }

View File

@ -19,7 +19,6 @@
static const char* TAG_APP = "App"; static const char* TAG_APP = "App";
static const char* TAG_APP_TITLE = "AppTitle"; static const char* TAG_APP_TITLE = "AppTitle";
static const char* TAG_APP_ID = "ID"; static const char* TAG_APP_ID = "ID";
static const char* TAG_APP_IS_RUNNING = "IsRunning";
- (void)populateWithData:(NSData *)xml { - (void)populateWithData:(NSData *)xml {
self.data = xml; self.data = xml;
@ -67,7 +66,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
xmlNodePtr appInfoNode = node->xmlChildrenNode; xmlNodePtr appInfoNode = node->xmlChildrenNode;
NSString* appName = @""; NSString* appName = @"";
NSString* appId = nil; NSString* appId = nil;
BOOL appIsRunning = NO;
while (appInfoNode != NULL) { while (appInfoNode != NULL) {
if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) { if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) {
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1); xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
@ -83,14 +81,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
appId = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding]; appId = [[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding];
xmlFree(nodeVal); xmlFree(nodeVal);
} }
} else if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_IS_RUNNING)) {
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
if (nodeVal != NULL) {
appIsRunning = [[[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding] isEqualToString:@"1"];
xmlFree(nodeVal);
} else {
appIsRunning = NO;
}
} }
appInfoNode = appInfoNode->next; appInfoNode = appInfoNode->next;
} }
@ -98,7 +88,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
TemporaryApp* app = [[TemporaryApp alloc] init]; TemporaryApp* app = [[TemporaryApp alloc] init];
app.name = appName; app.name = appName;
app.id = appId; app.id = appId;
app.isRunning = appIsRunning;
[_appList addObject:app]; [_appList addObject:app];
} }
} }

View File

@ -15,6 +15,8 @@
#define TAG_UNIQUE_ID @"uniqueid" #define TAG_UNIQUE_ID @"uniqueid"
#define TAG_MAC_ADDRESS @"mac" #define TAG_MAC_ADDRESS @"mac"
#define TAG_PAIR_STATUS @"PairStatus" #define TAG_PAIR_STATUS @"PairStatus"
#define TAG_STATE @"state"
#define TAG_CURRENT_GAME @"currentgame"
@interface ServerInfoResponse : HttpResponse <Response> @interface ServerInfoResponse : HttpResponse <Response>

View File

@ -23,6 +23,15 @@
host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim]; host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim];
host.uuid = [[self getStringTag:TAG_UNIQUE_ID] trim]; host.uuid = [[self getStringTag:TAG_UNIQUE_ID] trim];
host.mac = [[self getStringTag:TAG_MAC_ADDRESS] trim]; host.mac = [[self getStringTag:TAG_MAC_ADDRESS] trim];
host.currentGame = [[self getStringTag:TAG_CURRENT_GAME] trim];
NSString *state = [[self getStringTag:TAG_STATE] trim];
if ([state hasSuffix:@"_SERVER_AVAILABLE"]) {
// GFE 2.8 started keeping currentgame set to the last game played. As a result, it no longer
// has the semantics that its name would indicate. To contain the effects of this change as much
// as possible, we'll force the current game to zero if the server isn't in a streaming session.
host.currentGame = @"0";
}
NSInteger pairStatus; NSInteger pairStatus;
if ([self getIntTag:TAG_PAIR_STATUS value:&pairStatus]) { if ([self getIntTag:TAG_PAIR_STATUS value:&pairStatus]) {

View File

@ -60,7 +60,7 @@ static UIImage* noImage;
_appOverlay = nil; _appOverlay = nil;
} }
if (_app.isRunning) { if ([_app.id isEqualToString:_app.host.currentGame]) {
// Only create the app overlay if needed // Only create the app overlay if needed
_appOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play"]]; _appOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play"]];
_appOverlay.layer.shadowColor = [UIColor blackColor].CGColor; _appOverlay.layer.shadowColor = [UIColor blackColor].CGColor;

View File

@ -166,7 +166,6 @@ static NSMutableSet* hostList;
for (TemporaryApp* savedApp in host.appList) { for (TemporaryApp* savedApp in host.appList) {
if ([app.id isEqualToString:savedApp.id]) { if ([app.id isEqualToString:savedApp.id]) {
savedApp.name = app.name; savedApp.name = app.name;
savedApp.isRunning = app.isRunning;
appAlreadyInList = YES; appAlreadyInList = YES;
break; break;
} }
@ -441,7 +440,7 @@ static NSMutableSet* hostList;
} }
// If it succeeds and we're to start streaming, segue to the stream and return // If it succeeds and we're to start streaming, segue to the stream and return
else if (![app.id isEqualToString:currentApp.id]) { else if (![app.id isEqualToString:currentApp.id]) {
currentApp.isRunning = NO; app.host.currentGame = @"0";
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[self updateAppsForHost:app.host]; [self updateAppsForHost:app.host];
@ -452,7 +451,7 @@ static NSMutableSet* hostList;
} }
// Otherwise, display a dialog to notify the user that the app was quit // Otherwise, display a dialog to notify the user that the app was quit
else { else {
currentApp.isRunning = NO; app.host.currentGame = @"0";
alert = [UIAlertController alertControllerWithTitle:@"Quitting App" alert = [UIAlertController alertControllerWithTitle:@"Quitting App"
message:@"The app was quit successfully." message:@"The app was quit successfully."
@ -475,7 +474,7 @@ static NSMutableSet* hostList;
- (TemporaryApp*) findRunningApp:(TemporaryHost*)host { - (TemporaryApp*) findRunningApp:(TemporaryHost*)host {
for (TemporaryApp* app in host.appList) { for (TemporaryApp* app in host.appList) {
if (app.isRunning) { if ([app.id isEqualToString:host.currentGame]) {
return app; return app;
} }
} }