mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Experiment with async callbacks from js
This commit is contained in:
@@ -20,4 +20,7 @@ struct JSGlobalContextRef;
|
||||
- (JSValueRefAndContextRef)jsWindow;
|
||||
- (void)performActionForMenuItemPath:(NSString *)menuItemPath;
|
||||
|
||||
- (void)contentsOfDirectoryAtPath:(NSString *)path onComplete:(JSValueRefAndContextRef)jsFunction;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#import "JSCocoa.h"
|
||||
#import <WebKit/WebKit.h>
|
||||
#import <dispatch/dispatch.h>
|
||||
|
||||
@interface AtomController ()
|
||||
@property (nonatomic, retain) JSCocoa *jscocoa;
|
||||
@@ -108,6 +109,7 @@
|
||||
}
|
||||
|
||||
- (void)performActionForMenuItemPath:(NSString *)menuItemPath {
|
||||
|
||||
NSString *jsCode = [NSString stringWithFormat:@"window.performActionForMenuItemPath('%@')", menuItemPath];
|
||||
[self.jscocoa evalJSString:jsCode];
|
||||
}
|
||||
@@ -118,6 +120,34 @@
|
||||
return windowWithContext;
|
||||
}
|
||||
|
||||
- (void)contentsOfDirectoryAtPath:(NSString *)path onComplete:(JSValueRefAndContextRef)jsFunction {
|
||||
dispatch_queue_t backgroundQueue = dispatch_get_global_queue(0, 0);
|
||||
dispatch_queue_t mainQueue = dispatch_get_main_queue();
|
||||
|
||||
JSValueProtect(jsFunction.ctx, jsFunction.value);
|
||||
NSLog(@"start %@", [NSThread currentThread]);
|
||||
dispatch_async(backgroundQueue, ^{
|
||||
NSLog(@"back %@", [NSThread currentThread]);
|
||||
[NSThread sleepForTimeInterval:2];
|
||||
|
||||
dispatch_sync(mainQueue, ^{
|
||||
NSLog(@"main %@", [NSThread currentThread]);
|
||||
NSLog(@"ran the block on main %p", jsFunction.value);
|
||||
[self.jscocoa callJSFunction:jsFunction.value withArguments:[NSArray arrayWithObject:@"testing"]];
|
||||
// JSValueUnprotect(jsFunction.ctx, jsFunction.value);
|
||||
|
||||
});
|
||||
|
||||
[NSThread sleepForTimeInterval:2];
|
||||
|
||||
dispatch_sync(mainQueue, ^{
|
||||
NSLog(@"main %@", [NSThread currentThread]);
|
||||
NSLog(@"ran the block on main %p", jsFunction.value);
|
||||
[self.jscocoa callJSFunction:jsFunction.value withArguments:[NSArray arrayWithObject:@"testing 2"]];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark NSWindowDelegate
|
||||
- (BOOL)windowShouldClose:(id)sender {
|
||||
[self close];
|
||||
|
||||
@@ -21,6 +21,10 @@ class RootView extends Template
|
||||
|
||||
viewProperties:
|
||||
initialize: ->
|
||||
|
||||
fs.async.list '/foo', (result) ->
|
||||
console.log(result.valueOf())
|
||||
|
||||
@bindKey 'meta+s', => @editor.save()
|
||||
@bindKey 'meta+w', => window.close()
|
||||
@bindKey 'meta+t', => @toggleFileFinder()
|
||||
|
||||
@@ -95,3 +95,8 @@ module.exports =
|
||||
# Return the path name of the current working directory.
|
||||
workingDirectory: ->
|
||||
OSX.NSFileManager.defaultManager.currentDirectoryPath.toString()
|
||||
|
||||
async:
|
||||
list: (path, callback) ->
|
||||
$atomController.contentsOfDirectoryAtPath_onComplete(path, callback)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user