mirror of
https://github.com/ZaidElkurdi/AssistantPlus.git
synced 2025-01-22 11:28:31 +00:00
- Pass-through support
This commit is contained in:
parent
ae6daf45b4
commit
a836b59617
@ -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;
|
||||
|
@ -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 };
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user