diff options
author | rowanbeentje <rowan@beent.je> | 2012-06-23 00:11:30 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2012-06-23 00:11:30 +0000 |
commit | 7d06e2efcc6874ac0a605920fdd62ec8cc433602 (patch) | |
tree | 0d72154ab0243764a60c731a26c9b790d59a0581 /Source/SPFavoritesController.m | |
parent | bc51d59ca9a5ec8a741eef8142d3224a02461a5a (diff) | |
download | sequelpro-7d06e2efcc6874ac0a605920fdd62ec8cc433602.tar.gz sequelpro-7d06e2efcc6874ac0a605920fdd62ec8cc433602.tar.bz2 sequelpro-7d06e2efcc6874ac0a605920fdd62ec8cc433602.zip |
Further improvements to further address Issue #1332:
- Ensure that favourites are saved synchronously on exit to avoid background threads being killed
- Improve logging on favourite rename error
- Only save favourites on exit if a connection window is open
Diffstat (limited to 'Source/SPFavoritesController.m')
-rw-r--r-- | Source/SPFavoritesController.m | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Source/SPFavoritesController.m b/Source/SPFavoritesController.m index da8be7c6..4e1ccdef 100644 --- a/Source/SPFavoritesController.m +++ b/Source/SPFavoritesController.m @@ -35,7 +35,7 @@ static SPFavoritesController *sharedFavoritesController = nil; - (void)_loadFavorites; - (void)_constructFavoritesTree; -- (void)_saveFavoritesDataInBackground:(NSDictionary *)data; +- (void)_saveFavoritesData:(NSDictionary *)data; - (void)_addNode:(SPTreeNode *)node asChildOfNode:(SPTreeNode *)parent; - (SPTreeNode *)_constructBranchForNodeData:(NSDictionary *)nodeData; @@ -101,12 +101,13 @@ static SPFavoritesController *sharedFavoritesController = nil; * Saves the current favorites dictionary in memory to disk. Note that the current favorites data file is moved * rather than overwritten in the event that we can't write the new file, the original can simply be restored. * This method also does a lot of error checking to ensure we don't lose the user's favorites data. + * Saves the data in the background so any UI tasks can stay responsive. */ - (void)saveFavorites { pthread_mutex_lock(&favoritesLock); - [NSThread detachNewThreadSelector:@selector(_saveFavoritesDataInBackground:) + [NSThread detachNewThreadSelector:@selector(_saveFavoritesData:) toTarget:self withObject:[[[favoritesTree childNodes] objectAtIndex:0] dictionaryRepresentation]]; @@ -114,6 +115,14 @@ static SPFavoritesController *sharedFavoritesController = nil; } /** + * Save the current favorites dictionary in memory to disk, in the foreground, in a blocking manner. + */ +- (void)saveFavoritesSynchronously +{ + [self _saveFavoritesData:[[[favoritesTree childNodes] objectAtIndex:0] dictionaryRepresentation]]; +} + +/** * Reloads the favorites data from disk with the option to save before doing so. * * @param save Indicates whether the current favorites data in memory should be saved to disk before being @@ -343,7 +352,7 @@ static SPFavoritesController *sharedFavoritesController = nil; * * @param data The raw plist data (serialized NSDictionary) to be saved */ -- (void)_saveFavoritesDataInBackground:(NSDictionary *)data +- (void)_saveFavoritesData:(NSDictionary *)data { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; @@ -411,7 +420,11 @@ static SPFavoritesController *sharedFavoritesController = nil; NSLog(@"Error writing favorites data. Restoring backup if available: %@", [error localizedDescription]); // Restore the original data file - [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:NULL]; + error = nil; + [fileManager moveItemAtPath:favoritesBackupFile toPath:favoritesFile error:&error]; + if (error) { + NSLog(@"Could not restore backup; favorites.plist left renamed as %@ due to error (%@)", favoritesBackupFile, [error localizedDescription]); + } } else { |