mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-04-03 06:26:09 +00:00
fixed some bugs with saving app list to database
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="8118.17" systemVersion="15A204h" minimumToolsVersion="Automatic">
|
||||
<entity name="App" representedClassName="App" syncable="YES">
|
||||
<attribute name="id" attributeType="String" syncable="YES"/>
|
||||
<attribute name="image" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||
<attribute name="image" optional="YES" attributeType="Binary" allowsExternalBinaryDataStorage="YES" syncable="YES"/>
|
||||
<attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
|
||||
<relationship name="host" maxCount="1" deletionRule="Nullify" destinationEntity="Host" inverseName="appList" inverseEntity="Host" syncable="YES"/>
|
||||
</entity>
|
||||
@@ -24,7 +24,7 @@
|
||||
<attribute name="width" attributeType="Integer 32" defaultValueString="1280" syncable="YES"/>
|
||||
</entity>
|
||||
<elements>
|
||||
<element name="App" positionX="0" positionY="54" width="128" height="103"/>
|
||||
<element name="App" positionX="0" positionY="54" width="128" height="105"/>
|
||||
<element name="Host" positionX="0" positionY="0" width="128" height="163"/>
|
||||
<element name="Settings" positionX="0" positionY="0" width="128" height="120"/>
|
||||
</elements>
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
|
||||
@interface AppListResponse : NSObject <Response>
|
||||
|
||||
@property Host* host;
|
||||
|
||||
- (void)populateWithData:(NSData *)data;
|
||||
- (NSArray*) getAppList;
|
||||
- (BOOL) isStatusOk;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
@implementation AppListResponse {
|
||||
NSMutableArray* _appList;
|
||||
}
|
||||
@synthesize data, statusCode, statusMessage;
|
||||
@synthesize data, statusCode, statusMessage, host;
|
||||
|
||||
static const char* TAG_APP = "App";
|
||||
static const char* TAG_APP_TITLE = "AppTitle";
|
||||
@@ -98,6 +98,7 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
||||
App* app = [dataMan createApp];
|
||||
app.name = appName;
|
||||
app.id = appId;
|
||||
app.host = host;
|
||||
app.isRunning = appIsRunning;
|
||||
if (app.id != nil) {
|
||||
[_appList addObject:app];
|
||||
|
||||
@@ -72,10 +72,10 @@ static NSArray* appList;
|
||||
|
||||
- (void)alreadyPaired {
|
||||
BOOL usingCachedAppList = false;
|
||||
if (_selectedHost.appList != nil) {
|
||||
if ([_selectedHost.appList count] > 0) {
|
||||
usingCachedAppList = true;
|
||||
appList = [_selectedHost.appList allObjects];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
appList = [_selectedHost.appList allObjects];
|
||||
_computerNameButton.title = _selectedHost.name;
|
||||
[self.navigationController.navigationBar setNeedsLayout];
|
||||
[self updateApps];
|
||||
@@ -87,6 +87,7 @@ static NSArray* appList;
|
||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||
|
||||
AppListResponse* appListResp = [[AppListResponse alloc] init];
|
||||
appListResp.host = _selectedHost;
|
||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
|
||||
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
|
||||
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
|
||||
@@ -101,10 +102,6 @@ static NSArray* appList;
|
||||
[self showHostSelectionView];
|
||||
});
|
||||
} else {
|
||||
if (!usingCachedAppList) {
|
||||
appList = [[NSArray alloc] init];
|
||||
[_selectedHost addAppList:[NSSet setWithArray:appList]];
|
||||
}
|
||||
[self mergeAppLists:[appListResp getAppList]];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -122,17 +119,31 @@ static NSArray* appList;
|
||||
}
|
||||
|
||||
- (void) mergeAppLists:(NSArray*) newList {
|
||||
NSMutableArray* mergedList = [NSMutableArray arrayWithArray:appList];
|
||||
NSMutableArray* mergedList = [[NSMutableArray alloc] init];
|
||||
for (App* app in newList) {
|
||||
BOOL appAlreadyInList = NO;
|
||||
for (App* savedApp in mergedList) {
|
||||
if (app.id == savedApp.id) {
|
||||
for (App* savedApp in appList) {
|
||||
if ([app.id isEqualToString:savedApp.id]) {
|
||||
appAlreadyInList = YES;
|
||||
[mergedList addObject:savedApp];
|
||||
}
|
||||
}
|
||||
if (!appAlreadyInList) {
|
||||
[mergedList addObject:app];
|
||||
[_selectedHost addAppListObject:app];
|
||||
app.host = _selectedHost;
|
||||
}
|
||||
}
|
||||
|
||||
for (App* app in appList) {
|
||||
BOOL appWasRemoved = YES;
|
||||
for (App* mergedApp in mergedList) {
|
||||
if ([mergedApp.id isEqualToString:app.id]) {
|
||||
appWasRemoved = NO;
|
||||
}
|
||||
}
|
||||
if (appWasRemoved) {
|
||||
[_selectedHost removeAppListObject:app];
|
||||
}
|
||||
}
|
||||
appList = mergedList;
|
||||
|
||||
Reference in New Issue
Block a user