mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2025-07-04 00:36:23 +00:00
fixed issue with apps duplicating in app list
This commit is contained in:
parent
8f12114a56
commit
9c6b718be2
@ -19,9 +19,10 @@
|
|||||||
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls;
|
- (void) saveSettingsWithBitrate:(NSInteger)bitrate framerate:(NSInteger)framerate height:(NSInteger)height width:(NSInteger)width onscreenControls:(NSInteger)onscreenControls;
|
||||||
- (Settings*) retrieveSettings;
|
- (Settings*) retrieveSettings;
|
||||||
- (NSArray*) retrieveHosts;
|
- (NSArray*) retrieveHosts;
|
||||||
- (void) saveHosts;
|
- (void) saveData;
|
||||||
- (Host*) createHost;
|
- (Host*) createHost;
|
||||||
- (void) removeHost:(Host*)host;
|
- (void) removeHost:(Host*)host;
|
||||||
- (App*) createApp;
|
- (App*) createApp;
|
||||||
|
- (void) removeApp:(App*)app;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -53,10 +53,10 @@
|
|||||||
|
|
||||||
- (void) removeHost:(Host*)host {
|
- (void) removeHost:(Host*)host {
|
||||||
[[self.appDelegate managedObjectContext] deleteObject:host];
|
[[self.appDelegate managedObjectContext] deleteObject:host];
|
||||||
[self saveHosts];
|
[self saveData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) saveHosts {
|
- (void) saveData {
|
||||||
NSError* error;
|
NSError* error;
|
||||||
if (![[self.appDelegate managedObjectContext] save:&error]) {
|
if (![[self.appDelegate managedObjectContext] save:&error]) {
|
||||||
Log(LOG_E, @"Unable to save hosts to database: %@", error);
|
Log(LOG_E, @"Unable to save hosts to database: %@", error);
|
||||||
@ -73,6 +73,10 @@
|
|||||||
return [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
|
return [[App alloc] initWithEntity:entity insertIntoManagedObjectContext:[self.appDelegate managedObjectContext]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) removeApp:(App*)app {
|
||||||
|
[[self.appDelegate managedObjectContext] deleteObject:app];
|
||||||
|
}
|
||||||
|
|
||||||
- (NSArray*) fetchRecords:(NSString*)entityName {
|
- (NSArray*) fetchRecords:(NSString*)entityName {
|
||||||
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
|
NSFetchRequest* fetchRequest = [[NSFetchRequest alloc] init];
|
||||||
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]];
|
NSEntityDescription* entity = [NSEntityDescription entityForName:entityName inManagedObjectContext:[self.appDelegate managedObjectContext]];
|
||||||
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
@interface AppListResponse : NSObject <Response>
|
@interface AppListResponse : NSObject <Response>
|
||||||
|
|
||||||
@property Host* host;
|
|
||||||
|
|
||||||
- (void)populateWithData:(NSData *)data;
|
- (void)populateWithData:(NSData *)data;
|
||||||
- (NSArray*) getAppList;
|
- (NSArray*) getAppList;
|
||||||
- (BOOL) isStatusOk;
|
- (BOOL) isStatusOk;
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
@implementation AppListResponse {
|
@implementation AppListResponse {
|
||||||
NSMutableArray* _appList;
|
NSMutableArray* _appList;
|
||||||
}
|
}
|
||||||
@synthesize data, statusCode, statusMessage, host;
|
@synthesize data, statusCode, statusMessage;
|
||||||
|
|
||||||
static const char* TAG_APP = "App";
|
static const char* TAG_APP = "App";
|
||||||
static const char* TAG_APP_TITLE = "AppTitle";
|
static const char* TAG_APP_TITLE = "AppTitle";
|
||||||
@ -99,7 +99,6 @@ static const char* TAG_APP_IS_RUNNING = "IsRunning";
|
|||||||
App* app = [dataMan createApp];
|
App* app = [dataMan createApp];
|
||||||
app.name = appName;
|
app.name = appName;
|
||||||
app.id = appId;
|
app.id = appId;
|
||||||
app.host = host;
|
|
||||||
app.isRunning = appIsRunning;
|
app.isRunning = appIsRunning;
|
||||||
[_appList addObject:app];
|
[_appList addObject:app];
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@
|
|||||||
[dataMan removeHost:host];
|
[dataMan removeHost:host];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[dataMan saveHosts];
|
[dataMan saveData];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,6 @@ static NSMutableSet* hostList;
|
|||||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.activeAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||||
|
|
||||||
AppListResponse* appListResp = [[AppListResponse alloc] init];
|
AppListResponse* appListResp = [[AppListResponse alloc] init];
|
||||||
appListResp.host = _selectedHost;
|
|
||||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
|
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:appListResp withUrlRequest:[hMan newAppListRequest]]];
|
||||||
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
|
if (appListResp == nil || ![appListResp isStatusOk] || [appListResp getAppList] == nil) {
|
||||||
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
|
Log(LOG_W, @"Failed to get applist: %@", appListResp.statusMessage);
|
||||||
@ -118,6 +117,7 @@ static NSMutableSet* hostList;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void) mergeAppLists:(NSArray*) newList {
|
- (void) mergeAppLists:(NSArray*) newList {
|
||||||
|
DataManager* database = [[DataManager alloc] init];
|
||||||
for (App* app in newList) {
|
for (App* app in newList) {
|
||||||
BOOL appAlreadyInList = NO;
|
BOOL appAlreadyInList = NO;
|
||||||
for (App* savedApp in _selectedHost.appList) {
|
for (App* savedApp in _selectedHost.appList) {
|
||||||
@ -129,6 +129,8 @@ static NSMutableSet* hostList;
|
|||||||
if (!appAlreadyInList) {
|
if (!appAlreadyInList) {
|
||||||
app.host = _selectedHost;
|
app.host = _selectedHost;
|
||||||
[_selectedHost addAppListObject:app];
|
[_selectedHost addAppListObject:app];
|
||||||
|
} else {
|
||||||
|
[database removeApp:app];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,13 +144,15 @@ static NSMutableSet* hostList;
|
|||||||
}
|
}
|
||||||
if (appWasRemoved) {
|
if (appWasRemoved) {
|
||||||
[_selectedHost removeAppListObject:app];
|
[_selectedHost removeAppListObject:app];
|
||||||
|
[database removeApp:app];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[database saveData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)showHostSelectionView {
|
- (void)showHostSelectionView {
|
||||||
[_appManager stopRetrieving];
|
[_appManager stopRetrieving];
|
||||||
[[[DataManager alloc] init] saveHosts];
|
[[[DataManager alloc] init] saveData];
|
||||||
_selectedHost = nil;
|
_selectedHost = nil;
|
||||||
_computerNameButton.title = @"No Host Selected";
|
_computerNameButton.title = @"No Host Selected";
|
||||||
[self.collectionView reloadData];
|
[self.collectionView reloadData];
|
||||||
@ -265,7 +269,7 @@ static NSMutableSet* hostList;
|
|||||||
[_discMan discoverHost:hostAddress withCallback:^(Host* host, NSString* error){
|
[_discMan discoverHost:hostAddress withCallback:^(Host* host, NSString* error){
|
||||||
if (host != nil) {
|
if (host != nil) {
|
||||||
DataManager* dataMan = [[DataManager alloc] init];
|
DataManager* dataMan = [[DataManager alloc] init];
|
||||||
[dataMan saveHosts];
|
[dataMan saveData];
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
@synchronized(hostList) {
|
@synchronized(hostList) {
|
||||||
[hostList addObject:host];
|
[hostList addObject:host];
|
||||||
@ -472,7 +476,7 @@ static NSMutableSet* hostList;
|
|||||||
[_discMan stopDiscovery];
|
[_discMan stopDiscovery];
|
||||||
|
|
||||||
// In case the host objects were updated in the background
|
// In case the host objects were updated in the background
|
||||||
[[[DataManager alloc] init] saveHosts];
|
[[[DataManager alloc] init] saveData];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) retrieveSavedHosts {
|
- (void) retrieveSavedHosts {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user