You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2013/04/12 02:14:13 UTC
mac commit: Fixed ShellUtils.
Updated Branches:
refs/heads/master 3eab1090b -> d691710e1
Fixed ShellUtils.
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/d691710e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/d691710e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/d691710e
Branch: refs/heads/master
Commit: d691710e13f7a12df73b1f2347d70f9d027fd8e5
Parents: 3eab109
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Apr 11 17:14:05 2013 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Apr 11 17:14:05 2013 -0700
----------------------------------------------------------------------
.../CordovaFramework.xcodeproj/project.pbxproj | 2 +-
.../CordovaFramework/Classes/Commands/CDV.h | 2 +
.../CordovaFramework/Classes/Utils/ShellUtils.h | 4 +-
.../CordovaFramework/Classes/Utils/ShellUtils.m | 57 ++++++++++++++-
.../project/__TESTING__.xcodeproj/project.pbxproj | 13 ++++
5 files changed, 73 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/d691710e/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj b/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
index ea990fa..a11e82b 100644
--- a/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
+++ b/CordovaFramework/CordovaFramework.xcodeproj/project.pbxproj
@@ -68,7 +68,7 @@
7E4C0AF916EAA2AD00542982 /* NSWindow+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E4C0AC516EAA2AD00542982 /* NSWindow+Utils.m */; };
7E4C0AFB16EAA35300542982 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E4C0AFA16EAA35300542982 /* SystemConfiguration.framework */; };
7E4C0AFD16EAA36400542982 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E4C0AFC16EAA36400542982 /* WebKit.framework */; };
- 7EE6E73D1714E77C0051492C /* ShellUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6E73B1714E77C0051492C /* ShellUtils.h */; };
+ 7EE6E73D1714E77C0051492C /* ShellUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE6E73B1714E77C0051492C /* ShellUtils.h */; settings = {ATTRIBUTES = (Public, ); }; };
7EE6E73E1714E77C0051492C /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EE6E73C1714E77C0051492C /* ShellUtils.m */; };
7EE6E73F1714E77C0051492C /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EE6E73C1714E77C0051492C /* ShellUtils.m */; };
/* End PBXBuildFile section */
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/d691710e/CordovaFramework/CordovaFramework/Classes/Commands/CDV.h
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework/Classes/Commands/CDV.h b/CordovaFramework/CordovaFramework/Classes/Commands/CDV.h
index 6fe45d8..2442121 100644
--- a/CordovaFramework/CordovaFramework/Classes/Commands/CDV.h
+++ b/CordovaFramework/CordovaFramework/Classes/Commands/CDV.h
@@ -25,3 +25,5 @@
#import "CDVInvokedUrlCommand.h"
#import "CDVPlugin.h"
#import "CDVDevice.h"
+
+#import "ShellUtils.h"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/d691710e/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
index ab84604..ca711c0 100644
--- a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
+++ b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.h
@@ -20,13 +20,15 @@
#import <Foundation/Foundation.h>
+@class CDVPlugin;
@interface ShellUtils : NSObject
+ (BOOL) restartComputer;
+ (void) quitApp;
+ (NSTask*) shellTask:(NSString*)command;
-+ (oneway void) executeShellTaskAsync:(NSString*)command;
++ (NSTask*) executeShellTaskAsync:(NSString*)command usingBlock:(void (^)(NSNotification *))block;
++ (void) executeShellTaskAsync:(NSString*)command withCallbackId:(NSString*)aCallbackId forPlugin:(CDVPlugin*)plugin;
+ (NSString*) executeShellTask:(NSString*)command;
@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/d691710e/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
----------------------------------------------------------------------
diff --git a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
index 27e127f..f7d24a6 100644
--- a/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
+++ b/CordovaFramework/CordovaFramework/Classes/Utils/ShellUtils.m
@@ -21,6 +21,7 @@
#import "ShellUtils.h"
#import <Cocoa/Cocoa.h>
#import <Security/Authorization.h>
+#import "CDVPlugin.h"
@implementation ShellUtils
@@ -63,11 +64,61 @@
return [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding];
}
-+ (oneway void) executeShellTaskAsync:(NSString*)command
++ (NSTask*) executeShellTaskAsync:(NSString*)command usingBlock:(void (^)(NSNotification *))block
{
- [[[self class] shellTask:command] launch];
+ NSPipe* pipe = [NSPipe pipe];
+ NSFileHandle* fileHandle = [pipe fileHandleForReading];
+
+ NSTask* task = [[self class] shellTask:command];
+ [task setStandardOutput:pipe];
+ [task setStandardError:pipe];
+
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
+ NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
+
+ [center addObserverForName:NSFileHandleReadCompletionNotification object:fileHandle queue:mainQueue usingBlock:block];
+ [center addObserverForName:NSTaskDidTerminateNotification object:task queue:mainQueue usingBlock:block];
+
+ [task launch];
+ [fileHandle readInBackgroundAndNotify];
+
+ return task;
+}
+
++ (void) executeShellTaskAsync:(NSString*)command withCallbackId:(NSString*)aCallbackId forPlugin:(CDVPlugin*)plugin
+{
+ __block NSString* callbackId = aCallbackId;
+ __block NSTask* task = nil;
- return;
+ task = [[self class] executeShellTaskAsync:command usingBlock:^(NSNotification* notif){
+ if ([notif.object isKindOfClass:[NSFileHandle class]]) {
+ NSFileHandle* fileHandle = (NSFileHandle*)notif.object;
+ NSData* data = [[notif userInfo] valueForKey:NSFileHandleNotificationDataItem];
+ NSString* output = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
+ CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{ @"data": output }];
+ result.keepCallback = [NSNumber numberWithBool:YES];
+ [plugin.commandDelegate sendPluginResult:result callbackId:callbackId];
+
+ if (task && [task isRunning]) {
+ [fileHandle readInBackgroundAndNotify];
+ }
+
+ } else if ([notif.object isKindOfClass:[NSTask class]]) {
+ int status = [task terminationStatus];
+ CDVPluginResult* result;
+ task = nil;
+
+ if (status == 0) { // 0 is success
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+ messageAsDictionary:@{ @"resultcode" :[NSNumber numberWithInt:status] }];
+ } else {
+ result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:status];
+ }
+ result.keepCallback = [NSNumber numberWithBool:NO];
+ [plugin.commandDelegate sendPluginResult:result callbackId:callbackId];
+ }
+ }];
}
+
@end
http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/d691710e/bin/templates/project/__TESTING__.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/bin/templates/project/__TESTING__.xcodeproj/project.pbxproj b/bin/templates/project/__TESTING__.xcodeproj/project.pbxproj
index 70d3cd6..60fff7e 100644
--- a/bin/templates/project/__TESTING__.xcodeproj/project.pbxproj
+++ b/bin/templates/project/__TESTING__.xcodeproj/project.pbxproj
@@ -13,6 +13,7 @@
48B43538152E5E6B00906A36 /* www in Resources */ = {isa = PBXBuildFile; fileRef = 48B43537152E5E6B00906A36 /* www */; };
7E4C0B0916EAA4EB00542982 /* Cordova.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E4C0B0416EAA3CF00542982 /* Cordova.framework */; };
7E4C0B0D16EAA6A700542982 /* Cordova.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7E4C0B0416EAA3CF00542982 /* Cordova.framework */; };
+ 7E545ABE17175CEF006EEBC6 /* README in Resources */ = {isa = PBXBuildFile; fileRef = 7E545ABD17175CEF006EEBC6 /* README */; };
7E608F2B16E7D9B00018F512 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = 7E608F2A16E7D9B00018F512 /* config.xml */; };
7E608F3C16E7EE8D0018F512 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E608F3416E7EE8D0018F512 /* AppDelegate.m */; };
7E608F4816E7EE970018F512 /* __TESTING__.icns in Resources */ = {isa = PBXBuildFile; fileRef = 7E608F4116E7EE970018F512 /* __TESTING__.icns */; };
@@ -71,6 +72,7 @@
48B43535152E5E4100906A36 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
48B43537152E5E6B00906A36 /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; path = www; sourceTree = "<group>"; };
7E4C0AFE16EAA3CF00542982 /* CordovaFramework.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = CordovaFramework.xcodeproj; path = ../CordovaFramework/CordovaFramework.xcodeproj; sourceTree = "<group>"; };
+ 7E545ABD17175CEF006EEBC6 /* README */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = README; sourceTree = "<group>"; };
7E608F2A16E7D9B00018F512 /* config.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = config.xml; path = __TESTING__/config.xml; sourceTree = "<group>"; };
7E608F3316E7EE8D0018F512 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
7E608F3416E7EE8D0018F512 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
@@ -107,6 +109,7 @@
7E4C0AFE16EAA3CF00542982 /* CordovaFramework.xcodeproj */,
7E608F4016E7EE970018F512 /* Resources */,
7E608F3216E7EE8D0018F512 /* Classes */,
+ 7E545ABC17175CEF006EEBC6 /* Plugins */,
7E608F2E16E7EC900018F512 /* Other Sources */,
48B43517152E5E3500906A36 /* Frameworks */,
48B43515152E5E3500906A36 /* Products */,
@@ -143,6 +146,15 @@
name = Products;
sourceTree = "<group>";
};
+ 7E545ABC17175CEF006EEBC6 /* Plugins */ = {
+ isa = PBXGroup;
+ children = (
+ 7E545ABD17175CEF006EEBC6 /* README */,
+ );
+ name = Plugins;
+ path = __TESTING__/Plugins;
+ sourceTree = "<group>";
+ };
7E608F2E16E7EC900018F512 /* Other Sources */ = {
isa = PBXGroup;
children = (
@@ -260,6 +272,7 @@
7E608F4916E7EE970018F512 /* Credits.rtf in Resources */,
7E608F4A16E7EE970018F512 /* InfoPlist.strings in Resources */,
7E608F4B16E7EE970018F512 /* MainViewController.xib in Resources */,
+ 7E545ABE17175CEF006EEBC6 /* README in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};