mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-12 19:06:21 +00:00
now request app image on multiple threads
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "App.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Host.h"
|
||||
|
||||
@protocol AppAssetCallback <NSObject>
|
||||
|
||||
@@ -18,6 +19,8 @@
|
||||
|
||||
@interface AppManager : NSObject
|
||||
|
||||
+ (void) retrieveAppAssets:(NSArray*)apps withManager:(HttpManager*)hMan andCallback:(id<AppAssetCallback>)callback;
|
||||
- (id) initWithHost:(Host*)host andCallback:(id<AppAssetCallback>)callback;
|
||||
- (void) retrieveAssets:(NSArray*)appList;
|
||||
- (void) stopRetrieving;
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,39 +7,48 @@
|
||||
//
|
||||
|
||||
#import "AppManager.h"
|
||||
#import "CryptoManager.h"
|
||||
#import "Utils.h"
|
||||
|
||||
@implementation AppManager {
|
||||
App* _app;
|
||||
HttpManager* _hMan;
|
||||
NSOperationQueue* opQueue;
|
||||
id<AppAssetCallback> _callback;
|
||||
Host* _host;
|
||||
NSString* _uniqueId;
|
||||
NSData* _cert;
|
||||
}
|
||||
|
||||
+ (void) retrieveAppAssets:(NSArray*)apps withManager:(HttpManager*)hMan andCallback:(id<AppAssetCallback>)callback {
|
||||
for (App* app in apps) {
|
||||
AppManager* manager = [[AppManager alloc] initWithApp:app httpManager:hMan andCallback:callback];
|
||||
[manager retrieveAsset];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
- (id) initWithApp:(App*)app httpManager:(HttpManager*)hMan andCallback:(id<AppAssetCallback>)callback {
|
||||
- (id) initWithHost:(Host*)host andCallback:(id<AppAssetCallback>)callback {
|
||||
self = [super init];
|
||||
_app = app;
|
||||
_hMan = hMan;
|
||||
_callback = callback;
|
||||
_host = host;
|
||||
opQueue = [[NSOperationQueue alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) retrieveAsset {
|
||||
NSData* appAsset = [_hMan executeRequestSynchronously:[_hMan newAppAssetRequestWithAppId:_app.appId]];
|
||||
UIImage* appImage = [UIImage imageWithData:appAsset];
|
||||
_app.appImage = appImage;
|
||||
NSLog(@"App Name: %@ id:%@ image: %@", _app.appName, _app.appId, _app.appImage);
|
||||
[self performSelectorOnMainThread:@selector(sendCallBack) withObject:self waitUntilDone:NO];
|
||||
- (void) retrieveAssets:(NSArray*)appList {
|
||||
for (App* app in appList) {
|
||||
[opQueue addOperationWithBlock:^{
|
||||
[self retrieveAssetForApp:app];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) sendCallBack {
|
||||
[_callback receivedAssetForApp:_app];
|
||||
- (void) stopRetrieving {
|
||||
[opQueue cancelAllOperations];
|
||||
}
|
||||
|
||||
- (void) retrieveAssetForApp:(App*)app {
|
||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.address uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||
NSData* appAsset = [hMan executeRequestSynchronously:[hMan newAppAssetRequestWithAppId:app.appId]];
|
||||
UIImage* appImage = [UIImage imageWithData:appAsset];
|
||||
app.appImage = appImage;
|
||||
NSLog(@"App Name: %@ id:%@ image: %@", app.appName, app.appId, app.appImage);
|
||||
[self performSelectorOnMainThread:@selector(sendCallBackForApp:) withObject:app waitUntilDone:NO];
|
||||
}
|
||||
|
||||
- (void) sendCallBackForApp:(App*)app {
|
||||
[_callback receivedAssetForApp:app];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
NSData* _cert;
|
||||
NSString* _currentGame;
|
||||
DiscoveryManager* _discMan;
|
||||
AppManager* _appManager;
|
||||
UIAlertView* _pairAlert;
|
||||
UIScrollView* hostScrollView;
|
||||
int currentPosition;
|
||||
@@ -77,7 +78,11 @@ static StreamConfiguration* streamConfig;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self updateApps];
|
||||
});
|
||||
[AppManager retrieveAppAssets:appList withManager:hMan andCallback:self];
|
||||
if (_appManager != nil) {
|
||||
[_appManager stopRetrieving];
|
||||
}
|
||||
_appManager = [[AppManager alloc] initWithHost:_selectedHost andCallback:self];
|
||||
[_appManager retrieveAssets:appList];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user