From fd50b71b16c93b0a8b1326d858b5172a66494c36 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 21 Oct 2016 11:41:42 -0700 Subject: [PATCH] Fix detection of running apps on GFE 3.1 --- Limelight/Database/TemporaryApp.h | 1 - Limelight/Database/TemporaryHost.h | 1 + Limelight/Database/TemporaryHost.m | 1 + Limelight/Network/AppListResponse.m | 11 ----------- Limelight/Network/ServerInfoResponse.h | 2 ++ Limelight/Network/ServerInfoResponse.m | 9 +++++++++ Limelight/UIAppView.m | 2 +- Limelight/ViewControllers/MainFrameViewController.m | 7 +++---- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Limelight/Database/TemporaryApp.h b/Limelight/Database/TemporaryApp.h index a004f3ba..15a8208a 100644 --- a/Limelight/Database/TemporaryApp.h +++ b/Limelight/Database/TemporaryApp.h @@ -15,7 +15,6 @@ @property (nullable, nonatomic, retain) NSString *id; @property (nullable, nonatomic, retain) NSData *image; @property (nullable, nonatomic, retain) NSString *name; -@property (nonatomic) BOOL isRunning; @property (nullable, nonatomic, retain) TemporaryHost *host; NS_ASSUME_NONNULL_BEGIN diff --git a/Limelight/Database/TemporaryHost.h b/Limelight/Database/TemporaryHost.h index d7620426..ffb5cdc5 100644 --- a/Limelight/Database/TemporaryHost.h +++ b/Limelight/Database/TemporaryHost.h @@ -15,6 +15,7 @@ @property (nonatomic) BOOL online; @property (nonatomic) PairState pairState; @property (nonatomic, nullable) NSString * activeAddress; +@property (nonatomic, nullable) NSString * currentGame; NS_ASSUME_NONNULL_BEGIN diff --git a/Limelight/Database/TemporaryHost.m b/Limelight/Database/TemporaryHost.m index 26f7e878..31c4d987 100644 --- a/Limelight/Database/TemporaryHost.m +++ b/Limelight/Database/TemporaryHost.m @@ -17,6 +17,7 @@ - (id) init { self = [super init]; self.appList = [[NSMutableSet alloc] init]; + self.currentGame = @"0"; return self; } diff --git a/Limelight/Network/AppListResponse.m b/Limelight/Network/AppListResponse.m index 51e408d8..ab6bc22f 100644 --- a/Limelight/Network/AppListResponse.m +++ b/Limelight/Network/AppListResponse.m @@ -19,7 +19,6 @@ static const char* TAG_APP = "App"; static const char* TAG_APP_TITLE = "AppTitle"; static const char* TAG_APP_ID = "ID"; -static const char* TAG_APP_IS_RUNNING = "IsRunning"; - (void)populateWithData:(NSData *)xml { self.data = xml; @@ -67,7 +66,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning"; xmlNodePtr appInfoNode = node->xmlChildrenNode; NSString* appName = @""; NSString* appId = nil; - BOOL appIsRunning = NO; while (appInfoNode != NULL) { if (!xmlStrcmp(appInfoNode->name, (xmlChar*)TAG_APP_TITLE)) { 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]; 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; } @@ -98,7 +88,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning"; TemporaryApp* app = [[TemporaryApp alloc] init]; app.name = appName; app.id = appId; - app.isRunning = appIsRunning; [_appList addObject:app]; } } diff --git a/Limelight/Network/ServerInfoResponse.h b/Limelight/Network/ServerInfoResponse.h index 445addbf..d9c0fc26 100644 --- a/Limelight/Network/ServerInfoResponse.h +++ b/Limelight/Network/ServerInfoResponse.h @@ -15,6 +15,8 @@ #define TAG_UNIQUE_ID @"uniqueid" #define TAG_MAC_ADDRESS @"mac" #define TAG_PAIR_STATUS @"PairStatus" +#define TAG_STATE @"state" +#define TAG_CURRENT_GAME @"currentgame" @interface ServerInfoResponse : HttpResponse diff --git a/Limelight/Network/ServerInfoResponse.m b/Limelight/Network/ServerInfoResponse.m index a69e3317..3faf632b 100644 --- a/Limelight/Network/ServerInfoResponse.m +++ b/Limelight/Network/ServerInfoResponse.m @@ -23,6 +23,15 @@ host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim]; host.uuid = [[self getStringTag:TAG_UNIQUE_ID] 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; if ([self getIntTag:TAG_PAIR_STATUS value:&pairStatus]) { diff --git a/Limelight/UIAppView.m b/Limelight/UIAppView.m index 5daefb62..9a006ef9 100644 --- a/Limelight/UIAppView.m +++ b/Limelight/UIAppView.m @@ -60,7 +60,7 @@ static UIImage* noImage; _appOverlay = nil; } - if (_app.isRunning) { + if ([_app.id isEqualToString:_app.host.currentGame]) { // Only create the app overlay if needed _appOverlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Play"]]; _appOverlay.layer.shadowColor = [UIColor blackColor].CGColor; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index ddf8bc5f..24043de2 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -166,7 +166,6 @@ static NSMutableSet* hostList; for (TemporaryApp* savedApp in host.appList) { if ([app.id isEqualToString:savedApp.id]) { savedApp.name = app.name; - savedApp.isRunning = app.isRunning; appAlreadyInList = YES; break; } @@ -441,7 +440,7 @@ static NSMutableSet* hostList; } // If it succeeds and we're to start streaming, segue to the stream and return else if (![app.id isEqualToString:currentApp.id]) { - currentApp.isRunning = NO; + app.host.currentGame = @"0"; dispatch_async(dispatch_get_main_queue(), ^{ [self updateAppsForHost:app.host]; @@ -452,7 +451,7 @@ static NSMutableSet* hostList; } // Otherwise, display a dialog to notify the user that the app was quit else { - currentApp.isRunning = NO; + app.host.currentGame = @"0"; alert = [UIAlertController alertControllerWithTitle:@"Quitting App" message:@"The app was quit successfully." @@ -475,7 +474,7 @@ static NSMutableSet* hostList; - (TemporaryApp*) findRunningApp:(TemporaryHost*)host { for (TemporaryApp* app in host.appList) { - if (app.isRunning) { + if ([app.id isEqualToString:host.currentGame]) { return app; } }