Add mechanism to prevent saving the engine if there have been no changes since it was last saved. This becomes important with iCloud Sync to prevent pushing an update whenever the app is closed, unloaded, or other activities that invoke saveEngine.

This commit is contained in:
Mark Jerde 2017-10-19 14:20:34 -05:00
parent 5a81af5942
commit f2fad2a8da
3 changed files with 25 additions and 0 deletions

View file

@ -31,6 +31,9 @@
int jcRememberNum; // The max we will allow users to display; 20
int jcDisplayNum; // How many the user actually wants to display; defaults to 10
int jcDisplayLen; // How many characters to display in the menu; defaults to 37
// Our status information
bool modifiedSinceLastSaveStore;
// hash -- key values to clippings
// initially we will use PasteboardCount as the key value, but this will not be guaranteed
@ -49,11 +52,13 @@
-(void) setRememberNum:(int)nowRemembering;
-(void) setDisplayNum:(int)nowDisplaying;
-(void) setDisplayLen:(int)newDisplayLength;
-(void) clearModifiedSinceLastSaveStore;
// Retrieve various values
-(int) rememberNum;
-(int) displayLen;
-(int) jcListCount;
-(bool) modifiedSinceLastSaveStore;
-(FlycutClipping *) clippingAtPosition:(int)index;
-(NSString *) clippingContentsAtPosition:(int)index;
-(NSString *) clippingDisplayStringAtPosition:(int)index;

View file

@ -218,6 +218,11 @@
}
}
-(void) clearModifiedSinceLastSaveStore
{
modifiedSinceLastSaveStore = NO;
}
-(int) rememberNum
{
return jcRememberNum;
@ -233,6 +238,11 @@
return [jcList count];
}
-(bool) modifiedSinceLastSaveStore
{
return modifiedSinceLastSaveStore;
}
-(FlycutClipping *) clippingAtPosition:(int)index
{
if ( index >= [jcList count] ) {
@ -373,24 +383,28 @@
-(void) delegateInsertClippingAtIndex:(int)index
{
modifiedSinceLastSaveStore = YES;
if ( self.delegate && [self.delegate respondsToSelector:@selector(insertClippingAtIndex:)] )
[self.delegate insertClippingAtIndex:index];
}
-(void) delegateDeleteClippingAtIndex:(int)index
{
modifiedSinceLastSaveStore = YES;
if ( self.delegate && [self.delegate respondsToSelector:@selector(deleteClippingAtIndex:)] )
[self.delegate deleteClippingAtIndex:index];
}
-(void) delegateReloadClippingAtIndex:(int)index
{
modifiedSinceLastSaveStore = YES;
if ( self.delegate && [self.delegate respondsToSelector:@selector(reloadClippingAtIndex:)] )
[self.delegate reloadClippingAtIndex:index];
}
-(void) delegateMoveClippingAtIndex:(int)index toIndex:(int)newIndex
{
modifiedSinceLastSaveStore = YES;
if ( self.delegate && [self.delegate respondsToSelector:@selector(moveClippingAtIndex:toIndex:)] )
[self.delegate moveClippingAtIndex:index toIndex:newIndex];
}

View file

@ -742,9 +742,15 @@
[jcListArray addObject:dict];
}
[saveDict setObject:jcListArray forKey:key];
[store clearModifiedSinceLastSaveStore];
}
-(void) saveEngine {
// saveEngine saves to NSUserDefaults. If there have been no modifications, just skip this to avoid busy activity for any observers.
if ( !([clippingStore modifiedSinceLastSaveStore]
|| [favoritesStore modifiedSinceLastSaveStore]) )
return;
NSMutableDictionary *saveDict;
saveDict = [NSMutableDictionary dictionaryWithCapacity:3];
[saveDict setObject:@"0.7" forKey:@"version"];