Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use the default notification center for notifications now. There is a…

… preprocessor flag (on by default on Mac) that *additionally* sends the notifications on the workspace notification center. This should make this usable on iOS and make things less weird.
  • Loading branch information...
commit f7794eca6c1196b6e702c0ba14292d3111f8343c 1 parent 0b1235a
@uliwitness authored
Showing with 36 additions and 3 deletions.
  1. +16 −0 UKKQueue.h
  2. +20 −3 UKKQueue.m
View
16 UKKQueue.h
@@ -36,6 +36,22 @@
// -----------------------------------------------------------------------------
+// Preprocessor flags:
+// -----------------------------------------------------------------------------
+
+// For historical reasons (I was young and stupid) UKKQueue sends its notifications
+// to NSWorkspace's notificationCenter. This is not available on iOS or in
+// Foundation tools, so we're switching to NSNotificationCenter. For backwards
+// compatibility, we currently *also* send notifications to the workspace's
+// notification center. Define this flag to 0 in your prefix header to remove this
+// behaviour. This is recommended for new code. This behaviour will be removed
+// in a future version.
+#ifndef UKKQ_NOTIFY_NSWORKSPACE_CENTER
+#define UKKQ_NOTIFY_NSWORKSPACE_CENTER (!TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR)
+#endif
+
+
+/// -----------------------------------------------------------------------------
// Constants:
// -----------------------------------------------------------------------------
View
23 UKKQueue.m
@@ -185,6 +185,9 @@ -(void) postNotification: (NSString*)nm forFile: (NSString*)fp; // Message-post
static UKKQueueCentral * gUKKQueueSharedQueueSingleton = nil;
static id gUKKQueueSharedNotificationCenterProxy = nil; // Object to which we send notifications so they get put in the main thread.
+#if UKKQ_NOTIFY_NSWORKSPACE_CENTER
+static id gUKKQueueOldSharedNotificationCenterProxy = nil; // Object to which we send notifications so they get put in the main thread.
+#endif
@implementation UKKQueueCentral
@@ -209,8 +212,12 @@ -(id) init
{
if( !gUKKQueueSharedNotificationCenterProxy )
{
- gUKKQueueSharedNotificationCenterProxy = [[[NSWorkspace sharedWorkspace] notificationCenter] copyMainThreadProxy]; // Singleton, 'intentional leak'.
+ gUKKQueueSharedNotificationCenterProxy = [[NSNotificationCenter defaultCenter] copyMainThreadProxy]; // Singleton, 'intentional leak'.
[gUKKQueueSharedNotificationCenterProxy setWaitForCompletion: NO]; // Better performance and avoid deadlocks.
+ #if UKKQ_NOTIFY_NSWORKSPACE_CENTER
+ gUKKQueueOldSharedNotificationCenterProxy = [[[NSWorkspace sharedWorkspace] notificationCenter] copyMainThreadProxy]; // Singleton, 'intentional leak'.
+ [gUKKQueueOldSharedNotificationCenterProxy setWaitForCompletion: NO]; // Better performance and avoid deadlocks.
+ #endif
}
queueFD = kqueue();
@@ -440,7 +447,9 @@ -(void) watcherThread: (id)sender
DEBUG_LOG_UKKQ( @"KEVENT flags are set" );
UKKQueuePathEntry* pe = [[(UKKQueuePathEntry*)ev.udata retain] autorelease]; // In case one of the notified folks removes the path.
NSString* fpath = [pe path];
+ #if UKKQ_NOTIFY_NSWORKSPACE_CENTER
[[NSWorkspace sharedWorkspace] noteFileSystemChanged: fpath];
+ #endif
if( (ev.fflags & NOTE_RENAME) == NOTE_RENAME )
[self postNotification: UKFileWatcherRenameNotification forFile: fpath];
@@ -501,6 +510,10 @@ -(void) postNotification: (NSString*)nm forFile: (NSString*)fp
[gUKKQueueSharedNotificationCenterProxy postNotificationName: nm object: self
userInfo: [NSDictionary dictionaryWithObjectsAndKeys: fp, @"path", nil]]; // The proxy sends the notification on the main thread.
+#if UKKQ_NOTIFY_NSWORKSPACE_CENTER
+ [gUKKQueueOldSharedNotificationCenterProxy postNotificationName: nm object: self
+ userInfo: [NSDictionary dictionaryWithObjectsAndKeys: fp, @"path", nil]]; // The proxy sends the notification on the main thread.
+#endif
}
@end
@@ -539,7 +552,7 @@ -(id) init
if(( self = [super init] ))
{
watchedFiles = [[NSMutableDictionary alloc] init];
- NSNotificationCenter* nc = [[NSWorkspace sharedWorkspace] notificationCenter];
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
UKKQueueCentral* kqc = [[self class] sharedFileWatcher];
[nc addObserver: self selector: @selector(fileChangeNotification:)
name: UKFileWatcherRenameNotification object: kqc];
@@ -579,7 +592,7 @@ -(void) dealloc
[watchedFiles release];
watchedFiles = nil;
- NSNotificationCenter* nc = [[NSWorkspace sharedWorkspace] notificationCenter];
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
UKKQueueCentral* kqc = [[self class] sharedFileWatcher];
[nc removeObserver: self
name: UKFileWatcherRenameNotification object: kqc];
@@ -696,8 +709,12 @@ -(void) fileChangeNotification: (NSNotification*)notif
[delegate watcher: self receivedNotification: nm forPath: fp];
if( !delegate || alwaysNotify )
{
+ [[NSNotificationCenter defaultCenter] postNotificationName: nm object: self
+ userInfo: [notif userInfo]]; // Send the notification on to *our* clients only.
+#if UKKQ_NOTIFY_NSWORKSPACE_CENTER
[[[NSWorkspace sharedWorkspace] notificationCenter] postNotificationName: nm object: self
userInfo: [notif userInfo]]; // Send the notification on to *our* clients only.
+#endif
}
}

0 comments on commit f7794ec

Please sign in to comment.
Something went wrong with that request. Please try again.