aboutsummaryrefslogtreecommitdiffstats
path: root/src
AgeCommit message (Collapse)Author
2018-10-29parse_args(): Don't make `--audio` exclusiveTeddy Wing
This argument is meant to be use in conjunction with the `--daemon` argument. What we had before was preventing audio from getting turned on if `--daemon` was passed first and vice versa. I just added to the existing if-else block without thinking. This makes the condition separate.
2018-10-29config: Add an `--audio` command line flagTeddy Wing
Including this flag will tell the program to play interface audio (namely the sounds for mode activated & deactivated).
2018-10-29Remove audio playing codeTeddy Wing
Remove code that was commented in 44f6a2d5544e3ad49e5e3c52167c045aed1d56b2. Since we weren't able to correctly link to the Core Audio framework from the Objective-C code using this Rust audio code, get rid of it. Instead, we play audio in the Objective-C application.
2018-10-29run_key_action(): Call a function pointer when mode changesTeddy Wing
Take a function pointer argument that will be called whenever a mode is activated or deactivated. We'll be using this on the Objective-C side to play audio when the mode changes.
2018-10-29Turn off audio handling with 'rodio'Teddy Wing
I was getting the following error when building the Objective-C project with the latest audio playing code: ld: warning: object file (.../DomeKey/lib/dome-key-map/target/debug/libdome_key_map.a(minimp3.o)) was built for newer OSX version (10.12) than being linked (10.7) ld: warning: object file (.../DomeKey/lib/dome-key-map/target/debug/libdome_key_map.a(util_helpers.o)) was built for newer OSX version (10.12) than being linked (10.7) ld: warning: object file (.../DomeKey/lib/dome-key-map/target/debug/libdome_key_map.a(aesni_helpers.o)) was built for newer OSX version (10.12) than being linked (10.7) Undefined symbols for architecture x86_64: "_AudioComponentFindNext", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioComponentInstanceNew", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioObjectGetPropertyData", referenced from: cpal::cpal_impl::Device::name::h96cf527e96e03bec in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::Device::supported_formats::h9019a8aeda6b1a55 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::Device::default_format::h1cffda96edcf1b5f in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::EventLoop::build_input_stream::rate_listener::he669322d080b4fd0 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::enumerate::audio_devices::h35df9cd3ad61905a in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) cpal::cpal_impl::enumerate::default_input_device::h4d38066593597777 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) cpal::cpal_impl::enumerate::default_output_device::hfb207f3766c759d9 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) ... "_AudioObjectGetPropertyDataSize", referenced from: cpal::cpal_impl::Device::supported_formats::h9019a8aeda6b1a55 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::enumerate::audio_devices::h35df9cd3ad61905a in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) "_AudioOutputUnitStart", referenced from: coreaudio::audio_unit::AudioUnit::start::h0ceab6edb211b577 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioOutputUnitStop", referenced from: coreaudio::audio_unit::AudioUnit::stop::h2929fdfd118ee7be in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioUnitGetProperty", referenced from: coreaudio::audio_unit::get_property::h58ff3c44f7ccc617 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::get_property::habcd9010fa8dc136 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioUnitInitialize", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioUnitSetProperty", referenced from: coreaudio::audio_unit::set_property::h5e5a6451ac49ed54 in libdome_key_map.a(rodio-d252ad0025b836aa.rodio15.rcgu.o) coreaudio::audio_unit::set_property::h86353d3d091c7540 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::set_property::hbaa7f6c599c38fa2 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::set_property::hf450b8b66e374b66 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioUnitUninitialize", referenced from: _$LT$coreaudio..audio_unit..AudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::h0a1df660f851dad4 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) After setting: $ export MACOSX_DEPLOYMENT_TARGET=10.7 in the shell, the error changed to: Undefined symbols for architecture x86_64: "_AudioComponentFindNext", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioComponentInstanceNew", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioObjectGetPropertyData", referenced from: cpal::cpal_impl::Device::name::h96cf527e96e03bec in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::Device::supported_formats::h9019a8aeda6b1a55 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::Device::default_format::h1cffda96edcf1b5f in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::EventLoop::build_input_stream::rate_listener::he669322d080b4fd0 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::enumerate::audio_devices::h35df9cd3ad61905a in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) cpal::cpal_impl::enumerate::default_input_device::h4d38066593597777 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) cpal::cpal_impl::enumerate::default_output_device::hfb207f3766c759d9 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) ... "_AudioObjectGetPropertyDataSize", referenced from: cpal::cpal_impl::Device::supported_formats::h9019a8aeda6b1a55 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal0.rcgu.o) cpal::cpal_impl::enumerate::audio_devices::h35df9cd3ad61905a in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal8.rcgu.o) "_AudioOutputUnitStart", referenced from: coreaudio::audio_unit::AudioUnit::start::h0ceab6edb211b577 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioOutputUnitStop", referenced from: coreaudio::audio_unit::AudioUnit::stop::h2929fdfd118ee7be in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioUnitGetProperty", referenced from: coreaudio::audio_unit::get_property::h58ff3c44f7ccc617 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::get_property::habcd9010fa8dc136 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) "_AudioUnitInitialize", referenced from: coreaudio::audio_unit::AudioUnit::new_with_flags::hc9c3029c77a9ba1d in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioUnitSetProperty", referenced from: coreaudio::audio_unit::set_property::h5e5a6451ac49ed54 in libdome_key_map.a(rodio-d252ad0025b836aa.rodio15.rcgu.o) coreaudio::audio_unit::set_property::h86353d3d091c7540 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::set_property::hbaa7f6c599c38fa2 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) coreaudio::audio_unit::set_property::hf450b8b66e374b66 in libdome_key_map.a(cpal-b228ca6a35ab9c25.cpal12.rcgu.o) "_AudioUnitUninitialize", referenced from: _$LT$coreaudio..audio_unit..AudioUnit$u20$as$u20$core..ops..drop..Drop$GT$::drop::h0a1df660f851dad4 in libdome_key_map.a(coreaudio-b5e291d8855015a5.coreaudio3.rcgu.o) ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Couldn't figure out how to get past this, so decided to move the audio playing into the Objective-C code. It's been something of a theme, where if something doesn't work in one language (like dome_key_event_source_simulator), write it in the other. Here we just comment out the audio-related code so I can work on connecting mode activation and deactivation and audio playing. I'll be completely removing this code soon.
2018-10-29sounds: Ignore "test" that plays soundsTeddy Wing
It's not exactly a real test, more of a smoke test. And it plays the actual audio, which isn't ideal when running the test suite.
2018-10-29key_code: Remove unneeded commentsTeddy Wing
* Commented code is no longer needed * Commented reference constants have served their purpose
2018-10-29map::run_key_action(): Remove `unwrap`s when playing soundsTeddy Wing
Log errors to stderr logger.
2018-10-29ffi::run_key_action(): Add `PlayAudio` argumentTeddy Wing
Mirror the `map::run_key_action()` function and add an extra `PlayAudio` argument, which will control whether audio cues are played when a mode is activated or deactivated. The Objective-C code will pass in this value based on the value of a `Config` setting, which will have come from a command line argument.
2018-10-29run_key_action(): Remove TODO commentTeddy Wing
This has already been handled. See the condition just below the comment.
2018-10-29map::run_key_action(): Add conditional argument for playing audioTeddy Wing
Play audio on mode activation and deactivation depending on the value of the new argument. Decided to make it an enum instead of a bool for better readability. Will need to get rid of the `unwrap`s.
2018-10-29Rename `run_key_action_for_mode` to `run_key_action`Teddy Wing
Now that this function no longer takes a "current mode" argument, the "mode" part of the name doesn't make sense.
2018-10-28Add mode activated and deactivated soundsTeddy Wing
* Remove test "activ.wav" file * Add mode activated and deactivated audio files * Add two new methods to play these two sounds without having to pass in `MODE_ACTIVATED` or `MODE_DEACTIVATED` from outside the module * Make `play_audio()` private The 'rodio' crate supports WAV, FLAC, MP3, and Vorbis file types. Tried using OGG and MP3 versions of the audio, which sound effectively the same played in an audio player, and have much better compression, but 'rodio' kept playing them choppily, in a weird staccato. Maybe the sample rate wasn't right? No idea what the problem was. Didn't really have the same problem with the WAV files. Unfortunate because the OGG files were only 16K, and the MP3 files were 32K, while the WAV files are 348K. Would much rather have smaller size files, but if the sounds play incorrectly, there's no easy way around it.
2018-10-28Add `play_audio()` functionTeddy Wing
Create a new function that encapsulates the code we experimented with for playing audio. Clean up what we had and handle errors by passing them back in a `Result`. This allows us to encapsulate, audio playing so we can do it in a single action during mode switching.
2018-10-28Test of playing an audio fileTeddy Wing
Success! Using the 'rodio' crate to play an audio file. Include the audio file in the binary using `include_bytes!`. This makes it so we get a single self-contained binary. Struggled a bit with getting the reader/array to `Seek`, but finally figured out `Cursor` and got it working. Cool.
2018-10-28Remove unused cratesTeddy Wing
2018-10-28MapAction::parse(): Use `error!` instead of `dkeprintln!` to log errorTeddy Wing
Seemed to make more sense as it will be printed to the daemon's stderr log when reloading mappings.
2018-10-28MapAction::parse(): Log error instead of unwrappingTeddy Wing
Don't panic on error. Instead display the error to the user.
2018-10-28MapGroup: Move `parse_action()` to `MapAction`Teddy Wing
Looking at the function, it makes more sense to put it inside a `MapAction` impl since it operates on a `MapAction`.
2018-10-28MapGroup::parse_action(): Accept `MapKind::Command` variant handlerTeddy Wing
I had written that TODO when I thought we were going to be parsing `Action::Command`s. I ended up completely getting rid of `Action::Command`, and putting commands in `Action::String`s instead.
2018-10-28ffi: Remove `ActionKind` enumTeddy Wing
This was for the `KeyActionResult` struct, which no longer exists.
2018-10-28parser: Remove old commented `Action` typeTeddy Wing
2018-10-27dome_key_logger_init(): Log `Err` instead of `unwrap()`Teddy Wing
Instead of just unwrapping, print the error message in our error format.
2018-10-27Move non-FFI functions from `ffi.rs` to `map.rs`Teddy Wing
Keep FFI functions separate from the rest.
2018-10-27lib.rs: Remove unneeded `use`Teddy Wing
2018-10-27Rename `cocoa_bridge.rs` to `ffi.rs`Teddy Wing
When I first created the file, it was going to be used to call Cocoa methods using the 'cocoa' crate. It's since turned into a module that contains C functions called by Objective-C code. This new name makes more sense. We'll need to move one or two non-FFI functions outside of this module for better organisation.
2018-10-27Prefix all extern C functions with "dome_key_"Teddy Wing
Give a namespace to our C functions to minimise chances of conflicts.
2018-10-27c_parse_args(): Remove unused `config` variableTeddy Wing
Correct this warning: warning: unused variable: `config` --> src/cocoa_bridge.rs:215:9 | 215 | let config = config::parse_args(&args, config); | ^^^^^^ help: consider using `_config` instead | = note: #[warn(unused_variables)] on by default Finished dev [unoptimized + debuginfo] target(s) in 18.97s The `config::parse_args()` function will modify the pointer that we return from here, so we don't need to use its return value.
2018-10-27trial: Fix unused import warningTeddy Wing
warning: unused import: `TimeZone` --> src/trial.rs:5:44 | 5 | use chrono::{DateTime, FixedOffset, Local, TimeZone}; | ^^^^^^^^ | = note: #[warn(unused_imports)] on by default
2018-10-27parser: Make `KeyboardKey` privateTeddy Wing
Get rid of these warnings: warning: private type `parser::Character` in public interface (error E0446) --> src/parser.rs:72:15 | 72 | Character(Character), | ^^^^^^^^^ | = note: #[warn(private_in_public)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537> warning: private type `parser::KeyCode` in public interface (error E0446) --> src/parser.rs:73:13 | 73 | KeyCode(KeyCode), | ^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #34537 <https://github.com/rust-lang/rust/issues/34537>
2018-10-27run_key_action_for_mode(): Remove unused `mode` variableTeddy Wing
2018-10-27c_run_key_action(): Remove `mode` argumentTeddy Wing
This argument is no longer used, as the current mode is tracked in `State`.
2018-10-27Action: Remove `Action::Command` variantTeddy Wing
I wasn't using it. At first I added it because it made sense, but ultimately I ended up using `Action::String` for commands instead because that was easier.
2018-10-27Remove `Action` implTeddy Wing
This function isn't used
2018-10-27datetime_local_to_fixed_offset(): Remove unused variableTeddy Wing
No longer needed since 8369a753e24e1e2d986e9988793655f8923e182c. Forgot to remove this line at the time.
2018-10-27c_run_key_action(): Remove debug print statementsTeddy Wing
2018-10-27run_key_action_for_mode(): Remove commentTeddy Wing
Figured out how to persist the map group without re-parsing using the `State` struct.
2018-10-27run_key_action_for_mode(): Remove `sample_maps`Teddy Wing
No longer used since we get maps from `State`.
2018-10-27cocoa_bridge: Delete unused codeTeddy Wing
Commented code and old code that's no longer relevant.
2018-10-27Delete unused importsTeddy Wing
2018-10-27Make `do_trial()` accessible via FFITeddy Wing
Wrap the function in an `extern "C"` function, make it public, and export it.
2018-10-26print_usage(): Exit after printing usageTeddy Wing
Otherwise we might end up printing things like error messages from the license check. Not very nice-looking to have that after the help message output.
2018-10-26config: Add `--version` flagTeddy Wing
Should print the version of the program. Doesn't actually do any printing in Rust, because the Rust library's version number is different from the DomeKey program version. We just indicate to the Objective-C code that it should print the version number.
2018-10-26Add a `--license` command line argumentTeddy Wing
Add a new argument that allows users to pass in the path to a license file. Doing so should get picked up by the Objective-C code which will copy and validate the license. In order for the Objective-C code to pick up the path string, we add a `license` field to the `Config.Args` struct. The new `license` field is a `*mut c_char`, which means we can't derive Default any more and need to implement a custom `Default` impl for `Args`. Additionally, 'getopts' gives us a Rust string (of course), which needs to be converted into a raw `CString` before we can stick it in the `license` field in `Args`. I previously wrote `dkeprintln` to be able to print an error here at the conversion point between `CString` and raw C string. Since we used `CString#into_raw()`, we need to call `from_raw()` on the pointer to free it, otherwise we end up with a memory leak. This necessitated adding some additional code to `config_free()` to free the `license` field if non-null. In order to access `config.args.license` from within `config_free()`, I also needed to make the `args` and `license` struct fields public, since the free function is in a different module. Instead of making only those two fields public, I decided to make them all public, as all the fields are technically accessible from C code, and are needed by that C code. Finally, move the module declaration of `prefix_println` to the top of the module list instead of listing it alphabetically, because otherwise any modules declared before it (like `config`) don't get access to its macro. Also add a `#[macro_use]` attribute to the module declaration because we do want to export its macro. (https://stackoverflow.com/questions/26731243/how-do-i-use-a-macro-across-module-files#comment78329437_31749071)
2018-10-25Add `dkeprintln` macroTeddy Wing
This macro functions exactly like `eprintln` while prepending the string "dome-key: error: " to all messages. Allows us to give a uniform prefix to printed rerrors. Used the `println` macro as a reference: https://doc.rust-lang.org/src/std/macros.rs.html#157-162
2018-10-23trial: Rename `trial_expired()` to `exit_trial_expired()`Teddy Wing
Make it clearer that the function exits.
2018-10-23trial: Add docstrings, clean up commentsTeddy Wing
2018-10-23print_trial_days(): Add a real output messageTeddy Wing
Plus a little dumb pluralisation.
2018-10-23decode_datetime(): Fix incorrect encoded & IV string splittingTeddy Wing
I was using `rsplitn` to split the encoded value into an encrypted timestamp and initialisation vector. Originally, I had used `splitn`, but upon discovering `rsplitn` decided to use that instead to ensure we captured the initialisation vector first, and that anything else would be captured to a single string. Didn't realise, though, that `rsplitn` orders element in reverse order compared to `splitn`. Correct the capture order.
2018-10-23error_chain!::foreign_links: Reorder `ErrorKind` definitionsTeddy Wing
Order them like imports, with `std` errors first, followed by extern crate errors, followed by local errors, alphabetically.