Files
moonlight-ios/Limelight/Network/AppAssetRetriever.m
Felix Kratz 6cc165b589 Port for macOS (#311)
* merged moonlight-mac with moonlight-ios

* reverted to the original project.pbxproj

* cleaned up the code, fixed lots of unnecessary code duplications

* multicontroller support (not tested)

* new class that can be used for further modularization of the MainFrameViewController
2018-03-26 23:50:40 -07:00

55 lines
1.5 KiB
Objective-C

//
// AppAssetRetriever.m
// Moonlight
//
// Created by Diego Waxemberg on 1/31/15.
// Copyright (c) 2015 Moonlight Stream. All rights reserved.
//
#import "AppAssetRetriever.h"
#import "HttpManager.h"
#import "CryptoManager.h"
#import "AppAssetResponse.h"
#import "HttpRequest.h"
#import "IdManager.h"
@implementation AppAssetRetriever
static const double RETRY_DELAY = 2; // seconds
static const int MAX_ATTEMPTS = 5;
- (void) main {
#if TARGET_OS_IPHONE
UIImage* appImage = nil;
#else
NSImage* appImage = nil;
#endif
int attempts = 0;
while (![self isCancelled] && appImage == nil && attempts++ < MAX_ATTEMPTS) {
HttpManager* hMan = [[HttpManager alloc] initWithHost:_host.activeAddress uniqueId:[IdManager getUniqueId] deviceName:deviceName cert:[CryptoManager readCertFromFile]];
AppAssetResponse* appAssetResp = [[AppAssetResponse alloc] init];
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appAssetResp withUrlRequest:[hMan newAppAssetRequestWithAppId:self.app.id]]];
#if TARGET_OS_IPHONE
appImage = [UIImage imageWithData:appAssetResp.data];
self.app.image = UIImagePNGRepresentation(appImage);
#else
#endif
if (![self isCancelled] && appImage == nil) {
[NSThread sleepForTimeInterval:RETRY_DELAY];
}
}
[self performSelectorOnMainThread:@selector(sendCallbackForApp:) withObject:self.app waitUntilDone:NO];
}
- (void) sendCallbackForApp:(TemporaryApp*)app {
[self.callback receivedAssetForApp:app];
}
@end