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