CB-10582 Clean up code before release
Project: http://git-wip-us.apache.org/repos/asf/cordova-osx/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-osx/commit/1430e66c Tree: http://git-wip-us.apache.org/repos/asf/cordova-osx/tree/1430e66c Diff: http://git-wip-us.apache.org/repos/asf/cordova-osx/diff/1430e66c Branch: refs/heads/master Commit: 1430e66cbdf84320e7d47829c6dd37f03ff9e3b6 Parents: 7b6b78a Author: Tobias Bocanegra <[email protected]> Authored: Tue Feb 9 15:54:00 2016 -0800 Committer: Tobias Bocanegra <[email protected]> Committed: Tue Feb 9 15:54:00 2016 -0800 ---------------------------------------------------------------------- CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 8 -- CordovaLib/CordovaLib/Classes/CDVBridge.h | 2 +- CordovaLib/CordovaLib/Classes/CDVBridge.m | 8 +- .../CordovaLib/Classes/CDVViewController.h | 29 +++-- .../CordovaLib/Classes/CDVViewController.m | 73 +++++------- .../CordovaLib/Classes/CDVWebViewDelegate.h | 7 +- .../CordovaLib/Classes/CDVWebViewDelegate.m | 4 +- .../Classes/Commands/CDVCommandDelegate.h | 67 ++++++++--- .../Classes/Commands/CDVCommandDelegateImpl.m | 48 +++----- .../Classes/Commands/CDVCommandQueue.h | 5 + .../Classes/Commands/CDVCommandQueue.m | 71 +++++------ .../Classes/Commands/CDVConfigParser.h | 3 +- .../Classes/Commands/CDVConfigParser.m | 42 +++---- .../CordovaLib/Classes/Commands/CDVConsole.m | 5 +- .../Classes/Commands/CDVCursorMonitorService.h | 5 + .../CordovaLib/Classes/Commands/CDVDebug.h | 5 + .../Classes/Commands/CDVInvokedUrlCommand.h | 25 ++-- .../Classes/Commands/CDVInvokedUrlCommand.m | 4 +- .../CordovaLib/Classes/Commands/CDVJSON.h | 11 +- .../CordovaLib/Classes/Commands/CDVJSON.m | 10 +- .../CordovaLib/Classes/Commands/CDVPlugin.h | 7 ++ .../CordovaLib/Classes/Commands/CDVPlugin.m | 39 +++--- .../Classes/Commands/CDVPluginResult.h | 13 +- .../Classes/Commands/CDVPluginResult.m | 114 ++++++++---------- .../CordovaLib/Classes/Utils/NSWindow+Utils.m | 8 +- .../CordovaLib/Classes/Utils/ShellUtils.h | 34 ------ .../CordovaLib/Classes/Utils/ShellUtils.m | 119 ------------------- .../CordovaLibApp/MainViewController.m | 21 ++-- 28 files changed, 314 insertions(+), 473 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib.xcodeproj/project.pbxproj ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj index 43935cd..255aaf7 100644 --- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj +++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj @@ -38,8 +38,6 @@ 70BD67B818FFA12D00A1EFCF /* NSData+Base64.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD679218FFA12D00A1EFCF /* NSData+Base64.m */; }; 70BD67B918FFA12D00A1EFCF /* NSWindow+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD679318FFA12D00A1EFCF /* NSWindow+Utils.h */; }; 70BD67BA18FFA12D00A1EFCF /* NSWindow+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD679418FFA12D00A1EFCF /* NSWindow+Utils.m */; }; - 70BD67BB18FFA12D00A1EFCF /* ShellUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 70BD679518FFA12D00A1EFCF /* ShellUtils.h */; }; - 70BD67BC18FFA12D00A1EFCF /* ShellUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 70BD679618FFA12D00A1EFCF /* ShellUtils.m */; }; CC6A01B9AD6ECF2D913FF418 /* CDVWindowSizeCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = CC6A03B1971BACCB9183AEFE /* CDVWindowSizeCommand.h */; }; CC6A03130738A1F299369195 /* CDVCursorMonitorService.m in Sources */ = {isa = PBXBuildFile; fileRef = CC6A07666A2CE3AE46F85AD6 /* CDVCursorMonitorService.m */; }; CC6A051516599A029D1ECA50 /* CDVMainWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = CC6A0F82EDAFA619D95D3392 /* CDVMainWindow.m */; }; @@ -90,8 +88,6 @@ 70BD679218FFA12D00A1EFCF /* NSData+Base64.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSData+Base64.m"; sourceTree = "<group>"; }; 70BD679318FFA12D00A1EFCF /* NSWindow+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSWindow+Utils.h"; sourceTree = "<group>"; }; 70BD679418FFA12D00A1EFCF /* NSWindow+Utils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSWindow+Utils.m"; sourceTree = "<group>"; }; - 70BD679518FFA12D00A1EFCF /* ShellUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShellUtils.h; sourceTree = "<group>"; }; - 70BD679618FFA12D00A1EFCF /* ShellUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShellUtils.m; sourceTree = "<group>"; }; 70DAA9241908E82600AF3749 /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; 70E382C81909BBFF0029A2F0 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; CC6A00E23A9BC2910E28D36E /* NSScreen+Utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScreen+Utils.h"; sourceTree = "<group>"; }; @@ -233,8 +229,6 @@ 70BD679218FFA12D00A1EFCF /* NSData+Base64.m */, 70BD679318FFA12D00A1EFCF /* NSWindow+Utils.h */, 70BD679418FFA12D00A1EFCF /* NSWindow+Utils.m */, - 70BD679518FFA12D00A1EFCF /* ShellUtils.h */, - 70BD679618FFA12D00A1EFCF /* ShellUtils.m */, CC6A01EC9D87C6FC66791911 /* NSScreen+Utils.m */, CC6A00E23A9BC2910E28D36E /* NSScreen+Utils.h */, ); @@ -261,7 +255,6 @@ 70BD679F18FFA12D00A1EFCF /* CDVCommandDelegate.h in Headers */, 70BD679E18FFA12D00A1EFCF /* CDVAvailability.h in Headers */, 70BD679918FFA12D00A1EFCF /* CDVViewController.h in Headers */, - 70BD67BB18FFA12D00A1EFCF /* ShellUtils.h in Headers */, 70BD67B118FFA12D00A1EFCF /* CDVPlugin.h in Headers */, 70BD67B318FFA12D00A1EFCF /* CDVPluginResult.h in Headers */, 70BD67A018FFA12D00A1EFCF /* CDVCommandDelegateImpl.h in Headers */, @@ -334,7 +327,6 @@ 70BD67B818FFA12D00A1EFCF /* NSData+Base64.m in Sources */, 70BD679C18FFA12D00A1EFCF /* CDVWebViewDelegate.m in Sources */, 70BD679818FFA12D00A1EFCF /* CDVBridge.m in Sources */, - 70BD67BC18FFA12D00A1EFCF /* ShellUtils.m in Sources */, 70BD67A518FFA12D00A1EFCF /* CDVConfigParser.m in Sources */, 70BD679A18FFA12D00A1EFCF /* CDVViewController.m in Sources */, 70BD67B218FFA12D00A1EFCF /* CDVPlugin.m in Sources */, http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVBridge.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVBridge.h b/CordovaLib/CordovaLib/Classes/CDVBridge.h index 62ef8cb..3a0c3e6 100644 --- a/CordovaLib/CordovaLib/Classes/CDVBridge.h +++ b/CordovaLib/CordovaLib/Classes/CDVBridge.h @@ -30,7 +30,7 @@ - (id) initWithWebView:(WebView*) webView andViewController:(CDVViewController*) viewController; -- (void) exec:(NSString*) callbackId withService:(NSString*) service andAction:(NSString*) action andArguments:(NSArray*) arguments; +- (void) exec:(NSString*) callbackId withService:(NSString*) service andAction:(NSString*) action andArguments:(WebScriptObject*) arguments; @end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVBridge.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVBridge.m b/CordovaLib/CordovaLib/Classes/CDVBridge.m index f9269d8..7ba9ec1 100644 --- a/CordovaLib/CordovaLib/Classes/CDVBridge.m +++ b/CordovaLib/CordovaLib/Classes/CDVBridge.m @@ -56,16 +56,16 @@ CDVInvokedUrlCommand* command = [[CDVInvokedUrlCommand alloc] initWithArguments:arguments callbackId:callbackId className:service methodName:action]; - if ((command.className == nil) || (command.methodName == nil)) { + if ((command.cmdClassName == nil) || (command.methodName == nil)) { NSLog(@"ERROR: Classname and/or methodName not found for command."); return; } // Fetch an instance of this class - CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.className]; + CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.cmdClassName]; if (!([obj isKindOfClass:[CDVPlugin class]])) { - NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.className); + NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.cmdClassName); return; } @@ -77,7 +77,7 @@ objc_msgSend(obj, normalSelector, command); } else { // There's no method to call, so throw an error. - NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className); + NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.cmdClassName); } } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVViewController.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.h b/CordovaLib/CordovaLib/Classes/CDVViewController.h index 13ee341..3f1859e 100644 --- a/CordovaLib/CordovaLib/Classes/CDVViewController.h +++ b/CordovaLib/CordovaLib/Classes/CDVViewController.h @@ -27,11 +27,10 @@ #import "CDVPlugin.h" #import "CDVWebViewDelegate.h" -@interface CDVViewController : NSWindowController -{ - @protected +@interface CDVViewController : NSWindowController { + +@protected id <CDVCommandDelegate> _commandDelegate; - @protected CDVCommandQueue* _commandQueue; NSString* _userAgent; } @@ -51,7 +50,7 @@ @property (nonatomic, readonly, strong) CDVCommandQueue* commandQueue; @property (nonatomic, readonly, strong) id <CDVCommandDelegate> commandDelegate; -- (id)getCommandInstance:(NSString*)pluginName; +- (id) getCommandInstance:(NSString*) pluginName; /** * Action that toggles the fullscreen. @@ -68,20 +67,24 @@ */ - (IBAction) onPreferences:(id) sender; -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className; -- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName; +- (void) registerPlugin:(CDVPlugin*) plugin withClassName:(NSString*) className; + +- (void) registerPlugin:(CDVPlugin*) plugin withPluginName:(NSString*) pluginName; @end // add private web preferences @interface WebPreferences (WebPrivate) -- (BOOL)webGLEnabled; -- (void)setWebGLEnabled:(BOOL)enabled; +- (BOOL) webGLEnabled; + +- (void) setWebGLEnabled:(BOOL) enabled; + +- (BOOL) localStorageEnabled; + +- (void) setLocalStorageEnabled:(BOOL) localStorageEnabled; -- (BOOL)localStorageEnabled; -- (void)setLocalStorageEnabled:(BOOL)localStorageEnabled; +- (NSString*) _localStorageDatabasePath; -- (NSString *)_localStorageDatabasePath; -- (void)_setLocalStorageDatabasePath:(NSString *)path; +- (void) _setLocalStorageDatabasePath:(NSString*) path; @end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVViewController.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVViewController.m b/CordovaLib/CordovaLib/Classes/CDVViewController.m index 90a76c6..b4449cc 100644 --- a/CordovaLib/CordovaLib/Classes/CDVViewController.m +++ b/CordovaLib/CordovaLib/Classes/CDVViewController.m @@ -25,16 +25,16 @@ @interface CDVViewController () -@property (nonatomic, readwrite, strong) NSXMLParser* configParser; -@property (nonatomic, readwrite, strong) NSMutableDictionary* settings; -@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects; -@property (nonatomic, readwrite, strong) NSArray* startupPluginNames; -@property (nonatomic, readwrite, strong) NSDictionary* pluginsMap; -@property (nonatomic, readwrite, assign) BOOL loadFromString; -@property (readwrite, assign) BOOL initialized; +@property(nonatomic, readwrite, strong) NSXMLParser* configParser; +@property(nonatomic, readwrite, strong) NSMutableDictionary* settings; +@property(nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects; +@property(nonatomic, readwrite, strong) NSArray* startupPluginNames; +@property(nonatomic, readwrite, strong) NSDictionary* pluginsMap; +@property(nonatomic, readwrite, assign) BOOL loadFromString; +@property(readwrite, assign) BOOL initialized; -@property (readwrite, assign) BOOL cfgFullScreen; -@property (readwrite, assign) NSSize cfgWindowSize; +@property(readwrite, assign) BOOL cfgFullScreen; +@property(readwrite, assign) NSSize cfgWindowSize; @end @@ -47,8 +47,7 @@ @synthesize commandDelegate = _commandDelegate; @synthesize commandQueue = _commandQueue; -- (void) awakeFromNib -{ +- (void) awakeFromNib { // make the linker happy since CDVWebViewDelegate is not referenced anywhere and would be stripped out // see http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime [CDVWebViewDelegate class]; @@ -89,7 +88,7 @@ WebPreferences* prefs = [self.webView preferences]; [prefs setAutosaves:YES]; - [self configureWebGL: prefs]; + [self configureWebGL:prefs]; [self configureLocalStorage:prefs]; [self configureWindowSize]; [self configureHideMousePointer]; @@ -97,7 +96,7 @@ [[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; } -- (void)__init { +- (void) __init { if ((self != nil) && !self.initialized) { _commandQueue = [[CDVCommandQueue alloc] initWithViewController:self]; _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:self]; @@ -111,8 +110,7 @@ } } -- (id) init -{ +- (id) init { self = [super init]; if (self) { // Initialization code here. @@ -121,8 +119,7 @@ return self; } -- (id)initWithWindowNibName:(NSString*)nibNameOrNil -{ +- (id) initWithWindowNibName:(NSString*) nibNameOrNil { self = [super initWithWindowNibName:nibNameOrNil]; if (self) { // Initialization code here. @@ -131,8 +128,7 @@ return self; } -- (void)loadSettings -{ +- (void) loadSettings { CDVConfigParser* delegate = [[CDVConfigParser alloc] init]; // read from config.xml in the app bundle @@ -150,7 +146,7 @@ NSLog(@"Failed to initialize XML parser."); return; } - [configParser setDelegate:((id < NSXMLParserDelegate >)delegate)]; + [configParser setDelegate:((id <NSXMLParserDelegate>) delegate)]; [configParser parse]; // Get the plugin dictionary, whitelist and settings from the delegate. @@ -172,7 +168,7 @@ /** * Configures WebGL */ -- (void) configureWebGL: (WebPreferences*) prefs { +- (void) configureWebGL:(WebPreferences*) prefs { // initialize items based on settings BOOL enableWebGL = [self.settings[@"EnableWebGL"] boolValue]; @@ -185,7 +181,7 @@ /** * Configures Local Storage path */ -- (void) configureLocalStorage: (WebPreferences*) prefs { +- (void) configureLocalStorage:(WebPreferences*) prefs { // ensure that local storage is enable and paths are correct NSString* webStoragePath = self.settings[@"OSXLocalStoragePath"]; if (webStoragePath == nil) { @@ -224,7 +220,7 @@ } else if ([windowSize isEqualToString:@"fullscreen"]) { _cfgFullScreen = true; } else { - NSArray *dims = [windowSize componentsSeparatedByString: @"x"]; + NSArray* dims = [windowSize componentsSeparatedByString:@"x"]; if (dims.count == 2) { _cfgWindowSize.width = [dims[0] integerValue]; _cfgWindowSize.height = [dims[1] integerValue]; @@ -236,14 +232,13 @@ * Configures the hideMousePointer preference. */ - (void) configureHideMousePointer { - NSString *hide = self.settings[@"HideMousePointer"]; + NSString* hide = self.settings[@"HideMousePointer"]; if (hide) { [[CDVCursorMonitorService service] startWithTimeout:[hide integerValue]]; } } -- (void)registerPlugin:(CDVPlugin*)plugin withClassName:(NSString*)className -{ +- (void) registerPlugin:(CDVPlugin*) plugin withClassName:(NSString*) className { if ([plugin respondsToSelector:@selector(setViewController:)]) { [plugin setViewController:self]; } @@ -252,12 +247,11 @@ [plugin setCommandDelegate:_commandDelegate]; } - [self.pluginObjects setObject:plugin forKey:className]; + self.pluginObjects[className] = plugin; [plugin pluginInitialize]; } -- (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName -{ +- (void) registerPlugin:(CDVPlugin*) plugin withPluginName:(NSString*) pluginName { if ([plugin respondsToSelector:@selector(setViewController:)]) { [plugin setViewController:self]; } @@ -267,30 +261,29 @@ } NSString* className = NSStringFromClass([plugin class]); - [self.pluginObjects setObject:plugin forKey:className]; + self.pluginObjects[className] = plugin; [self.pluginsMap setValue:className forKey:[pluginName lowercaseString]]; [plugin pluginInitialize]; } /** - Returns an instance of a CordovaCommand object, based on its name. If one exists already, it is returned. + * Returns an instance of a CordovaCommand object, based on its name. If one exists already, it is returned. */ -- (id)getCommandInstance:(NSString*)pluginName -{ +- (id) getCommandInstance:(NSString*) pluginName { // first, we try to find the pluginName in the pluginsMap // (acts as a whitelist as well) if it does not exist, we return nil // NOTE: plugin names are matched as lowercase to avoid problems - however, a // possible issue is there can be duplicates possible if you had: // "org.apache.cordova.Foo" and "org.apache.cordova.foo" - only the lower-cased entry will match - NSString* className = [self.pluginsMap objectForKey:[pluginName lowercaseString]]; + NSString* className = self.pluginsMap[[pluginName lowercaseString]]; if (className == nil) { return nil; } - id obj = [self.pluginObjects objectForKey:className]; + id obj = self.pluginObjects[className]; if (!obj) { - obj = [[NSClassFromString (className)alloc] initWithWebView:webView]; + obj = [(CDVPlugin*) [NSClassFromString(className) alloc] initWithWebView:webView]; if (obj != nil) { [self registerPlugin:obj withClassName:className]; @@ -313,19 +306,19 @@ [self showWindow:self]; [self.window makeKeyAndOrderFront:self]; - [[NSApplication sharedApplication] activateIgnoringOtherApps : YES]; + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } -- (void) windowResized:(NSNotification*)notification; -{ +- (void) windowResized:(NSNotification*) notification; { } #pragma mark Menu Action Handlers + /** * Implement our own fullscreen logic */ -- (IBAction) onFullscreen:(id)sender { +- (IBAction) onFullscreen:(id) sender { [CDVWindowSizeCommand toggleFullScreen:self.window]; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h index 348ad54..41f7aeb 100644 --- a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h +++ b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.h @@ -6,9 +6,9 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -20,6 +20,9 @@ #import <Cocoa/Cocoa.h> #import <WebKit/WebKit.h> +#define CDV_JS_KEY_CONSOLE @"console" +#define CDV_JS_KEY_CORDOVABRIDGE @"cordovabridge" + @class CDVConsole; @class CDVBridge; @class CDVViewController; http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m index 0859589..234b7ca 100644 --- a/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m +++ b/CordovaLib/CordovaLib/Classes/CDVWebViewDelegate.m @@ -44,7 +44,7 @@ // allways re-initialized bridge to that it can add the helper methods on the webview's window self.bridge = [[CDVBridge alloc] initWithWebView:webView andViewController:self.viewController]; - [windowScriptObject setValue:self.bridge forKey:@"cordovabridge"]; + [windowScriptObject setValue:self.bridge forKey:CDV_JS_KEY_CORDOVABRIDGE]; } - (void) webView:(WebView*) webView addMessageToConsole:(NSDictionary*) message { @@ -63,7 +63,7 @@ if (self.console == nil) { self.console = [CDVConsole new]; } - [windowScriptObject setValue:self.console forKey:@"console"]; + [windowScriptObject setValue:self.console forKey:CDV_JS_KEY_CONSOLE]; } } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h index 04df6bc..795ab8d 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegate.h @@ -20,31 +20,60 @@ #import "CDVAvailability.h" #import "CDVInvokedUrlCommand.h" +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedPropertyInspection" +#pragma ide diagnostic ignored "OCUnusedMethodInspection" + @class CDVPlugin; @class CDVPluginResult; -@class CDVWhitelist; @protocol CDVCommandDelegate <NSObject> @property (nonatomic, readonly) NSDictionary* settings; -- (NSString*)pathForResource:(NSString*)resourcepath; -- (id)getCommandInstance:(NSString*)pluginName; - -// Sends a plugin result to the JS. This is thread-safe. -- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId; -// Evaluates the given JS. This is thread-safe. -- (void)evalJs:(NSString*)js; -// Can be used to evaluate JS right away instead of scheduling it on the run-loop. -// This is required for dispatch resign and pause events, but should not be used -// without reason. Without the run-loop delay, alerts used in JS callbacks may result -// in dead-lock. This method must be called from the UI thread. -- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop; -// Runs the given block on a background thread using a shared thread-pool. -- (void)runInBackground:(void (^)())block; -// Returns the User-Agent of the associated UIWebView. -- (NSString*)userAgent; -// Returns whether the given URL passes the white-list. -- (BOOL)URLIsWhitelisted:(NSURL*)url; +/** + * Resolves the path for a given resource. + */ +- (NSString*) pathForResource:(NSString*) resourcepath; + +/** + * Returns the command instance for the given plugin name + */ +- (id) getCommandInstance:(NSString*) pluginName; + +/** + * Sends a plugin result to the JS. This is thread-safe. + */ +- (void) sendPluginResult:(CDVPluginResult*) result callbackId:(NSString*) callbackId; + +/** + * Evaluates the given JS. This is thread-safe. + */ +- (void) evalJs:(NSString*) js; + +/** + * Can be used to evaluate JS right away instead of scheduling it on the run-loop. + * This is required for dispatch resign and pause events, but should not be used + * without reason. Without the run-loop delay, alerts used in JS callbacks may result + * in dead-lock. This method must be called from the UI thread. + */ +- (void) evalJs:(NSString*) js scheduledOnRunLoop:(BOOL) scheduledOnRunLoop; + +/** + * Runs the given block on a background thread using a shared thread-pool. + */ +- (void) runInBackground:(void (^)()) block; + +/** + * Returns the User-Agent of the associated UIWebView. + */ +- (NSString*) userAgent; + +/** + * Returns whether the given URL passes the white-list. + */ +- (BOOL) URLIsWhitelisted:(NSURL*) url; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegateImpl.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegateImpl.m b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegateImpl.m index c5c583e..2b33270 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegateImpl.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandDelegateImpl.m @@ -18,15 +18,13 @@ */ #import "CDVCommandDelegateImpl.h" -#import "CDVJSON.h" #import "CDVCommandQueue.h" #import "CDVPluginResult.h" #import "CDVViewController.h" @implementation CDVCommandDelegateImpl -- (id)initWithViewController:(CDVViewController*)viewController -{ +- (id) initWithViewController:(CDVViewController*) viewController { self = [super init]; if (self != nil) { _viewController = viewController; @@ -36,8 +34,7 @@ return self; } -- (NSString*)pathForResource:(NSString*)resourcepath -{ +- (NSString*) pathForResource:(NSString*) resourcepath { NSBundle* mainBundle = [NSBundle mainBundle]; NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]]; NSString* filename = [directoryParts lastObject]; @@ -54,8 +51,7 @@ return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr]; } -- (void)evalJsHelper2:(NSString*)js -{ +- (void) evalJsHelper2:(NSString*) js { CDV_EXEC_LOG(@"Exec: evalling: %@", [js substringToIndex:MIN([js length], 160)]); NSString* commandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString:js]; if ([commandsJSON length] > 0) { @@ -63,11 +59,10 @@ } // TODO: -// [_commandQueue enqueCommandBatch:commandsJSON]; + // [_commandQueue enqueCommandBatch:commandsJSON]; } -- (void)evalJsHelper:(NSString*)js -{ +- (void) evalJsHelper:(NSString*) js { // Cycle the run-loop before executing the JS. // This works around a bug where sometimes alerts() within callbacks can cause // dead-lock. @@ -83,8 +78,7 @@ } } -- (void)sendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId -{ +- (void) sendPluginResult:(CDVPluginResult*) result callbackId:(NSString*) callbackId { CDV_EXEC_LOG(@"Exec(%@): Sending result. Status=%@", callbackId, result.status); // This occurs when there is are no win/fail callbacks for the call. if ([@"INVALID" isEqualToString:callbackId]) { @@ -99,13 +93,11 @@ [self evalJsHelper:js]; } -- (void)evalJs:(NSString*)js -{ +- (void) evalJs:(NSString*) js { [self evalJs:js scheduledOnRunLoop:YES]; } -- (void)evalJs:(NSString*)js scheduledOnRunLoop:(BOOL)scheduledOnRunLoop -{ +- (void) evalJs:(NSString*) js scheduledOnRunLoop:(BOOL) scheduledOnRunLoop { js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeEvalAndFetch(function(){%@})", js]; if (scheduledOnRunLoop) { [self evalJsHelper:js]; @@ -114,37 +106,31 @@ } } -- (BOOL)execute:(CDVInvokedUrlCommand*)command -{ +- (BOOL) execute:(CDVInvokedUrlCommand*) command { return [_commandQueue execute:command]; } -- (id)getCommandInstance:(NSString*)pluginName -{ +- (id) getCommandInstance:(NSString*) pluginName { return [_viewController getCommandInstance:pluginName]; } -- (void)runInBackground:(void (^)())block -{ +- (void) runInBackground:(void (^)()) block { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block); } -- (NSString*)userAgent -{ +- (NSString*) userAgent { //return [_viewController userAgent]; return nil; } -- (BOOL)URLIsWhitelisted:(NSURL*)url -{ -// TODO: -// return ![_viewController.whitelist schemeIsAllowed:[url scheme]] || -// [_viewController.whitelist URLIsAllowed:url]; +- (BOOL) URLIsWhitelisted:(NSURL*) url { + // TODO: + // return ![_viewController.whitelist schemeIsAllowed:[url scheme]] || + // [_viewController.whitelist URLIsAllowed:url]; return NO; } -- (NSDictionary*)settings -{ +- (NSDictionary*) settings { return _viewController.settings; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.h b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.h index 27c47b5..8e1d460 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.h @@ -19,6 +19,9 @@ #import <Foundation/Foundation.h> +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedMethodInspection" + @class CDVInvokedUrlCommand; @class CDVViewController; @@ -38,3 +41,5 @@ - (BOOL)execute:(CDVInvokedUrlCommand*)command; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.m b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.m index 2ff947b..4265f0b 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCommandQueue.m @@ -19,15 +19,13 @@ #include <objc/message.h> #import "CDV.h" -#import "CDVCommandQueue.h" -#import "CDVCommandDelegateImpl.h" @interface CDVCommandQueue () { NSInteger _lastCommandQueueFlushRequestId; #ifdef __MAC_10_8 __weak #endif - NSViewController* _viewController; + CDVViewController* _viewController; NSMutableArray* _queue; BOOL _currentlyExecuting; } @@ -37,8 +35,7 @@ @synthesize currentlyExecuting = _currentlyExecuting; -- (id)initWithViewController:(NSViewController*)viewController -{ +- (id) initWithViewController:(CDVViewController*) viewController { self = [super init]; if (self != nil) { _viewController = viewController; @@ -47,27 +44,23 @@ return self; } -- (void)dispose -{ +- (void) dispose { // TODO(agrieve): Make this a zeroing weak ref once we drop support for 4.3. _viewController = nil; } -- (void)resetRequestId -{ +- (void) resetRequestId { _lastCommandQueueFlushRequestId = 0; } -- (void)enqueCommandBatch:(NSString*)batchJSON -{ +- (void) enqueCommandBatch:(NSString*) batchJSON { if ([batchJSON length] > 0) { [_queue addObject:batchJSON]; [self executePending]; } } -- (void)maybeFetchCommandsFromJs:(NSNumber*)requestId -{ +- (void) maybeFetchCommandsFromJs:(NSNumber*) requestId { // Use the request ID to determine if we've already flushed for this request. // This is required only because the NSURLProtocol enqueues the same request // multiple times. @@ -77,21 +70,19 @@ } } -- (void)fetchCommandsFromJs -{ +- (void) fetchCommandsFromJs { // TODO: -// // Grab all the queued commands from the JS side. -// NSString* queuedCommandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString: -// @"cordova.require('cordova/exec').nativeFetchMessages()"]; -// -// [self enqueCommandBatch:queuedCommandsJSON]; -// if ([queuedCommandsJSON length] > 0) { -// CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by request."); -// } + // // Grab all the queued commands from the JS side. + // NSString* queuedCommandsJSON = [_viewController.webView stringByEvaluatingJavaScriptFromString: + // @"cordova.require('cordova/exec').nativeFetchMessages()"]; + // + // [self enqueCommandBatch:queuedCommandsJSON]; + // if ([queuedCommandsJSON length] > 0) { + // CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by request."); + // } } -- (void)executePending -{ +- (void) executePending { // Make us re-entrant-safe. if (_currentlyExecuting) { return; @@ -101,37 +92,35 @@ for (NSUInteger i = 0; i < [_queue count]; ++i) { // Parse the returned JSON array. - NSArray* commandBatch = [[_queue objectAtIndex:i] JSONObject]; + NSArray* commandBatch = [_queue[i] JSONObject]; // Iterate over and execute all of the commands. for (NSArray* jsonEntry in commandBatch) { CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry]; - CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.className, command.methodName); + CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.cmdClassName, command.methodName); if (![self execute:command]) { #ifdef DEBUG - NSString* commandJson = [jsonEntry JSONString]; - static NSUInteger maxLogLength = 1024; - NSString* commandString = ([commandJson length] > maxLogLength) ? - [NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] : - commandJson; + NSString* commandJson = [jsonEntry JSONString]; + static NSUInteger maxLogLength = 1024; + NSString* commandString = ([commandJson length] > maxLogLength) ? + [NSString stringWithFormat:@"%@[...]", [commandJson substringToIndex:maxLogLength]] : + commandJson; - DLog(@"FAILED pluginJSON = %@", commandString); + DLog(@"FAILED pluginJSON = %@", commandString); #endif } } } [_queue removeAllObjects]; - } @finally - { + } @finally { _currentlyExecuting = NO; } } -- (BOOL)execute:(CDVInvokedUrlCommand*)command -{ - if ((command.className == nil) || (command.methodName == nil)) { +- (BOOL) execute:(CDVInvokedUrlCommand*) command { + if ((command.cmdClassName == nil) || (command.methodName == nil)) { NSLog(@"ERROR: Classname and/or methodName not found for command."); return NO; } @@ -141,9 +130,9 @@ // CDVPlugin* obj = [_viewController.commandDelegate getCommandInstance:command.className]; // CDVPlugin* obj = nil; - + if (!([obj isKindOfClass:[CDVPlugin class]])) { - NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.className); + NSLog(@"ERROR: Plugin '%@' not found, or is not a CDVPlugin. Check your plugin mapping in config.xml.", command.cmdClassName); return NO; } BOOL retVal = YES; @@ -157,7 +146,7 @@ objc_msgSend(obj, normalSelector, command); } else { // There's no method to call, so throw an error. - NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.className); + NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, command.cmdClassName); retVal = NO; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.h b/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.h index 2e06c88..8360312 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.h @@ -17,8 +17,7 @@ under the License. */ -@interface CDVConfigParser : NSObject <NSXMLParserDelegate> -{ +@interface CDVConfigParser : NSObject <NSXMLParserDelegate> { NSString* featureName; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.m b/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.m index 76326b9..f414842 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVConfigParser.m @@ -22,31 +22,31 @@ // The block below is to support NSArray/NSDictionary subscripting in 10.7 #ifdef __MAC_10_7 -@interface NSArray(Subscripting) -- (id)objectAtIndexedSubscript:(NSUInteger)index; +@interface NSArray (Subscripting) +- (id) objectAtIndexedSubscript:(NSUInteger) index; @end -@interface NSMutableArray(Subscripting) -- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index; +@interface NSMutableArray (Subscripting) +- (void) setObject:(id) obj atIndexedSubscript:(NSUInteger) index; @end -@interface NSDictionary(Subscripting) -- (id)objectForKeyedSubscript:(id)key; +@interface NSDictionary (Subscripting) +- (id) objectForKeyedSubscript:(id) key; @end -@interface NSMutableDictionary(Subscripting) -- (void)setObject:(id)obj forKeyedSubscript:(id <NSCopying>)key; +@interface NSMutableDictionary (Subscripting) +- (void) setObject:(id) obj forKeyedSubscript:(id <NSCopying>) key; @end #endif @interface CDVConfigParser () -@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict; -@property (nonatomic, readwrite, strong) NSMutableDictionary* settings; -@property (nonatomic, readwrite, strong) NSMutableArray* whitelistHosts; -@property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames; -@property (nonatomic, readwrite, strong) NSString* startPage; +@property(nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict; +@property(nonatomic, readwrite, strong) NSMutableDictionary* settings; +@property(nonatomic, readwrite, strong) NSMutableArray* whitelistHosts; +@property(nonatomic, readwrite, strong) NSMutableArray* startupPluginNames; +@property(nonatomic, readwrite, strong) NSString* startPage; @end @@ -54,8 +54,7 @@ @synthesize pluginsDict, settings, whitelistHosts, startPage, startupPluginNames; -- (id)init -{ +- (id) init { self = [super init]; if (self != nil) { self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:30]; @@ -67,8 +66,7 @@ return self; } -- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict -{ +- (void) parser:(NSXMLParser*) parser didStartElement:(NSString*) elementName namespaceURI:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName attributes:(NSDictionary*) attributeDict { if ([elementName isEqualToString:@"preference"]) { settings[attributeDict[@"name"]] = attributeDict[@"value"]; } else if ([elementName isEqualToString:@"feature"]) { // store feature name to use with correct parameter set @@ -79,8 +77,8 @@ if ([paramName isEqualToString:@"ios-package"] || [paramName isEqualToString:@"osx-package"]) { pluginsDict[featureName] = value; } - BOOL paramIsOnload = ([paramName isEqualToString:@"onload"] && [@"true" isEqualToString : value]); - BOOL attribIsOnload = [@"true" isEqualToString : [attributeDict[@"onload"] lowercaseString]]; + BOOL paramIsOnload = ([paramName isEqualToString:@"onload"] && [@"true" isEqualToString:value]); + BOOL attribIsOnload = [@"true" isEqualToString:[attributeDict[@"onload"] lowercaseString]]; if (paramIsOnload || attribIsOnload) { [self.startupPluginNames addObject:featureName]; } @@ -91,15 +89,13 @@ } } -- (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName -{ +- (void) parser:(NSXMLParser*) parser didEndElement:(NSString*) elementName namespaceURI:(NSString*) namespaceURI qualifiedName:(NSString*) qualifiedName { if ([elementName isEqualToString:@"feature"]) { // no longer handling a feature so release featureName = nil; } } -- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError -{ +- (void) parser:(NSXMLParser*) parser parseErrorOccurred:(NSError*) parseError { NSAssert(NO, @"config.xml parse error line %ld col %ld", [parser lineNumber], [parser columnNumber]); } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m b/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m index 988f5b1..d0345c2 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVConsole.m @@ -23,8 +23,7 @@ @implementation CDVConsole -- (void) log:(NSString*)message -{ +- (void) log:(NSString*) message { NSLog(@"%@", message); } @@ -80,7 +79,7 @@ } // right now exclude all properties (eg keys) -+ (BOOL) isKeyExcludedFromWebScript:(const char*)name { ++ (BOOL) isKeyExcludedFromWebScript:(const char*) name { return YES; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h index 3cca760..e9547d0 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVCursorMonitorService.h @@ -19,6 +19,9 @@ #import <Foundation/Foundation.h> +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedMethodInspection" + @interface CDVCursorMonitorService : NSObject + (CDVCursorMonitorService*) service; @@ -28,3 +31,5 @@ - (void) stop; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVDebug.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVDebug.h b/CordovaLib/CordovaLib/Classes/Commands/CDVDebug.h index 4a0d9f9..0a54c82 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVDebug.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVDebug.h @@ -17,9 +17,14 @@ under the License. */ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedMacroInspection" + #ifdef DEBUG #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #else #define DLog(...) #endif #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h b/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h index a15ab3c..881680e 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.h @@ -19,16 +19,19 @@ #import <Foundation/Foundation.h> +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedPropertyInspection" + @interface CDVInvokedUrlCommand : NSObject { NSString* _callbackId; - NSString* _className; + NSString* _cmdClassName; NSString* _methodName; NSArray* _arguments; } @property(nonatomic, readonly) NSArray* arguments; @property(nonatomic, readonly) NSString* callbackId; -@property(nonatomic, readonly) NSString* className; +@property(nonatomic, readonly) NSString* cmdClassName; @property(nonatomic, readonly) NSString* methodName; + (CDVInvokedUrlCommand*) commandFromJson:(NSArray*) jsonEntry; @@ -40,15 +43,23 @@ - (id) initFromJson:(NSArray*) jsonEntry; -// Returns the argument at the given index. -// If index >= the number of arguments, returns nil. -// If the argument at the given index is NSNull, returns nil. +/** + * Returns the argument at the given index. + * If index >= the number of arguments, returns nil. + * If the argument at the given index is NSNull, returns nil. + */ - (id) argumentAtIndex:(NSUInteger) index; -// Same as above, but returns defaultValue instead of nil. +/** + * Same as above, but returns defaultValue instead of nil. + */ - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue; -// Same as above, but returns defaultValue instead of nil, and if the argument is not of the expected class, returns defaultValue +/** + * Same as above, but returns defaultValue instead of nil, and if the argument is not of the expected class, returns defaultValue + */ - (id) argumentAtIndex:(NSUInteger) index withDefault:(id) defaultValue andClass:(Class) aClass; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m b/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m index 6d73610..6210abb 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVInvokedUrlCommand.m @@ -23,7 +23,7 @@ @synthesize arguments = _arguments; @synthesize callbackId = _callbackId; -@synthesize className = _className; +@synthesize cmdClassName = _cmdClassName; @synthesize methodName = _methodName; + (CDVInvokedUrlCommand*) commandFromJson:(NSArray*) jsonEntry { @@ -51,7 +51,7 @@ if (self != nil) { _arguments = arguments; _callbackId = callbackId; - _className = className; + _cmdClassName = className; _methodName = methodName; } [self massageArguments]; http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.h b/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.h index eaa895e..01b5d27 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.h @@ -17,14 +17,19 @@ under the License. */ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedMethodInspection" + @interface NSArray (CDVJSONSerializing) -- (NSString*)JSONString; +- (NSString*) JSONString; @end @interface NSDictionary (CDVJSONSerializing) -- (NSString*)JSONString; +- (NSString*) JSONString; @end @interface NSString (CDVJSONSerializing) -- (id)JSONObject; +- (id) JSONObject; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m b/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m index 78267e5..4eab8fd 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVJSON.m @@ -18,12 +18,10 @@ */ #import "CDVJSON.h" -#import <Foundation/NSJSONSerialization.h> @implementation NSArray (CDVJSONSerializing) -- (NSString*)JSONString -{ +- (NSString*) JSONString { NSError* error = nil; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted @@ -41,8 +39,7 @@ @implementation NSDictionary (CDVJSONSerializing) -- (NSString*)JSONString -{ +- (NSString*) JSONString { NSError* error = nil; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted @@ -60,8 +57,7 @@ @implementation NSString (CDVJSONSerializing) -- (id)JSONObject -{ +- (id) JSONObject { NSError* error = nil; id object = [NSJSONSerialization JSONObjectWithData:[self dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h b/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h index f9debe5..a2bd61f 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.h @@ -23,6 +23,11 @@ #import "CDVCommandDelegate.h" #import "CDVViewController.h" +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedPropertyInspection" +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#pragma ide diagnostic ignored "OCUnusedMethodInspection" + NSString* const CDVPageDidLoadNotification; NSString* const CDVPluginHandleOpenURLNotification; NSString* const CDVPluginResetNotification; @@ -57,3 +62,5 @@ NSString* const CDVLocalNotification; - (id)appDelegate; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.m b/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.m index a7d98ed..7a191db 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVPlugin.m @@ -26,19 +26,18 @@ NSString* const CDVLocalNotification = @"CDVLocalNotification"; @interface CDVPlugin () -@property (readwrite, assign) BOOL hasPendingOperation; +@property(readwrite, assign) BOOL hasPendingOperation; @end @implementation CDVPlugin @synthesize webView, viewController, commandDelegate, hasPendingOperation; -- (CDVPlugin*)initWithWebView:(WebView*)theWebView -{ +- (CDVPlugin*) initWithWebView:(WebView*) theWebView { self = [super init]; if (self) { -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil]; -// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; + // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppTerminate) name:UIApplicationWillTerminateNotification object:nil]; + // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onMemoryWarning) name:UIApplicationDidReceiveMemoryWarningNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:CDVPluginHandleOpenURLNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onReset) name:CDVPluginResetNotification object:theWebView]; @@ -47,8 +46,7 @@ NSString* const CDVLocalNotification = @"CDVLocalNotification"; return self; } -- (void)pluginInitialize -{ +- (void) pluginInitialize { // You can listen to more app notifications, see: // http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-DontLinkElementID_4 @@ -66,8 +64,7 @@ NSString* const CDVLocalNotification = @"CDVLocalNotification"; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pageDidLoad:) name:CDVPageDidLoadNotification object:self.webView]; } -- (void)dispose -{ +- (void) dispose { viewController = nil; commandDelegate = nil; webView = nil; @@ -82,41 +79,33 @@ NSString* const CDVLocalNotification = @"CDVLocalNotification"; */ /* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */ -- (void)handleOpenURL:(NSNotification*)notification -{ +- (void) handleOpenURL:(NSNotification*) notification { // override to handle urls sent to your app // register your url schemes in your App-Info.plist - - NSURL* url = [notification object]; - - if ([url isKindOfClass:[NSURL class]]) { + if ([[notification object] isKindOfClass:[NSURL class]]) { + NSURL __unused* url = [notification object]; /* Do your thing! */ } } /* NOTE: calls into JavaScript must not call or trigger any blocking UI, like alerts */ -- (void)onAppTerminate -{ +- (void) onAppTerminate { // override this if you need to do any cleanup on app exit } -- (void)onMemoryWarning -{ +- (void) onMemoryWarning { // override to remove caches, etc } -- (void)onReset -{ +- (void) onReset { // Override to cancel any long-running requests when the WebView navigates or refreshes. } -- (void)dealloc -{ +- (void) dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; // this will remove all notification unless added using addObserverForName:object:queue:usingBlock: } -- (id)appDelegate -{ +- (id) appDelegate { return [[NSApplication sharedApplication] delegate]; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h b/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h index 887d2e6..472a131 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.h @@ -19,6 +19,10 @@ #import <Foundation/Foundation.h> +#pragma clang diagnostic push +#pragma ide diagnostic ignored "OCUnusedPropertyInspection" +#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection" +#pragma ide diagnostic ignored "OCUnusedMethodInspection" typedef enum { CDVCommandStatus_NO_RESULT = 0, CDVCommandStatus_OK, @@ -37,8 +41,11 @@ typedef enum { @property (nonatomic, strong, readonly) NSNumber* status; @property (nonatomic, strong, readonly) id message; @property (nonatomic, strong) NSNumber* keepCallback; -// This property can be used to scope the lifetime of another object. For example, -// Use it to store the associated NSData when `message` is created using initWithBytesNoCopy. + +/** + * This property can be used to scope the lifetime of another object. For example, + * Use it to store the associated NSData when `message` is created using initWithBytesNoCopy. + */ @property (nonatomic, strong) id associatedObject; - (CDVPluginResult*)init; @@ -61,3 +68,5 @@ typedef enum { - (NSString*)argumentsAsJSON; @end + +#pragma clang diagnostic pop http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.m b/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.m index 81addb8..8c87f77 100644 --- a/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.m +++ b/CordovaLib/CordovaLib/Classes/Commands/CDVPluginResult.m @@ -19,12 +19,10 @@ #import "CDVPluginResult.h" #import "CDVJSON.h" -#import "CDVDebug.h" -#import "NSData+Base64.h" @interface CDVPluginResult () -- (CDVPluginResult*)initWithStatus:(CDVCommandStatus)statusOrdinal message:(id)theMessage; +- (CDVPluginResult*) initWithStatus:(CDVCommandStatus) statusOrdinal message:(id) theMessage; @end @@ -33,128 +31,111 @@ static NSArray* org_apache_cordova_CommandStatusMsgs; -id messageFromArrayBuffer(NSData* data) -{ +id messageFromArrayBuffer(NSData* data) { return @{ - @"CDVType" : @"ArrayBuffer", - @"data" :[data base64EncodedStringWithOptions:0] + @"CDVType" : @"ArrayBuffer", + @"data" : [data base64EncodedStringWithOptions:0] }; } -id massageMessage(id message) -{ +id massageMessage(id message) { if ([message isKindOfClass:[NSData class]]) { return messageFromArrayBuffer(message); } return message; } -id messageFromMultipart(NSArray* theMessages) -{ +id messageFromMultipart(NSArray* theMessages) { NSMutableArray* messages = [NSMutableArray arrayWithArray:theMessages]; for (NSUInteger i = 0; i < messages.count; ++i) { - [messages replaceObjectAtIndex:i withObject:massageMessage([messages objectAtIndex:i])]; + messages[i] = massageMessage(messages[i]); } return @{ - @"CDVType" : @"MultiPart", - @"messages" : messages + @"CDVType" : @"MultiPart", + @"messages" : messages }; } -+ (void)initialize -{ - org_apache_cordova_CommandStatusMsgs = [[NSArray alloc] initWithObjects:@"No result", - @"OK", - @"Class not found", - @"Illegal access", - @"Instantiation error", - @"Malformed url", - @"IO error", - @"Invalid action", - @"JSON error", - @"Error", - nil]; ++ (void) initialize { + org_apache_cordova_CommandStatusMsgs = @[ + @"No result", + @"OK", + @"Class not found", + @"Illegal access", + @"Instantiation error", + @"Malformed url", + @"IO error", + @"Invalid action", + @"JSON error", + @"Error" + ]; } -- (CDVPluginResult*)init -{ +- (CDVPluginResult*) init { return [self initWithStatus:CDVCommandStatus_NO_RESULT message:nil]; } -- (CDVPluginResult*)initWithStatus:(CDVCommandStatus)statusOrdinal message:(id)theMessage -{ +- (CDVPluginResult*) initWithStatus:(CDVCommandStatus) statusOrdinal message:(id) theMessage { self = [super init]; if (self) { - status = [NSNumber numberWithInt:statusOrdinal]; + status = @(statusOrdinal); message = theMessage; - keepCallback = [NSNumber numberWithBool:NO]; + keepCallback = @NO; } return self; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal { return [[self alloc] initWithStatus:statusOrdinal message:nil]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsString:(NSString*)theMessage -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsString:(NSString*) theMessage { return [[self alloc] initWithStatus:statusOrdinal message:theMessage]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArray:(NSArray*)theMessage -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsArray:(NSArray*) theMessage { return [[self alloc] initWithStatus:statusOrdinal message:theMessage]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsInt:(int)theMessage -{ - return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithInt:theMessage]]; ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsInt:(int) theMessage { + return [[self alloc] initWithStatus:statusOrdinal message:@(theMessage)]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDouble:(double)theMessage -{ - return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithDouble:theMessage]]; ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsDouble:(double) theMessage { + return [[self alloc] initWithStatus:statusOrdinal message:@(theMessage)]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsBool:(BOOL)theMessage -{ - return [[self alloc] initWithStatus:statusOrdinal message:[NSNumber numberWithBool:theMessage]]; ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsBool:(BOOL) theMessage __unused { + return [[self alloc] initWithStatus:statusOrdinal message:@(theMessage)]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsDictionary:(NSDictionary*)theMessage -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsDictionary:(NSDictionary*) theMessage { return [[self alloc] initWithStatus:statusOrdinal message:theMessage]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsArrayBuffer:(NSData*)theMessage -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsArrayBuffer:(NSData*) theMessage { return [[self alloc] initWithStatus:statusOrdinal message:messageFromArrayBuffer(theMessage)]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageAsMultipart:(NSArray*)theMessages -{ ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageAsMultipart:(NSArray*) theMessages { return [[self alloc] initWithStatus:statusOrdinal message:messageFromMultipart(theMessages)]; } -+ (CDVPluginResult*)resultWithStatus:(CDVCommandStatus)statusOrdinal messageToErrorObject:(int)errorCode -{ - NSDictionary* errDict = @{@"code" :[NSNumber numberWithInt:errorCode]}; ++ (CDVPluginResult*) resultWithStatus:(CDVCommandStatus) statusOrdinal messageToErrorObject:(int) errorCode { + NSDictionary* errDict = @{@"code" : @(errorCode)}; return [[self alloc] initWithStatus:statusOrdinal message:errDict]; } -- (void)setKeepCallbackAsBool:(BOOL)bKeepCallback -{ - [self setKeepCallback:[NSNumber numberWithBool:bKeepCallback]]; +- (void) setKeepCallbackAsBool:(BOOL) bKeepCallback { + [self setKeepCallback:@(bKeepCallback)]; } -- (NSString*)argumentsAsJSON -{ +- (NSString*) argumentsAsJSON { id arguments = (self.message == nil ? [NSNull null] : self.message); - NSArray* argumentsWrappedInArray = [NSArray arrayWithObject:arguments]; + NSArray* argumentsWrappedInArray = @[arguments]; NSString* argumentsJSON = [argumentsWrappedInArray JSONString]; @@ -164,13 +145,12 @@ id messageFromMultipart(NSArray* theMessages) } static BOOL gIsVerbose = NO; -+ (void)setVerbose:(BOOL)verbose -{ + ++ (void) setVerbose:(BOOL) verbose { gIsVerbose = verbose; } -+ (BOOL)isVerbose -{ ++ (BOOL) isVerbose { return gIsVerbose; } http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m b/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m index a4b5f8c..52363d6 100644 --- a/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m +++ b/CordovaLib/CordovaLib/Classes/Utils/NSWindow+Utils.m @@ -6,9 +6,9 @@ to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 - + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -27,8 +27,8 @@ NSRect frame = [self frame]; NSRect contentRect = [NSWindow contentRectForFrameRect: frame styleMask: NSTitledWindowMask]; - - return (frame.size.height - contentRect.size.height); + + return (float) (frame.size.height - contentRect.size.height); } @end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.h ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.h b/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.h deleted file mode 100644 index ca711c0..0000000 --- a/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - - -#import <Foundation/Foundation.h> - -@class CDVPlugin; -@interface ShellUtils : NSObject - -+ (BOOL) restartComputer; -+ (void) quitApp; - -+ (NSTask*) shellTask:(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/1430e66c/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.m ---------------------------------------------------------------------- diff --git a/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.m b/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.m deleted file mode 100644 index 9dcd55c..0000000 --- a/CordovaLib/CordovaLib/Classes/Utils/ShellUtils.m +++ /dev/null @@ -1,119 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. - */ - - -#import "ShellUtils.h" -#import <Cocoa/Cocoa.h> -#import <Security/Authorization.h> -#import "CDVPlugin.h" - -@implementation ShellUtils - -+ (BOOL) restartComputer -{ - NSAppleScript* script = [[NSAppleScript alloc] initWithSource:@"tell application \"System Events\" to restart"]; - NSDictionary* errorInfo; - NSAppleEventDescriptor* descriptor = [script executeAndReturnError:&errorInfo]; - - return (descriptor != nil); -} - -+ (void) quitApp -{ - [[NSApplication sharedApplication] terminate:nil]; -} - -+ (NSTask*) shellTask:(NSString*)command -{ - NSTask* task = [[NSTask alloc] init]; - [task setLaunchPath: @"/bin/sh"]; - [task setStandardInput:[NSFileHandle fileHandleWithNullDevice]]; - [task setArguments: @[@"-c", command]]; - - return task; -} - -+ (NSString*) executeShellTask:(NSString*)command -{ - NSPipe* pipe = [NSPipe pipe]; - NSFileHandle* fileHandle = [pipe fileHandleForReading]; - - NSTask* task = [[self class] shellTask:command]; - [task setStandardOutput:pipe]; - [task setStandardError:pipe]; - [task launch]; - - NSData* outputData = [fileHandle readDataToEndOfFile]; - - return [[NSString alloc] initWithData:outputData encoding:NSUTF8StringEncoding]; -} - -+ (NSTask*) executeShellTaskAsync:(NSString*)command usingBlock:(void (^)(NSNotification *))block -{ - 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; - - 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]; - task = nil; - - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK - messageAsDictionary:@{ @"resultcode" :[NSNumber numberWithInt:status] }]; - result.keepCallback = [NSNumber numberWithBool:NO]; - [plugin.commandDelegate sendPluginResult:result callbackId:callbackId]; - } - }]; -} - - -@end http://git-wip-us.apache.org/repos/asf/cordova-osx/blob/1430e66c/tests/CordovaLibTests/CordovaLibApp/MainViewController.m ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/CordovaLibApp/MainViewController.m b/tests/CordovaLibTests/CordovaLibApp/MainViewController.m index bf5daa6..26581c0 100644 --- a/tests/CordovaLibTests/CordovaLibApp/MainViewController.m +++ b/tests/CordovaLibTests/CordovaLibApp/MainViewController.m @@ -25,8 +25,7 @@ @implementation MainViewController -- (id)initWithWindow:(NSWindow *)window -{ +- (id) initWithWindow:(NSWindow*) window { self = [super initWithWindow:window]; if (self) { // Initialization code here. @@ -35,8 +34,7 @@ return self; } -- (id)initWithWindowNibName:(NSString*)nibNameOrNil -{ +- (id) initWithWindowNibName:(NSString*) nibNameOrNil { self = [super initWithWindowNibName:nibNameOrNil]; if (self) { // Uncomment to override the CDVCommandDelegateImpl used @@ -48,8 +46,7 @@ } -- (id)init -{ +- (id) init { self = [super init]; if (self) { // Uncomment to override the CDVCommandDelegateImpl used @@ -61,8 +58,7 @@ } -- (void)awakeFromNib -{ +- (void) awakeFromNib { [super awakeFromNib]; // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. @@ -78,13 +74,11 @@ #pragma mark CDVCommandDelegate implementation -- (id)getCommandInstance:(NSString*)className -{ +- (id) getCommandInstance:(NSString*) className { return [super getCommandInstance:className]; } -- (NSString*)pathForResource:(NSString*)resourcepath; -{ +- (NSString*) pathForResource:(NSString*) resourcepath; { return [super pathForResource:resourcepath]; } @@ -95,8 +89,7 @@ /* To override, uncomment the line in the init function(s) in MainViewController.m */ -- (BOOL)execute:(CDVInvokedUrlCommand*)command -{ +- (BOOL) execute:(CDVInvokedUrlCommand*) command { return [super execute:command]; } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
