aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-29 23:23:35 +0100
committerTeddy Wing2018-10-29 23:23:35 +0100
commit73b27de4dcb823dbb978f154522fc0a383903dce (patch)
tree6cfcbfde18afa250320f0e31aabf0a81949ff6c7
parentec6c2f262c6823460264c6d765443c5f5e5ec604 (diff)
downloadDomeKey-73b27de4dcb823dbb978f154522fc0a383903dce.tar.bz2
HeadphoneKey: Play audio only with the `--audio` command line flag
Allow users to decide whether interface audio (mode activated & deactivated) should play. The flag value is in a `Config`, so to make it easier to pass both the audio flag and the timeout config value to `HeadphoneKey`, rename `initWithTimeout:` to `initWithConfig:`. Only allocate a `Sounds` instance if `--audio` is passed, because there's no reason to allocate memory for it otherwise. Add a `_play_audio` flag as a static variable to make it accessible to the `on_mode_change()` function, just like we did for `sounds_inst`. In `on_mode_change()`, don't play any audio if `_play_audio` is on.
-rw-r--r--DomeKey/AppDelegate.m2
-rw-r--r--DomeKey/HeadphoneKey.h2
-rw-r--r--DomeKey/HeadphoneKey.m16
3 files changed, 15 insertions, 5 deletions
diff --git a/DomeKey/AppDelegate.m b/DomeKey/AppDelegate.m
index bcd4dd0..30bd898 100644
--- a/DomeKey/AppDelegate.m
+++ b/DomeKey/AppDelegate.m
@@ -21,7 +21,7 @@
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
- _headphone_key = [[HeadphoneKey alloc] initWithTimeout:_config->timeout];
+ _headphone_key = [[HeadphoneKey alloc] initWithConfig:_config];
}
@end
diff --git a/DomeKey/HeadphoneKey.h b/DomeKey/HeadphoneKey.h
index fc500cd..1d12e10 100644
--- a/DomeKey/HeadphoneKey.h
+++ b/DomeKey/HeadphoneKey.h
@@ -27,7 +27,7 @@ static const Milliseconds TIMEOUT_DEFAULT = 500;
Milliseconds _timeout;
}
-- (instancetype)initWithTimeout:(Milliseconds)timeout;
+- (instancetype)initWithConfig:(Config *)config;
- (void)handleDeadKey:(HeadphoneButton)button;
- (void)runAction;
diff --git a/DomeKey/HeadphoneKey.m b/DomeKey/HeadphoneKey.m
index a176cbf..11046e7 100644
--- a/DomeKey/HeadphoneKey.m
+++ b/DomeKey/HeadphoneKey.m
@@ -9,6 +9,7 @@
#import "HeadphoneKey.h"
static const Sounds *sounds_inst;
+static BOOL _play_audio;
@implementation HeadphoneKey
@@ -23,7 +24,7 @@ static const Sounds *sounds_inst;
// default should always come from a `Config`, set in the Rust library.
_timeout = TIMEOUT_DEFAULT;
- sounds_inst = [[Sounds alloc] init];
+ _play_audio = NO;
// TODO: Think about moving this logger higher up
dome_key_logger_init();
@@ -39,11 +40,16 @@ static const Sounds *sounds_inst;
return self;
}
-- (instancetype)initWithTimeout:(Milliseconds)timeout
+- (instancetype)initWithConfig:(Config *)config
{
self = [self init];
if (self) {
- _timeout = timeout;
+ _timeout = config->timeout;
+ _play_audio = config->args.audio;
+
+ if (_play_audio) {
+ sounds_inst = [[Sounds alloc] init];
+ }
}
return self;
}
@@ -112,6 +118,10 @@ static const Sounds *sounds_inst;
}
void on_mode_change(ModeChange mode_change) {
+ if (!_play_audio) {
+ return;
+ }
+
switch (mode_change) {
case ModeChange_Activated:
[sounds_inst playModeActivated];