-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Really basic implementation for passing scripting commands through UR…
…L scheme pomodoro://. An example: pomodoro://start Maps DIRECTLY to the commands in Pomodoro/src/<url>Command.(h,m) Doesn't (yet) pass arguments.
- Loading branch information
1 parent
c2dd292
commit 66fb909
Showing
5 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface OpenUrlCommand : NSScriptCommand | ||
|
||
- (id)performDefaultImplementation; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#import "OpenUrlCommand.h" | ||
|
||
@implementation OpenUrlCommand | ||
|
||
- (id)performDefaultImplementation | ||
{ | ||
NSURL *url = [NSURL URLWithString:[self directParameter]]; | ||
if (!url) return @"A parameter is required, e.g. pomodoro://start"; | ||
|
||
//accept any capitalization | ||
NSString *command = [[url host] capitalizedString]; | ||
|
||
//Special case for CamelCase commands (if there were more than say, two, we'd consider doing this more intelligently. | ||
if ([command isEqualToString:@"Externalinterrupt"]) command = @"ExternalInterrupt"; | ||
if ([command isEqualToString:@"Internalinterrupt"]) command = @"InternalInterrupt"; | ||
//Disallow this possible loop. | ||
if ([command isEqualToString:@"Openurl"]) command = nil; | ||
|
||
//TODO pass along arguments from query. | ||
|
||
Class CommandClass = NSClassFromString([NSString stringWithFormat:@"%@Command", command]); | ||
if (CommandClass && [CommandClass isSubclassOfClass:[NSScriptCommand class]]) | ||
{ | ||
return [[[CommandClass alloc] init] performDefaultImplementation]; | ||
} | ||
|
||
return [NSString stringWithFormat:@"Didn't understand the command '%@'", [url host]]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters