From 0018be6fd886c0e1e7fc13f967fb8b6d4949983a Mon Sep 17 00:00:00 2001 From: Malte Tancred Date: Wed, 13 Jun 2012 10:37:08 +0200 Subject: [PATCH 1/2] Make XcodeCapp synchronize file system event status more frequently. This is a small fix that makes XcodeCapp update the latestEventId value in the defaults database at the end of each FSEvents callback. Prior to this fix, the synchronization was performed only when the user actively decided to stop listening to a project. --- Tools/XcodeCapp/FSEventCallback.m | 2 ++ Tools/XcodeCapp/TNXCodeCapp.h | 1 + Tools/XcodeCapp/TNXCodeCapp.m | 20 +++++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Tools/XcodeCapp/FSEventCallback.m b/Tools/XcodeCapp/FSEventCallback.m index c4af80093..f546a0b78 100644 --- a/Tools/XcodeCapp/FSEventCallback.m +++ b/Tools/XcodeCapp/FSEventCallback.m @@ -138,4 +138,6 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, } } } + + [xcc synchronizeLastEventId]; } diff --git a/Tools/XcodeCapp/TNXCodeCapp.h b/Tools/XcodeCapp/TNXCodeCapp.h index 937132502..1606df375 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.h +++ b/Tools/XcodeCapp/TNXCodeCapp.h @@ -80,6 +80,7 @@ extern NSString * const XCCListeningStartNotification; - (void)initializeEventStreamWithPath:(NSString*)aPath; - (void)stopEventStream; - (void)updateLastEventId:(uint64_t)eventId; +- (void)synchronizeLastEventId; - (void)listenProjectAtPath:(NSString *)path; - (void)clear; - (void)start; diff --git a/Tools/XcodeCapp/TNXCodeCapp.m b/Tools/XcodeCapp/TNXCodeCapp.m index ffe2d1cab..d7f28b60b 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.m +++ b/Tools/XcodeCapp/TNXCodeCapp.m @@ -195,13 +195,7 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification */ - (void)clear { - if (lastEventId && [lastEventId longLongValue] != 0) - { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - [defaults setObject:lastEventId forKey:@"lastEventId"]; - [defaults synchronize]; - } - + [self synchronizeLastEventId]; currentProjectURL = nil; currentProjectName = nil; [ignoredFilePaths removeAllObjects]; @@ -259,6 +253,18 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification lastEventId = [NSNumber numberWithUnsignedLongLong:eventId]; } +/*! + Synchronizes the last recorded event ID with the user defaults. + */ +- (void)synchronizeLastEventId { + if (lastEventId && [lastEventId longLongValue] != 0) + { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + [defaults setObject:lastEventId forKey:@"lastEventId"]; + [defaults synchronize]; + } +} + /*! Run a NSTask with the given arguments @param arguments NSArray containing the NSTask arguments From 1fd021770ed23b3be5220d66cd4ae97bb13212aa Mon Sep 17 00:00:00 2001 From: Malte Tancred Date: Thu, 14 Jun 2012 11:43:52 +0200 Subject: [PATCH 2/2] Split -synchronizeLastEventId in two methods. The first method (updateUserDefaultsWithLastEventId) just sets the default while the other (synchronizeUserDefaultsWithDisk) forces a synchronization with the disk. --- Tools/XcodeCapp/FSEventCallback.m | 2 +- Tools/XcodeCapp/TNXCodeCapp.h | 3 ++- Tools/XcodeCapp/TNXCodeCapp.m | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Tools/XcodeCapp/FSEventCallback.m b/Tools/XcodeCapp/FSEventCallback.m index f546a0b78..9df1fd56a 100644 --- a/Tools/XcodeCapp/FSEventCallback.m +++ b/Tools/XcodeCapp/FSEventCallback.m @@ -139,5 +139,5 @@ void fsevents_callback(ConstFSEventStreamRef streamRef, } } - [xcc synchronizeLastEventId]; + [xcc updateUserDefaultsWithLastEventId]; } diff --git a/Tools/XcodeCapp/TNXCodeCapp.h b/Tools/XcodeCapp/TNXCodeCapp.h index 1606df375..51c507de3 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.h +++ b/Tools/XcodeCapp/TNXCodeCapp.h @@ -80,7 +80,8 @@ extern NSString * const XCCListeningStartNotification; - (void)initializeEventStreamWithPath:(NSString*)aPath; - (void)stopEventStream; - (void)updateLastEventId:(uint64_t)eventId; -- (void)synchronizeLastEventId; +- (void)updateUserDefaultsWithLastEventId; +- (void)synchronizeUserDefaultsWithDisk; - (void)listenProjectAtPath:(NSString *)path; - (void)clear; - (void)start; diff --git a/Tools/XcodeCapp/TNXCodeCapp.m b/Tools/XcodeCapp/TNXCodeCapp.m index d7f28b60b..e6d6e9af7 100644 --- a/Tools/XcodeCapp/TNXCodeCapp.m +++ b/Tools/XcodeCapp/TNXCodeCapp.m @@ -195,7 +195,8 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification */ - (void)clear { - [self synchronizeLastEventId]; + [self updateUserDefaultsWithLastEventId]; + [self synchronizeUserDefaultsWithDisk]; currentProjectURL = nil; currentProjectName = nil; [ignoredFilePaths removeAllObjects]; @@ -254,17 +255,24 @@ NSString * const XCCListeningStartNotification = @"XCCListeningStartNotification } /*! - Synchronizes the last recorded event ID with the user defaults. + Updates the user defaults with the last recorded event Id. */ -- (void)synchronizeLastEventId { +- (void)updateUserDefaultsWithLastEventId +{ if (lastEventId && [lastEventId longLongValue] != 0) { - NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - [defaults setObject:lastEventId forKey:@"lastEventId"]; - [defaults synchronize]; + [[NSUserDefaults standardUserDefaults] setObject:lastEventId forKey:@"lastEventId"]; } } +/*! + Tells the standard user defaults to synchronize with disk. + */ +- (void)synchronizeUserDefaultsWithDisk +{ + [[NSUserDefaults standardUserDefaults] synchronize]; +} + /*! Run a NSTask with the given arguments @param arguments NSArray containing the NSTask arguments