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

@ -32,6 +32,9 @@
int jcDisplayNum; // How many the user actually wants to display; defaults to 10 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 int jcDisplayLen; // How many characters to display in the menu; defaults to 37
// Our status information
bool modifiedSinceLastSaveStore;
// hash -- key values to clippings // hash -- key values to clippings
// initially we will use PasteboardCount as the key value, but this will not be guaranteed // initially we will use PasteboardCount as the key value, but this will not be guaranteed
// to be unique once we allow for saving. Instead, we should use seconds since day 0 or some such. // to be unique once we allow for saving. Instead, we should use seconds since day 0 or some such.
@ -49,11 +52,13 @@
-(void) setRememberNum:(int)nowRemembering; -(void) setRememberNum:(int)nowRemembering;
-(void) setDisplayNum:(int)nowDisplaying; -(void) setDisplayNum:(int)nowDisplaying;
-(void) setDisplayLen:(int)newDisplayLength; -(void) setDisplayLen:(int)newDisplayLength;
-(void) clearModifiedSinceLastSaveStore;
// Retrieve various values // Retrieve various values
-(int) rememberNum; -(int) rememberNum;
-(int) displayLen; -(int) displayLen;
-(int) jcListCount; -(int) jcListCount;
-(bool) modifiedSinceLastSaveStore;
-(FlycutClipping *) clippingAtPosition:(int)index; -(FlycutClipping *) clippingAtPosition:(int)index;
-(NSString *) clippingContentsAtPosition:(int)index; -(NSString *) clippingContentsAtPosition:(int)index;
-(NSString *) clippingDisplayStringAtPosition:(int)index; -(NSString *) clippingDisplayStringAtPosition:(int)index;

View file

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

View file

@ -742,9 +742,15 @@
[jcListArray addObject:dict]; [jcListArray addObject:dict];
} }
[saveDict setObject:jcListArray forKey:key]; [saveDict setObject:jcListArray forKey:key];
[store clearModifiedSinceLastSaveStore];
} }
-(void) saveEngine { -(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; NSMutableDictionary *saveDict;
saveDict = [NSMutableDictionary dictionaryWithCapacity:3]; saveDict = [NSMutableDictionary dictionaryWithCapacity:3];
[saveDict setObject:@"0.7" forKey:@"version"]; [saveDict setObject:@"0.7" forKey:@"version"];