mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-15 21:21:45 +00:00
Preserve app art when updating the app list
This commit is contained in:
@@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
- (NSArray*) getHosts;
|
- (NSArray*) getHosts;
|
||||||
- (void) updateHost:(TemporaryHost*)host;
|
- (void) updateHost:(TemporaryHost*)host;
|
||||||
|
- (void) updateAppsForExistingHost:(TemporaryHost *)host;
|
||||||
|
- (void) updateIconForExistingApp:(TemporaryApp*)app;
|
||||||
- (void) removeHost:(TemporaryHost*)host;
|
- (void) removeHost:(TemporaryHost*)host;
|
||||||
|
|
||||||
- (TemporarySettings*) getSettings;
|
- (TemporarySettings*) getSettings;
|
||||||
@@ -25,7 +27,4 @@
|
|||||||
- (void) updateUniqueId:(NSString*)uniqueId;
|
- (void) updateUniqueId:(NSString*)uniqueId;
|
||||||
- (NSString*) getUniqueId;
|
- (NSString*) getUniqueId;
|
||||||
|
|
||||||
// Don't call this outside of database code
|
|
||||||
- (App*) getAppForTemporaryApp:(TemporaryApp*)tempApp;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -68,7 +68,49 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Push changes from the temp host to the persistent one
|
// Push changes from the temp host to the persistent one
|
||||||
[host propagateChangesToParent:parent withDm:self];
|
[host propagateChangesToParent:parent];
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateAppsForExistingHost:(TemporaryHost *)host {
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
Host* parent = [self getHostForTemporaryHost:host];
|
||||||
|
if (parent == nil) {
|
||||||
|
// The host must exist to be updated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMutableSet *applist = [[NSMutableSet alloc] init];
|
||||||
|
for (TemporaryApp* app in host.appList) {
|
||||||
|
// Add a new persistent managed object if one doesn't exist
|
||||||
|
App* parentApp = [self getAppForTemporaryApp:app];
|
||||||
|
if (parentApp == nil) {
|
||||||
|
NSEntityDescription* entity = [NSEntityDescription entityForName:@"App" inManagedObjectContext:_managedObjectContext];
|
||||||
|
parentApp = [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:_managedObjectContext];
|
||||||
|
}
|
||||||
|
|
||||||
|
[app propagateChangesToParent:parentApp withHost:parent];
|
||||||
|
|
||||||
|
[applist addObject:parentApp];
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.appList = applist;
|
||||||
|
|
||||||
|
[self saveData];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) updateIconForExistingApp:(TemporaryApp*)app {
|
||||||
|
[_managedObjectContext performBlockAndWait:^{
|
||||||
|
App* parentApp = [self getAppForTemporaryApp:app];
|
||||||
|
if (parentApp == nil) {
|
||||||
|
// The app must exist to be updated
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentApp.image = app.image;
|
||||||
|
|
||||||
[self saveData];
|
[self saveData];
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
- (void) propagateChangesToParent:(App*)parent withHost:(Host*)host {
|
- (void) propagateChangesToParent:(App*)parent withHost:(Host*)host {
|
||||||
parent.id = self.id;
|
parent.id = self.id;
|
||||||
parent.image = self.image;
|
|
||||||
parent.name = self.name;
|
parent.name = self.name;
|
||||||
parent.host = host;
|
parent.host = host;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,6 @@
|
|||||||
#import "Utils.h"
|
#import "Utils.h"
|
||||||
#import "Host.h"
|
#import "Host.h"
|
||||||
|
|
||||||
@class DataManager;
|
|
||||||
|
|
||||||
@interface TemporaryHost : NSObject
|
@interface TemporaryHost : NSObject
|
||||||
|
|
||||||
@property (nonatomic) BOOL online;
|
@property (nonatomic) BOOL online;
|
||||||
@@ -26,13 +24,13 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
@property (nonatomic, retain) NSString *mac;
|
@property (nonatomic, retain) NSString *mac;
|
||||||
@property (nonatomic, retain) NSString *name;
|
@property (nonatomic, retain) NSString *name;
|
||||||
@property (nonatomic, retain) NSString *uuid;
|
@property (nonatomic, retain) NSString *uuid;
|
||||||
@property (nonatomic, retain) NSSet *appList;
|
@property (nonatomic, retain) NSMutableSet *appList;
|
||||||
|
|
||||||
- (id) initFromHost:(Host*)host;
|
- (id) initFromHost:(Host*)host;
|
||||||
|
|
||||||
- (NSComparisonResult)compareName:(TemporaryHost *)other;
|
- (NSComparisonResult)compareName:(TemporaryHost *)other;
|
||||||
|
|
||||||
- (void) propagateChangesToParent:(Host*)host withDm:(DataManager*)dm;
|
- (void) propagateChangesToParent:(Host*)host;
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) propagateChangesToParent:(Host*)parentHost withDm:(DataManager*)dm {
|
- (void) propagateChangesToParent:(Host*)parentHost {
|
||||||
parentHost.address = self.address;
|
parentHost.address = self.address;
|
||||||
parentHost.externalAddress = self.externalAddress;
|
parentHost.externalAddress = self.externalAddress;
|
||||||
parentHost.localAddress = self.localAddress;
|
parentHost.localAddress = self.localAddress;
|
||||||
@@ -45,22 +45,6 @@
|
|||||||
parentHost.name = self.name;
|
parentHost.name = self.name;
|
||||||
parentHost.uuid = self.uuid;
|
parentHost.uuid = self.uuid;
|
||||||
parentHost.pairState = [NSNumber numberWithInt:self.pairState];
|
parentHost.pairState = [NSNumber numberWithInt:self.pairState];
|
||||||
|
|
||||||
NSMutableSet *applist = [[NSMutableSet alloc] init];
|
|
||||||
for (TemporaryApp* app in self.appList) {
|
|
||||||
// Add a new persistent managed object if one doesn't exist
|
|
||||||
App* parentApp = [dm getAppForTemporaryApp:app];
|
|
||||||
if (parentApp == nil) {
|
|
||||||
NSEntityDescription* entity = [NSEntityDescription entityForName:@"App" inManagedObjectContext:parentHost.managedObjectContext];
|
|
||||||
parentApp = [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:parentHost.managedObjectContext];
|
|
||||||
}
|
|
||||||
|
|
||||||
[app propagateChangesToParent:parentApp withHost:parentHost];
|
|
||||||
|
|
||||||
[applist addObject:parentApp];
|
|
||||||
}
|
|
||||||
|
|
||||||
parentHost.appList = applist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSComparisonResult)compareName:(TemporaryHost *)other {
|
- (NSComparisonResult)compareName:(TemporaryHost *)other {
|
||||||
|
|||||||
@@ -161,9 +161,48 @@ static NSMutableSet* hostList;
|
|||||||
- (void) updateApplist:(NSSet*) newList forHost:(TemporaryHost*)host {
|
- (void) updateApplist:(NSSet*) newList forHost:(TemporaryHost*)host {
|
||||||
DataManager* database = [[DataManager alloc] init];
|
DataManager* database = [[DataManager alloc] init];
|
||||||
|
|
||||||
host.appList = newList;
|
for (TemporaryApp* app in newList) {
|
||||||
|
BOOL appAlreadyInList = NO;
|
||||||
|
for (TemporaryApp* savedApp in host.appList) {
|
||||||
|
if ([app.id isEqualToString:savedApp.id]) {
|
||||||
|
savedApp.name = app.name;
|
||||||
|
savedApp.isRunning = app.isRunning;
|
||||||
|
appAlreadyInList = YES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!appAlreadyInList) {
|
||||||
|
app.host = host;
|
||||||
|
[host.appList addObject:app];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL appWasRemoved;
|
||||||
|
do {
|
||||||
|
appWasRemoved = NO;
|
||||||
|
|
||||||
|
for (TemporaryApp* app in host.appList) {
|
||||||
|
appWasRemoved = YES;
|
||||||
|
for (TemporaryApp* mergedApp in newList) {
|
||||||
|
if ([mergedApp.id isEqualToString:app.id]) {
|
||||||
|
appWasRemoved = NO;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (appWasRemoved) {
|
||||||
|
// Removing the app mutates the list we're iterating (which isn't legal).
|
||||||
|
// We need to jump out of this loop and restart enumeration.
|
||||||
|
|
||||||
|
[host.appList removeObject:app];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep looping until the list is no longer being mutated
|
||||||
|
} while (appWasRemoved);
|
||||||
|
|
||||||
[database updateHost:host];
|
[database updateAppsForExistingHost:host];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showHostSelectionView {
|
- (void)showHostSelectionView {
|
||||||
@@ -179,6 +218,9 @@ static NSMutableSet* hostList;
|
|||||||
// on the main thread
|
// on the main thread
|
||||||
[self updateBoxArtCacheForApp:app];
|
[self updateBoxArtCacheForApp:app];
|
||||||
|
|
||||||
|
DataManager* dataManager = [[DataManager alloc] init];
|
||||||
|
[dataManager updateIconForExistingApp: app];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[self.collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user