added url handler speaker: so one can send text programatically and start reading

This commit is contained in:
Jeena 2015-04-12 00:43:47 +02:00
parent b323b82f55
commit 33ad89b0d1
2 changed files with 38 additions and 2 deletions

View file

@ -28,5 +28,14 @@
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>SpeakerApplication</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>speaker</string>
</array>
</dict>
</array>
</dict>
</plist>

View file

@ -46,6 +46,28 @@
[self initLanugageMenu];
}
- (void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
[[NSAppleEventManager sharedAppleEventManager]
setEventHandler:self
andSelector:@selector(handleURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass
andEventID:kAEGetURL];
}
- (void)handleURLEvent:(NSAppleEventDescriptor*)event
withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
NSString* text = [[[[event paramDescriptorForKeyword:keyDirectObject]
stringValue] substringFromIndex:8] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if ([synth isSpeaking]) {
[self speakAction:self];
}
[textView setString:text];
[self speakAction:self];
}
- (void)initLanugageMenu
{
NSString *startName = [[NSUserDefaults standardUserDefaults] stringForKey:@"languageVoiceName"];
@ -57,6 +79,7 @@
NSMutableArray *langs = [NSMutableArray arrayWithCapacity:[voices count]];
NSMutableArray *defaultVoices = [[NSUserDefaults standardUserDefaults] mutableArrayValueForKey:@"defaultVoices"];
NSLog(@"%@", defaultVoices);
for (NSInteger i = 0; i < [voices count]; i++)
{
@ -81,7 +104,7 @@
item.tag = i;
[[country submenu] addItem:item];
if ([defaultVoices indexOfObjectIdenticalTo:item.title] != NSNotFound) {
if ([defaultVoices indexOfObject:item.title] != NSNotFound) {
item.state = NSOnState;
}
@ -103,7 +126,11 @@
for (NSMenuItem *child in parent.submenu.itemArray) {
if (child.state == NSOnState) {
[defaultVoices removeObjectIdenticalTo:child.title];
for (NSString *voice in defaultVoices) {
if ([child.title isEqualToString:voice]) {
[defaultVoices removeObject:voice];
}
}
child.state = NSOffState;
}
}