mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-15 21:21:45 +00:00
added quitting an app
This commit is contained in:
@@ -13,5 +13,6 @@
|
|||||||
@property NSString* appId;
|
@property NSString* appId;
|
||||||
@property NSString* appName;
|
@property NSString* appName;
|
||||||
@property UIImage* appImage;
|
@property UIImage* appImage;
|
||||||
|
@property BOOL isRunning;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
+1
-1
@@ -10,6 +10,6 @@
|
|||||||
#import "HttpManager.h"
|
#import "HttpManager.h"
|
||||||
|
|
||||||
@implementation App
|
@implementation App
|
||||||
@synthesize appId, appName, appImage;
|
@synthesize appId, appName, appImage, isRunning;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
- (NSURLRequest*) newServerInfoRequest;
|
- (NSURLRequest*) newServerInfoRequest;
|
||||||
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid;
|
- (NSURLRequest*) newLaunchRequest:(NSString*)appId width:(int)width height:(int)height refreshRate:(int)refreshRate rikey:(NSString*)rikey rikeyid:(int)rikeyid;
|
||||||
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId;
|
- (NSURLRequest*) newResumeRequestWithRiKey:(NSString*)riKey riKeyId:(int)riKeyId;
|
||||||
|
- (NSURLRequest*) newQuitAppRequest;
|
||||||
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString*)appId;
|
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString*)appId;
|
||||||
- (NSData*) executeRequestSynchronously:(NSURLRequest*)request;
|
- (NSData*) executeRequestSynchronously:(NSURLRequest*)request;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ static const NSString* PORT = @"47984";
|
|||||||
xmlNodePtr appInfoNode = node->xmlChildrenNode;
|
xmlNodePtr appInfoNode = node->xmlChildrenNode;
|
||||||
NSString* appName;
|
NSString* appName;
|
||||||
NSString* appId;
|
NSString* appId;
|
||||||
|
BOOL appIsRunning = NO;
|
||||||
while (appInfoNode != NULL) {
|
while (appInfoNode != NULL) {
|
||||||
NSLog(@"appInfoNode: %s", appInfoNode->name);
|
NSLog(@"appInfoNode: %s", appInfoNode->name);
|
||||||
if (!xmlStrcmp(appInfoNode->name, (const xmlChar*)"AppTitle")) {
|
if (!xmlStrcmp(appInfoNode->name, (const xmlChar*)"AppTitle")) {
|
||||||
@@ -64,12 +65,17 @@ static const NSString* PORT = @"47984";
|
|||||||
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
||||||
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, (const xmlChar*)"IsRunning")) {
|
||||||
|
xmlChar* nodeVal = xmlNodeListGetString(docPtr, appInfoNode->xmlChildrenNode, 1);
|
||||||
|
appIsRunning = [[[NSString alloc] initWithCString:(const char*)nodeVal encoding:NSUTF8StringEncoding] isEqualToString:@"1"];
|
||||||
|
xmlFree(nodeVal);
|
||||||
}
|
}
|
||||||
appInfoNode = appInfoNode->next;
|
appInfoNode = appInfoNode->next;
|
||||||
}
|
}
|
||||||
App* app = [[App alloc] init];
|
App* app = [[App alloc] init];
|
||||||
app.appName = appName;
|
app.appName = appName;
|
||||||
app.appId = appId;
|
app.appId = appId;
|
||||||
|
app.isRunning = appIsRunning;
|
||||||
[appList addObject:app];
|
[appList addObject:app];
|
||||||
}
|
}
|
||||||
node = node->next;
|
node = node->next;
|
||||||
@@ -254,6 +260,11 @@ static const NSString* PORT = @"47984";
|
|||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSURLRequest*) newQuitAppRequest {
|
||||||
|
NSString* urlString = [NSString stringWithFormat:@"%@/cancel?uniqueid=%@", _baseURL, _uniqueId];
|
||||||
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString *)appId {
|
- (NSURLRequest*) newAppAssetRequestWithAppId:(NSString *)appId {
|
||||||
NSString* urlString = [NSString stringWithFormat:@"%@/appasset?uniqueid=%@&appid=%@&AssetType=2&AssetIdx=0", _baseURL, _uniqueId, appId];
|
NSString* urlString = [NSString stringWithFormat:@"%@/appasset?uniqueid=%@&appid=%@&AssetType=2&AssetIdx=0", _baseURL, _uniqueId, appId];
|
||||||
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
return [self createRequestFromString:urlString enableTimeout:FALSE];
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
Computer* _selectedHost;
|
Computer* _selectedHost;
|
||||||
NSString* _uniqueId;
|
NSString* _uniqueId;
|
||||||
NSData* _cert;
|
NSData* _cert;
|
||||||
|
NSString* _currentGame;
|
||||||
|
|
||||||
UIAlertView* _pairAlert;
|
UIAlertView* _pairAlert;
|
||||||
UIScrollView* hostScrollView;
|
UIScrollView* hostScrollView;
|
||||||
@@ -65,7 +66,6 @@ static StreamConfiguration* streamConfig;
|
|||||||
|
|
||||||
- (void)alreadyPaired {
|
- (void)alreadyPaired {
|
||||||
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.hostName uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.hostName uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
NSData* appListResp = [hMan executeRequestSynchronously:[hMan newAppListRequest]];
|
NSData* appListResp = [hMan executeRequestSynchronously:[hMan newAppListRequest]];
|
||||||
appList = [HttpManager getAppListFromXML:appListResp];
|
appList = [HttpManager getAppListFromXML:appListResp];
|
||||||
@@ -73,6 +73,7 @@ static StreamConfiguration* streamConfig;
|
|||||||
[self updateApps];
|
[self updateApps];
|
||||||
_computerNameButton.title = _selectedHost.displayName;
|
_computerNameButton.title = _selectedHost.displayName;
|
||||||
});
|
});
|
||||||
|
|
||||||
[AppManager retrieveAppAssets:appList withManager:hMan andCallback:self];
|
[AppManager retrieveAppAssets:appList withManager:hMan andCallback:self];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -157,7 +158,53 @@ static StreamConfiguration* streamConfig;
|
|||||||
if (currentPosition != FrontViewPositionLeft) {
|
if (currentPosition != FrontViewPositionLeft) {
|
||||||
[[self revealViewController] revealToggle:self];
|
[[self revealViewController] revealToggle:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App* currentApp = [self findRunningApp];
|
||||||
|
if (currentApp != nil) {
|
||||||
|
UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"App Already Running" message:[NSString stringWithFormat:@"%@ is currently running", currentApp.appName] preferredStyle:UIAlertControllerStyleAlert];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Resume App" style:UIAlertActionStyleDefault handler:^(UIAlertAction* action){
|
||||||
|
NSLog(@"Resuming application: %@", currentApp.appName);
|
||||||
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
|
}]];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Quit App" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){
|
||||||
|
NSLog(@"Quitting application: %@", currentApp.appName);
|
||||||
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||||
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.hostName uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
|
[hMan executeRequestSynchronously:[hMan newQuitAppRequest]];
|
||||||
|
// TODO: handle failure to quit app
|
||||||
|
currentApp.isRunning = NO;
|
||||||
|
|
||||||
|
if (![app.appId isEqualToString:currentApp.appId]) {
|
||||||
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}]];
|
||||||
|
[alertController addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
|
||||||
|
[self presentViewController:alertController animated:YES completion:nil];
|
||||||
|
} else {
|
||||||
|
[self performSegueWithIdentifier:@"createStreamFrame" sender:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (App*) findRunningApp {
|
||||||
|
for (App* app in appList) {
|
||||||
|
if (app.isRunning) {
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (App*) findAppInAppList:(NSString*)appId {
|
||||||
|
for (App* app in appList) {
|
||||||
|
if ([app.appId isEqualToString:appId]) {
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position {
|
- (void)revealController:(SWRevealViewController *)revealController didMoveToPosition:(FrontViewPosition)position {
|
||||||
@@ -222,6 +269,11 @@ static StreamConfiguration* streamConfig;
|
|||||||
|
|
||||||
_mDNSManager = [[MDNSManager alloc] initWithCallback:self];
|
_mDNSManager = [[MDNSManager alloc] initWithCallback:self];
|
||||||
[_mDNSManager searchForHosts];
|
[_mDNSManager searchForHosts];
|
||||||
|
|
||||||
|
// This will refresh the applist
|
||||||
|
if (_selectedHost != nil) {
|
||||||
|
[self hostClicked:_selectedHost];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidDisappear:(BOOL)animated
|
- (void)viewDidDisappear:(BOOL)animated
|
||||||
|
|||||||
Reference in New Issue
Block a user