From a836b59617c5988b609afb75d257bdd2dc6af6a2 Mon Sep 17 00:00:00 2001 From: Zaid Elkurdi Date: Thu, 9 Apr 2015 19:45:25 -0700 Subject: [PATCH] - Pass-through support --- .../assistantplusapp/APActivatorListener.h | 1 + .../assistantplusapp/APActivatorListener.m | 9 +++++++ .../ListenerDetailViewController.m | 25 ++++++++++++++++--- .../APActivatorListener.h | 1 + .../APActivatorListener.m | 3 +++ .../APPluginSystem.m | 6 +++-- 6 files changed, 39 insertions(+), 6 deletions(-) diff --git a/assistant+/assistantplusapp/APActivatorListener.h b/assistant+/assistantplusapp/APActivatorListener.h index 0777173..fb62a34 100644 --- a/assistant+/assistantplusapp/APActivatorListener.h +++ b/assistant+/assistantplusapp/APActivatorListener.h @@ -13,6 +13,7 @@ @property (nonatomic, strong) NSString *name; @property (nonatomic, strong) NSString *trigger; @property (nonatomic) BOOL enabled; +@property (nonatomic) BOOL willPassthrough; @property (nonatomic, strong) NSString *uniqueId; -(id)initWithDictionary:(NSDictionary*)dict; diff --git a/assistant+/assistantplusapp/APActivatorListener.m b/assistant+/assistantplusapp/APActivatorListener.m index fd1bef2..621cec0 100644 --- a/assistant+/assistantplusapp/APActivatorListener.m +++ b/assistant+/assistantplusapp/APActivatorListener.m @@ -15,13 +15,21 @@ NSString *name = dict[@"name"]; NSString *trigger = dict[@"trigger"]; NSString *identifier = dict[@"identifier"] ? dict[@"identifier"] : [NSString stringWithFormat:@"%@", [NSDate date]]; + BOOL enabled = false; if (dict[@"enabled"]) { enabled = [dict[@"enabled"] boolValue]; } + + BOOL passthrough = false; + if (dict[@"passthrough"]) { + enabled = [dict[@"passthrough"] boolValue]; + } + self.name = name; self.trigger = trigger; self.enabled = enabled; + self.willPassthrough = passthrough; self.uniqueId = identifier; } return self; @@ -31,6 +39,7 @@ return @{@"name" : self.name ? self.name : @"Untitled", @"trigger" : self.trigger ? self.trigger : @"", @"enabled" : self.enabled ? [NSNumber numberWithBool:self.enabled] : [NSNumber numberWithBool:NO], + @"passthrough": self.willPassthrough ? [NSNumber numberWithBool:self.willPassthrough] : [NSNumber numberWithBool:NO], @"identifier" : self.uniqueId }; } diff --git a/assistant+/assistantplusapp/ListenerDetailViewController.m b/assistant+/assistantplusapp/ListenerDetailViewController.m index 9633963..4282a84 100644 --- a/assistant+/assistantplusapp/ListenerDetailViewController.m +++ b/assistant+/assistantplusapp/ListenerDetailViewController.m @@ -11,6 +11,7 @@ @interface ListenerDetailViewController () @property (strong, nonatomic) APActivatorListener *currListener; @property (strong, nonatomic) UISwitch *enabledSwitch; +@property (strong, nonatomic) UISwitch *passthroughSwitch; @property (strong, nonatomic) UITextField *nameField; @property (strong, nonatomic) UITextView *triggerField; @property (nonatomic) BOOL didChange; @@ -33,12 +34,23 @@ UIView *switchBackground = [[UIView alloc] initWithFrame:CGRectMake(0, 90, self.view.frame.size.width, 50)]; switchBackground.backgroundColor = [UIColor whiteColor]; - UILabel *switchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)]; - switchLabel.text = @"Enabled:"; + + UILabel *enabledSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 50)]; + enabledSwitchLabel.text = @"Enabled:"; + + UILabel *passthroughSwitchLabel = [[UILabel alloc] initWithFrame:CGRectMake(170, 0, 80, 50)]; + passthroughSwitchLabel.text = @"Pass-Through:"; + self.enabledSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)]; [self.enabledSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged]; self.enabledSwitch.on = self.currListener.enabled; - [switchBackground addSubview:switchLabel]; + + self.passthroughSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 9.5, 51, 31)]; + [self.passthroughSwitch addTarget:self action:@selector(didToggleSwitch:) forControlEvents:UIControlEventValueChanged]; + self.passthroughSwitch.on = self.currListener.willPassthrough; + + [switchBackground addSubview:enabledSwitchLabel]; + [switchBackground addSubview:passthroughSwitchLabel]; [switchBackground addSubview:self.enabledSwitch]; [self.view addSubview:switchBackground]; @@ -81,7 +93,12 @@ - (void)didToggleSwitch:(UISwitch*)theSwitch { self.didChange = YES; - self.currListener.enabled = theSwitch.on; + + if (theSwitch == self.enabledSwitch) { + self.currListener.enabled = theSwitch.on; + } else if (theSwitch == self.passthroughSwitch) { + self.currListener.willPassthrough = theSwitch.on; + } } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { diff --git a/assistant+/assistantpluspluginmanager/APActivatorListener.h b/assistant+/assistantpluspluginmanager/APActivatorListener.h index 65b5811..f623a71 100644 --- a/assistant+/assistantpluspluginmanager/APActivatorListener.h +++ b/assistant+/assistantpluspluginmanager/APActivatorListener.h @@ -13,5 +13,6 @@ @property (strong, nonatomic) NSString *triggerString; @property (strong, nonatomic) NSRegularExpression *trigger; @property (strong, nonatomic) NSString *identifier; +@property (nonatomic) BOOL willPassthrough; - (id)initWithDictionary:(NSDictionary*)dict; @end diff --git a/assistant+/assistantpluspluginmanager/APActivatorListener.m b/assistant+/assistantpluspluginmanager/APActivatorListener.m index dc604f0..5c19f6e 100644 --- a/assistant+/assistantpluspluginmanager/APActivatorListener.m +++ b/assistant+/assistantpluspluginmanager/APActivatorListener.m @@ -16,6 +16,9 @@ self.triggerString = dict[@"trigger"]; self.trigger = [NSRegularExpression regularExpressionWithPattern:self.triggerString options:NSRegularExpressionCaseInsensitive error:nil]; self.identifier = dict[@"identifier"]; + + NSNumber *pass = dict[@"passthrough"]; + self.willPassthrough = pass ? [pass boolValue] : NO; } return self; } diff --git a/assistant+/assistantpluspluginmanager/APPluginSystem.m b/assistant+/assistantpluspluginmanager/APPluginSystem.m index 5ff0238..a44860a 100644 --- a/assistant+/assistantpluspluginmanager/APPluginSystem.m +++ b/assistant+/assistantpluspluginmanager/APPluginSystem.m @@ -66,8 +66,10 @@ static NSString *EVENT_PREFIX = @"APListener"; if (match.numberOfRanges > 0) { NSString *eventName = [NSString stringWithFormat:@"%@%@", EVENT_PREFIX, currListener.identifier]; [LASharedActivator sendEventToListener:[LAEvent eventWithName:eventName mode:LASharedActivator.currentEventMode]]; - [currSession sendRequestCompleted]; - return YES; + if (!currListener.willPassthrough) { + [currSession sendRequestCompleted]; + return YES; + } } } }