diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index 7ac8ef0..d83b3c0 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -21,6 +21,7 @@ - (void) updateAppsForExistingHost:(TemporaryHost *)host; - (void) updateIconForExistingApp:(TemporaryApp*)app; - (void) removeHost:(TemporaryHost*)host; +- (void) removeApp:(TemporaryApp*)app; - (TemporarySettings*) getSettings; diff --git a/Limelight/Database/DataManager.m b/Limelight/Database/DataManager.m index 18ade1a..67eb7da 100644 --- a/Limelight/Database/DataManager.m +++ b/Limelight/Database/DataManager.m @@ -140,6 +140,16 @@ } } +- (void) removeApp:(TemporaryApp*)app { + [_managedObjectContext performBlockAndWait:^{ + App* managedApp = [self getAppForTemporaryApp:app]; + if (managedApp != nil) { + [_managedObjectContext deleteObject:managedApp]; + [self saveData]; + } + }]; +} + - (void) removeHost:(TemporaryHost*)host { [_managedObjectContext performBlockAndWait:^{ Host* managedHost = [self getHostForTemporaryHost:host]; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 4da2f1b..2414959 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -195,6 +195,11 @@ static NSMutableSet* hostList; [host.appList removeObject:app]; + // It's important to remove the app record from the database + // since we'll have a constraint violation now that appList + // doesn't have this app in it. + [database removeApp:app]; + break; } }