Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Separating KeyboardCommand into IOSKeyboardCommand and OSXKeyboardCom…

…mand, and change extractInstanceFrom* methods to take platform-appropriate types instead of id
  • Loading branch information...
commit 81b4b2664e164d64a562fedc7f966619f2c474c3 1 parent 2bb229c
@MichaelBuckley MichaelBuckley authored
View
36 Frank.xcodeproj/project.pbxproj
@@ -57,7 +57,9 @@
3072649B165812FB00815A1A /* Operation.m in Sources */ = {isa = PBXBuildFile; fileRef = D6D79B5C11D7FB8B003E0E60 /* Operation.m */; };
3072649D165812FB00815A1A /* SelectorEngineRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = D6BD521D146C34BF001770B1 /* SelectorEngineRegistry.m */; };
3072649F165812FB00815A1A /* ViewJSONSerializer.m in Sources */ = {isa = PBXBuildFile; fileRef = 0071264514F8956700E738ED /* ViewJSONSerializer.m */; };
- 308685551653F10A00C6FAD7 /* KeyboardCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = C9605E631606BF2900170F88 /* KeyboardCommand.m */; };
+ 30AC65A4165C39FF00DEB0AB /* FrankMac-Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 30AC65A3165C39FF00DEB0AB /* FrankMac-Prefix.pch */; };
+ 30AC65A7165C3A4D00DEB0AB /* OSXKeyboardCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 30AC65A5165C3A4D00DEB0AB /* OSXKeyboardCommand.h */; };
+ 30AC65A8165C3A4D00DEB0AB /* OSXKeyboardCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 30AC65A6165C3A4D00DEB0AB /* OSXKeyboardCommand.m */; };
4C1DD76C12BADFE100E10B8C /* OrientationCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DD76812BADFE100E10B8C /* OrientationCommand.m */; };
4C1DD76D12BADFE100E10B8C /* OrientationCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = 4C1DD76912BADFE100E10B8C /* OrientationCommand.h */; };
4C1DD76E12BADFE100E10B8C /* AppCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C1DD76A12BADFE100E10B8C /* AppCommand.m */; };
@@ -109,8 +111,8 @@
C18A5F17160D528C00DC25F6 /* PublicAutomation.xcodeproj in Resources */ = {isa = PBXBuildFile; fileRef = C18A5F16160D528C00DC25F6 /* PublicAutomation.xcodeproj */; };
C18A5F1E160D547A00DC25F6 /* UIView+PublicAutomation.m in Sources */ = {isa = PBXBuildFile; fileRef = C18A5F1D160D547A00DC25F6 /* UIView+PublicAutomation.m */; };
C18A5F21160D572300DC25F6 /* libPublicAutomation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C18A5F20160D572300DC25F6 /* libPublicAutomation.a */; };
- C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = C9605E621606BF2900170F88 /* KeyboardCommand.h */; };
- C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = C9605E631606BF2900170F88 /* KeyboardCommand.m */; };
+ C9605E641606BF2900170F88 /* IOSKeyboardCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = C9605E621606BF2900170F88 /* IOSKeyboardCommand.h */; };
+ C9605E651606BF2900170F88 /* IOSKeyboardCommand.m in Sources */ = {isa = PBXBuildFile; fileRef = C9605E631606BF2900170F88 /* IOSKeyboardCommand.m */; };
C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */ = {isa = PBXBuildFile; fileRef = C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */; };
C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */ = {isa = PBXBuildFile; fileRef = C9605E681606BFAE00170F88 /* UIImage+Frank.h */; };
C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */ = {isa = PBXBuildFile; fileRef = C9605E691606BFAE00170F88 /* UIImage+Frank.m */; };
@@ -205,9 +207,11 @@
305CA7761642059400C4ACE5 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
305CA7771642059400C4ACE5 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
305CA7781642059400C4ACE5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
- 305CA77B1642059400C4ACE5 /* FrankMac-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "FrankMac-Prefix.pch"; path = "../FrankMac/FrankMac-Prefix.pch"; sourceTree = "<group>"; };
305CA7A2164205F800C4ACE5 /* libCocoaHTTPServerMac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libCocoaHTTPServerMac.a; sourceTree = BUILT_PRODUCTS_DIR; };
305CA7A31642063E00C4ACE5 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
+ 30AC65A3165C39FF00DEB0AB /* FrankMac-Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FrankMac-Prefix.pch"; sourceTree = "<group>"; };
+ 30AC65A5165C3A4D00DEB0AB /* OSXKeyboardCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSXKeyboardCommand.h; sourceTree = "<group>"; };
+ 30AC65A6165C3A4D00DEB0AB /* OSXKeyboardCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OSXKeyboardCommand.m; sourceTree = "<group>"; };
4C1DD76812BADFE100E10B8C /* OrientationCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OrientationCommand.m; sourceTree = "<group>"; };
4C1DD76912BADFE100E10B8C /* OrientationCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OrientationCommand.h; sourceTree = "<group>"; };
4C1DD76A12BADFE100E10B8C /* AppCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppCommand.m; sourceTree = "<group>"; };
@@ -280,8 +284,8 @@
C18A5F16160D528C00DC25F6 /* PublicAutomation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = PublicAutomation.xcodeproj; path = PublicAutomation/PublicAutomation.xcodeproj; sourceTree = "<group>"; };
C18A5F1D160D547A00DC25F6 /* UIView+PublicAutomation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+PublicAutomation.m"; sourceTree = "<group>"; };
C18A5F20160D572300DC25F6 /* libPublicAutomation.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPublicAutomation.a; path = "lib/PublicAutomation/build/Release-iphoneos/libPublicAutomation.a"; sourceTree = "<group>"; };
- C9605E621606BF2900170F88 /* KeyboardCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyboardCommand.h; sourceTree = "<group>"; };
- C9605E631606BF2900170F88 /* KeyboardCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KeyboardCommand.m; sourceTree = "<group>"; };
+ C9605E621606BF2900170F88 /* IOSKeyboardCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOSKeyboardCommand.h; sourceTree = "<group>"; };
+ C9605E631606BF2900170F88 /* IOSKeyboardCommand.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IOSKeyboardCommand.m; sourceTree = "<group>"; };
C9605E661606BF8E00170F88 /* UIView+MapKitWorkaround.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+MapKitWorkaround.m"; sourceTree = "<group>"; };
C9605E681606BFAE00170F88 /* UIImage+Frank.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Frank.h"; sourceTree = "<group>"; };
C9605E691606BFAE00170F88 /* UIImage+Frank.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Frank.m"; sourceTree = "<group>"; };
@@ -539,14 +543,16 @@
D6FA01B714283C4F00576AEE /* EnginesCommand.m */,
A91F3AA415F6E456003F434F /* ExitCommand.h */,
A91F3AA515F6E456003F434F /* ExitCommand.m */,
- C9605E621606BF2900170F88 /* KeyboardCommand.h */,
- C9605E631606BF2900170F88 /* KeyboardCommand.m */,
+ C9605E621606BF2900170F88 /* IOSKeyboardCommand.h */,
+ C9605E631606BF2900170F88 /* IOSKeyboardCommand.m */,
+ 9B3E52AD163FB98300EB24C2 /* LocationCommand.h */,
+ 9B3E52AE163FB98300EB24C2 /* LocationCommand.m */,
D6D05CA711C883AA0081C5A5 /* MapOperationCommand.h */,
D6D05CA811C883AA0081C5A5 /* MapOperationCommand.m */,
4C1DD76912BADFE100E10B8C /* OrientationCommand.h */,
4C1DD76812BADFE100E10B8C /* OrientationCommand.m */,
- 9B3E52AD163FB98300EB24C2 /* LocationCommand.h */,
- 9B3E52AE163FB98300EB24C2 /* LocationCommand.m */,
+ 30AC65A5165C3A4D00DEB0AB /* OSXKeyboardCommand.h */,
+ 30AC65A6165C3A4D00DEB0AB /* OSXKeyboardCommand.m */,
);
name = Commands;
sourceTree = "<group>";
@@ -587,7 +593,7 @@
isa = PBXGroup;
children = (
AA747D9E0F9514B9006C5449 /* Frank_Prefix.pch */,
- 305CA77B1642059400C4ACE5 /* FrankMac-Prefix.pch */,
+ 30AC65A3165C39FF00DEB0AB /* FrankMac-Prefix.pch */,
D67F2ABD13F5F55A00A0BFF1 /* FrankLoader.h */,
D67F2ABE13F5F55A00A0BFF1 /* FrankLoader.m */,
D6D05CA511C883AA0081C5A5 /* FrankServer.h */,
@@ -659,6 +665,8 @@
files = (
302B80411646DE02000F9861 /* NSImage+Frank.h in Headers */,
30412D30165333E300719CD2 /* NSView+FrankImageCapture.h in Headers */,
+ 30AC65A4165C39FF00DEB0AB /* FrankMac-Prefix.pch in Headers */,
+ 30AC65A7165C3A4D00DEB0AB /* OSXKeyboardCommand.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -692,7 +700,7 @@
AB7947BB15C4412300052B74 /* WebSocket.h in Headers */,
D6FA01B714283C4F00576AF1 /* EnginesCommand.h in Headers */,
A91F3AA615F6E456003F434F /* ExitCommand.h in Headers */,
- C9605E641606BF2900170F88 /* KeyboardCommand.h in Headers */,
+ C9605E641606BF2900170F88 /* IOSKeyboardCommand.h in Headers */,
C9605E6A1606BFAE00170F88 /* UIImage+Frank.h in Headers */,
C18A5EF0160D4AB400DC25F6 /* ImageCaptureRoute.h in Headers */,
C18A5EF5160D4AD300DC25F6 /* UIView+ImageCapture.h in Headers */,
@@ -848,7 +856,7 @@
30228E241642161200B1F9E7 /* DumpCommand.m in Sources */,
30228E261642161200B1F9E7 /* EnginesCommand.m in Sources */,
30228E281642161200B1F9E7 /* ExitCommand.m in Sources */,
- 308685551653F10A00C6FAD7 /* KeyboardCommand.m in Sources */,
+ 30AC65A8165C3A4D00DEB0AB /* OSXKeyboardCommand.m in Sources */,
306249F91644E68C00E8C20A /* FrankCommandRoute.m in Sources */,
306249FB1644E68C00E8C20A /* ImageCaptureRoute.m in Sources */,
306249FD1644E68C00E8C20A /* RequestRouter.m in Sources */,
@@ -945,7 +953,7 @@
D6A1D28015A8D05E00EC056C /* UIView+Frank.m in Sources */,
D6FA01B714283C4F00576AEF /* EnginesCommand.m in Sources */,
A91F3AA715F6E456003F434F /* ExitCommand.m in Sources */,
- C9605E651606BF2900170F88 /* KeyboardCommand.m in Sources */,
+ C9605E651606BF2900170F88 /* IOSKeyboardCommand.m in Sources */,
C9605E671606BF8E00170F88 /* UIView+MapKitWorkaround.m in Sources */,
C9605E6B1606BFAE00170F88 /* UIImage+Frank.m in Sources */,
C18A5EF1160D4AB400DC25F6 /* ImageCaptureRoute.m in Sources */,
View
7 FrankMac/FrankMac-Prefix.pch
@@ -1,7 +0,0 @@
-//
-// Prefix header for all source files of the 'FrankMac' target in the 'FrankMac' project
-//
-
-#ifdef __OBJC__
- #import <Cocoa/Cocoa.h>
-#endif
View
13 FrankMac/FrankMac.h
@@ -1,13 +0,0 @@
-//
-// FrankMac.h
-// FrankMac
-//
-// Created by Buckley on 10/31/12.
-//
-//
-
-#import <Foundation/Foundation.h>
-
-@interface FrankMac : NSObject
-
-@end
View
13 FrankMac/FrankMac.m
@@ -1,13 +0,0 @@
-//
-// FrankMac.m
-// FrankMac
-//
-// Created by Buckley on 10/31/12.
-//
-//
-
-#import "FrankMac.h"
-
-@implementation FrankMac
-
-@end
View
8 src/DumpCommand.m
@@ -14,15 +14,15 @@
#import "DumpCommand.h"
#if TARGET_OS_IPHONE
-#define serializeViewType UIView
+#define FrankSerializeViewType UIView
#else
-#define serializeViewType NSObject
+#define FrankSerializeViewType NSObject
#endif
@interface DumpCommand()
@property (nonatomic, readwrite, retain) NSMutableDictionary *classMapping;
-- (NSDictionary *) serializeView: (serializeViewType *) view;
+- (NSDictionary *) serializeView: (FrankSerializeViewType *) view;
- (id) valueForAttribute: (NSString *) attribute onObject: (NSObject *) object;
- (void) loadClassMapping;
@end
@@ -125,7 +125,7 @@ - (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
}
#pragma mark - view serialization
-- (NSDictionary *) serializeView: (serializeViewType *) view {
+- (NSDictionary *) serializeView: (FrankSerializeViewType *) view {
NSMutableDictionary *serializedView = [NSMutableDictionary dictionaryWithCapacity: 20];
[serializedView setObject:NSStringFromClass(view.class) forKey: @"class"];
View
27 src/FrankServer.m
@@ -14,15 +14,20 @@
#import "ImageCaptureRoute.h"
#import "FrankCommandRoute.h"
#import "DumpCommand.h"
-#import "MapOperationCommand.h"
-#import "OrientationCommand.h"
-#import "LocationCommand.h"
#import "ExitCommand.h"
#import "AppCommand.h"
#import "AccessibilityCheckCommand.h"
-#import "KeyboardCommand.h"
#import "EnginesCommand.h"
+#if TARGET_OS_IPHONE
+#import "MapOperationCommand.h"
+#import "OrientationCommand.h"
+#import "LocationCommand.h"
+#import "IOSKeyboardCommand.h"
+#else
+#import "OSXKeyboardCommand.h"
+#endif
+
static NSUInteger __defaultPort = FRANK_SERVER_PORT;
@implementation FrankServer
@@ -43,14 +48,20 @@ - (id) initWithStaticFrankBundleNamed:(NSString *)bundleName
FrankCommandRoute *frankCommandRoute = [FrankCommandRoute singleton];
[frankCommandRoute registerCommand:[[[DumpCommand alloc]init]autorelease] withName:@"dump"];
- [frankCommandRoute registerCommand:[[[MapOperationCommand alloc]init]autorelease] withName:@"map"];
- [frankCommandRoute registerCommand:[[[OrientationCommand alloc]init]autorelease] withName:@"orientation"];
- [frankCommandRoute registerCommand:[[[LocationCommand alloc]init]autorelease] withName:@"location"];
[frankCommandRoute registerCommand:[[[AccessibilityCheckCommand alloc] init]autorelease] withName:@"accessibility_check"];
[frankCommandRoute registerCommand:[[[AppCommand alloc] init]autorelease] withName:@"app_exec"];
- [frankCommandRoute registerCommand:[[[KeyboardCommand alloc] init]autorelease] withName:@"type_into_keyboard"];
[frankCommandRoute registerCommand:[[[EnginesCommand alloc] init]autorelease] withName:@"engines"];
[frankCommandRoute registerCommand:[[[ExitCommand alloc] init] autorelease] withName:@"exit"];
+
+#if TARGET_OS_IPHONE
+ [frankCommandRoute registerCommand:[[[MapOperationCommand alloc]init]autorelease] withName:@"map"];
+ [frankCommandRoute registerCommand:[[[OrientationCommand alloc]init]autorelease] withName:@"orientation"];
+ [frankCommandRoute registerCommand:[[[LocationCommand alloc]init]autorelease] withName:@"location"];
+ [frankCommandRoute registerCommand:[[[IOSKeyboardCommand alloc] init]autorelease] withName:@"type_into_keyboard"];
+#else
+ [frankCommandRoute registerCommand:[[[OSXKeyboardCommand alloc] init]autorelease] withName:@"type_into_keyboard"];
+#endif
+
[[RequestRouter singleton] registerRoute:frankCommandRoute];
StaticResourcesRoute *staticRoute = [[[StaticResourcesRoute alloc] initWithStaticResourceSubDir:bundleName] autorelease];
View
2  src/KeyboardCommand.h → src/IOSKeyboardCommand.h
@@ -9,5 +9,5 @@
#import "FrankCommandRoute.h"
-@interface KeyboardCommand : NSObject<FrankCommand>
+@interface IOSKeyboardCommand : NSObject<FrankCommand>
@end
View
37 src/IOSKeyboardCommand.m
@@ -0,0 +1,37 @@
+//
+// Created by pete on 5/20/12.
+//
+// To change the template use AppCode | Preferences | File Templates.
+//
+
+
+#import "IOSKeyboardCommand.h"
+#import "JSON.h"
+#import <PublicAutomation/UIAutomationBridge.h>
+
+#import "FranklyProtocolHelper.h"
+
+@implementation IOSKeyboardCommand {
+
+}
+
+- (NSString *)generateKeyboardNotPresentErrorResponse {
+ return [FranklyProtocolHelper generateErrorResponseWithReason:@"keyboard not present"
+ andDetails:@"The iOS keyboard is not currently present, so Frank can't use it so simulate typing. You might want to simulate a tap on the thing you want to type into first."];
+}
+
+- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
+
+ NSDictionary *requestCommand = FROM_JSON(requestBody);
+ NSString *textToType = [requestCommand objectForKey:@"text_to_type"];
+
+ if( ![UIAutomationBridge checkForKeyboard] ){
+ return [self generateKeyboardNotPresentErrorResponse];
+ }
+
+ [UIAutomationBridge typeIntoKeyboard:textToType];
+
+ return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
+}
+
+@end
View
82 src/KeyboardCommand.m
@@ -1,82 +0,0 @@
-//
-// Created by pete on 5/20/12.
-//
-// To change the template use AppCode | Preferences | File Templates.
-//
-
-
-#import "KeyboardCommand.h"
-#import "JSON.h"
-
-#if TARGET_OS_IPHONE
-#import <PublicAutomation/UIAutomationBridge.h>
-#endif
-
-#import "FranklyProtocolHelper.h"
-
-@implementation KeyboardCommand {
-
-}
-
-#if TARGET_OS_IPHONE
-- (NSString *)generateKeyboardNotPresentErrorResponse {
- return [FranklyProtocolHelper generateErrorResponseWithReason:@"keyboard not present"
- andDetails:@"The iOS keyboard is not currently present, so Frank can't use it so simulate typing. You might want to simulate a tap on the thing you want to type into first."];
-}
-#else
-- (void) synthesizeNSEventForString:(NSString *)aString
-{
- NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
-
- if (keyWindow != nil)
- {
- NSEvent *event = [NSEvent keyEventWithType:NSKeyDown
- location:NSMakePoint(0, 0)
- modifierFlags:0
- timestamp:0
- windowNumber:[keyWindow windowNumber]
- context:nil
- characters:aString
- charactersIgnoringModifiers:nil
- isARepeat:NO
- keyCode:0];
-
- [[NSApplication sharedApplication] postEvent:event atStart:NO];
-
- event = event = [NSEvent keyEventWithType:NSKeyUp
- location:NSMakePoint(0, 0)
- modifierFlags:0
- timestamp:0
- windowNumber:[keyWindow windowNumber]
- context:nil
- characters:aString
- charactersIgnoringModifiers:nil
- isARepeat:NO
- keyCode:0];
-
- [[NSApplication sharedApplication] postEvent:event atStart:NO];
-
- }
-}
-#endif
-
-- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
-
- NSDictionary *requestCommand = FROM_JSON(requestBody);
- NSString *textToType = [requestCommand objectForKey:@"text_to_type"];
-
-#if TARGET_OS_IPHONE
- if( ![UIAutomationBridge checkForKeyboard] ){
- return [self generateKeyboardNotPresentErrorResponse];
- }
-
- [UIAutomationBridge typeIntoKeyboard:textToType];
-#else
- [self synthesizeNSEventForString:textToType];
-#endif
-
-
- return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
-}
-
-@end
View
14 src/OSXKeyboardCommand.h
@@ -0,0 +1,14 @@
+//
+// OSXKeyboardCommand.h
+// Frank
+//
+// Created by Buckley on 11/20/12.
+//
+//
+
+#import <Foundation/Foundation.h>
+#import "FrankCommandRoute.h"
+
+@interface OSXKeyboardCommand : NSObject<FrankCommand>
+
+@end
View
65 src/OSXKeyboardCommand.m
@@ -0,0 +1,65 @@
+//
+// OSXKeyboardCommand.m
+// Frank
+//
+// Created by Buckley on 11/20/12.
+//
+//
+
+#import "OSXKeyboardCommand.h"
+#import "JSON.h"
+#import "FranklyProtocolHelper.h"
+
+@implementation OSXKeyboardCommand
+
+- (void) synthesizeNSEventForString:(NSString *)aString
+{
+ NSWindow *keyWindow = [[NSApplication sharedApplication] keyWindow];
+
+ if (keyWindow != nil)
+ {
+ for (NSUInteger charIndex = 0; charIndex < [aString length]; ++charIndex)
+ {
+ NSString* eventChar = [aString substringWithRange: NSMakeRange(charIndex, 1)];
+
+ NSEvent *event = [NSEvent keyEventWithType:NSKeyDown
+ location:NSMakePoint(0, 0)
+ modifierFlags:0
+ timestamp:0
+ windowNumber:[keyWindow windowNumber]
+ context:nil
+ characters:eventChar
+ charactersIgnoringModifiers:nil
+ isARepeat:NO
+ keyCode:0];
+
+ [[NSApplication sharedApplication] postEvent:event atStart:NO];
+
+ event = event = [NSEvent keyEventWithType:NSKeyUp
+ location:NSMakePoint(0, 0)
+ modifierFlags:0
+ timestamp:0
+ windowNumber:[keyWindow windowNumber]
+ context:nil
+ characters:eventChar
+ charactersIgnoringModifiers:nil
+ isARepeat:NO
+ keyCode:0];
+
+ [[NSApplication sharedApplication] postEvent:event atStart:NO];
+ }
+
+ }
+}
+
+- (NSString *)handleCommandWithRequestBody:(NSString *)requestBody {
+
+ NSDictionary *requestCommand = FROM_JSON(requestBody);
+ NSString *textToType = [requestCommand objectForKey:@"text_to_type"];
+
+ [self synthesizeNSEventForString:textToType];
+
+ return [FranklyProtocolHelper generateSuccessResponseWithoutResults];
+}
+
+@end
View
12 src/ViewJSONSerializer.h
@@ -8,10 +8,18 @@
#import <Foundation/Foundation.h>
+#if TARGET_OS_IPHONE
+#define FrankColor UIColor
+#define FrankFont UIFont
+#else
+#define FrankColor NSColor
+#define FrankFont NSFont
+#endif
+
@interface ViewJSONSerializer : NSObject
+ (NSObject *) jsonify: (id<NSObject>) obj;
+ (id) extractInstanceFromValue: (NSValue *) value;
-+ (id) extractInstanceFromColor: (id) color;
-+ (id) extractInstanceFromFont: (id) font;
++ (id) extractInstanceFromColor: (FrankColor *) color;
++ (id) extractInstanceFromFont: (FrankFont *) font;
@end
View
10 src/ViewJSONSerializer.m
@@ -65,7 +65,7 @@ + (NSObject *) jsonify: (id<NSObject>) obj {
#pragma mark - Special conversions
#pragma mark UIColor
-+ (id) extractInstanceFromColor: (id) color {
++ (id) extractInstanceFromColor: (FrankColor *) color {
CGColorSpaceModel colorModel = CGColorSpaceGetModel(CGColorGetColorSpace([color CGColor]));
const CGFloat *colors = CGColorGetComponents([color CGColor]);
@@ -97,16 +97,16 @@ + (id) extractInstanceFromColor: (id) color {
return value;
}
-+ (id) extractInstanceFromFont: (id) font {
++ (id) extractInstanceFromFont: (FrankFont *) font {
if(font == nil) {
return nil;
}
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity: 4];
// grab font name, family and size
- [dictionary setObject: [font fontName] forKey: @"fontName"];
- [dictionary setObject: [font familyName] forKey: @"familyName"];
- NSNumber *pointSize = [NSNumber numberWithFloat: [font pointSize]];
+ [dictionary setObject: font.fontName forKey: @"fontName"];
+ [dictionary setObject: font.familyName forKey: @"familyName"];
+ NSNumber *pointSize = [NSNumber numberWithFloat: font.pointSize];
[dictionary setObject: pointSize forKey: @"pointSize"];
return dictionary;
Please sign in to comment.
Something went wrong with that request. Please try again.