The callback passed to Native.watch returns an event type string instead of an object.

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-07-23 16:34:39 -07:00
parent 9658cf61ff
commit 4744c1cb34
5 changed files with 18 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
#import "include/cef_v8.h"
#import <Foundation/Foundation.h>
typedef void (^WatchCallback)(NSArray *, NSString *);
typedef void (^WatchCallback)(NSString *, NSString *);
@interface PathWatcher : NSObject {
int _kq;

View File

@@ -196,14 +196,14 @@ static NSMutableArray *gPathWatchers;
}
NSNumber *fdNumber = [NSNumber numberWithInt:event.ident];
NSMutableArray *eventFlags = [NSMutableArray array];
NSString *eventFlag = nil;
NSString *path = [self pathForFileDescriptor:fdNumber];
if (event.fflags & NOTE_WRITE) {
[eventFlags addObject:@"modified"];
eventFlag = @"contents-change";
}
else if ([self isAtomicWrite:event]) {
[eventFlags addObject:@"modified"];
eventFlag = @"contents-change";
// The fd for the path has changed. Remove references to old fd and
// make sure the path and callbacks are linked with new fd.
@@ -216,10 +216,10 @@ static NSMutableArray *gPathWatchers;
}
}
else if (event.fflags & NOTE_DELETE) {
[eventFlags addObject:@"removed"];
eventFlag = @"remove";
}
else if (event.fflags & NOTE_RENAME) {
[eventFlags addObject:@"moved"];
eventFlag = @"move";
char pathBuffer[MAXPATHLEN];
fcntl((int)event.ident, F_GETPATH, &pathBuffer);
@@ -233,7 +233,7 @@ static NSMutableArray *gPathWatchers;
for (NSString *key in callbacks) {
WatchCallback callback = [callbacks objectForKey:key];
dispatch_async(dispatch_get_main_queue(), ^{
callback(eventFlags, path);
callback(eventFlag, path);
});
}
}

View File

@@ -304,19 +304,14 @@ bool NativeHandler::Execute(const CefString& name,
CefRefPtr<CefV8Context> context = CefV8Context::GetCurrentContext();
WatchCallback callback = ^(NSArray *eventList, NSString *path) {
WatchCallback callback = ^(NSString *eventType, NSString *path) {
context->Enter();
CefV8ValueList args;
CefRefPtr<CefV8Value> retval;
CefRefPtr<CefV8Exception> e;
CefRefPtr<CefV8Value> eventObject = CefV8Value::CreateObject(NULL, NULL);
for (NSString *event in eventList) {
eventObject->SetValue([event UTF8String], CefV8Value::CreateBool(true), V8_PROPERTY_ATTRIBUTE_NONE);
}
args.push_back(eventObject);
args.push_back(CefV8Value::CreateString(std::string([eventType UTF8String], [eventType lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
args.push_back(CefV8Value::CreateString(std::string([path UTF8String], [path lengthOfBytesUsingEncoding:NSUTF8StringEncoding])));
function->ExecuteFunction(function, args, retval, e, true);

View File

@@ -29,8 +29,8 @@ class Directory
@unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventTypes) =>
@trigger 'contents-change' if eventTypes.modified?
@watchId = $native.watchPath @path, (eventType) =>
@trigger "contents-change" if eventType is "contents-change"
unsubscribeFromNativeChangeEvents: ->
$native.unwatchPath(@path, @watchId)

View File

@@ -29,14 +29,14 @@ class File
@unsubscribeFromNativeChangeEvents() if @subscriptionCount() == 0
subscribeToNativeChangeEvents: ->
@watchId = $native.watchPath @path, (eventTypes, path) =>
if eventTypes.removed?
@trigger 'remove'
@watchId = $native.watchPath @path, (eventType, path) =>
if eventType is "remove"
@trigger "remove"
@off()
else if eventTypes.moved?
else if eventType is "move"
@setPath(path)
@trigger 'move'
else if eventTypes.modified?
@trigger "move"
else if eventType is "contents-change"
newMd5 = fs.md5ForPath(@getPath())
return if newMd5 == @md5