| Age | Commit message (Collapse) | Author |
|
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.
|
|
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.
|
|
|
|
This function serves as the entry point to all trial functionality. When
called, it will try to determine the number of days remaining in the
trial.
* If the trial period is in progress, the number of days remaining will
be printed.
* If an error is encountered involving the trial file, or the trial has
expired, an error message is printed and the program exits.
* Finally, if an unrelated error occurs, print the error without
exiting.
Change `DateTime<Local>`s to `DateTime<FixedOffset>`s in order to have
uniform date types. Otherwise we run into trouble when comparing dates
and when querying functions with different date typs.
TODO: This fails the tests (unless your local timezone is UTC
presumably) because the local time gets stripped of its offset and the
correct offset gets reapplied, incorrectly shifting the time. Figure out
a way to have uniform datetime types without muffing up the timezone
offsets.
|
|
Add functions to encrypt and decrypt a timestamp. We'll be using those
functions to write the encrypted timestamp of the first trial launch
date to a file.
Decided to go for some light encryption instead of just storing a plain
or base64-encoded value. Still need to come up with a key, but that will
be stored as a plain string in the binary.
Need a way to capture the results so we don't end up panicking. Trouble
is, 'magic-crypt' doesn't implement the required `Error` traits, so I
can't just slot it into 'error-chain'. Still trying to work out how to
deal with that.
Also add a function to get the days remaining from now.
|
|
This new module will contain functions to calculate trial days.
Here we implement a function to calculate the days remaining in a trial
period.
If there are less than 0 days remaining, it returns an error result.
Couldn't use 'error-chain' because it was complaining about `Debug` and
`PartialEq` not being defined. Don't know if it's possible to implement
those traits on 'error-chain''s ErrorKind`, but it was complicated
enough that I ended up not bothering. Went with 'quick_error' instead to
create a custom error type without having to `impl` all the required
traits.
|
|
|
|
Make it easier to handle errors with `Result` types from other crates.
|
|
A new function that will read a TOML config file. Doesn't currently
access the filesystem. This commit is mostly supporting code to allow
that to work.
* Add the 'toml' crate
* `parse_args()`: Take a mutable `Config` and return that config instead
of creating a new one. The recipe will now be to read the config from
a file first and then pass that config to this function to be updated.
* Modify `c_parse_args()` to take a `*Config` and mirror the new method
signature of `parse_args()`
|
|
This new field will be used by the calling Objective-C code as the
timeout between multi-button maps.
It will be defined in a `config.toml` file in the XDG config directory,
with a default if unspecified. That part of the code hasn't been written
yet, but we've prepared by deriving Serde `Deserialize` on the `Config`
struct in order to deserialise a TOML config file.
The latest Serde is v1.0.80, but we can't use it because 'cbindgen'
depends on an older version. We had been using 'cbindgen' v0.6.3, which
depends on serde v1.0.21. Decided to update 'cbindgen' in order to use a
newer version of Serde, but that puts us at v1.0.58 instead of the
latest:
error: failed to select a version for `serde_derive`.
... required by package `cbindgen v0.6.6`
... which is depended on by `dome-key-map v0.0.1 (file:///Users/tw/Documents/Development/dome-key-map)`
versions that meet the requirements `= 1.0.58` are: 1.0.58
all possible versions conflict with previously selected packages.
previously selected package `serde_derive v1.0.80`
... which is depended on by `dome-key-map v0.0.1 (file:///Users/tw/Documents/Development/dome-key-map)`
failed to select a version for `serde_derive` which could resolve this conflict
|
|
Segfaults on key_code.rs:184:
error: process didn't exit successfully: `.../dome-key-map/target/debug/deps/dome_key_map-0efa5c8428fad354 send_media_key --nocapture` (signal: 11, SIGSEGV: invalid memory reference)
shell returned 101
This is my attempt to use first the 'cocoa' and 'core-graphics' crates,
then the 'objc' crate (because I hoped that would get around the
segfault), to simulate a media key event.
Once I got the types right and the code compiling, I couldn't get past
segfaults. After struggling with this for over a day and not being able
to figure out what on earth is going on, I wrote the exact same thing in
Objective-C and it just worked. That's it, I'm done with this. This code
is going to be expunged and I'm going to take a C function pointer in
the function that runs map actions that will simulate media key presses
in real Cocoa/Carbon. Enough of this headache.
|
|
Thanks to Lifthrasiir for the detailed information about reducing Rust
compiled binary size:
https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-large.html
Using link-time optimisation gets our release build built with
cargo build --release
down from 13 Mb to 2 Mb. Pretty good.
Using
RUSTFLAGS="-C opt-level=s" cargo build --release
# or
RUSTFLAGS="-C opt-level=z" cargo build --release
brought it down additionally to 1.9 Mb. Still trying to decide if I want
to keep that. Think I might, but will add it later.
|
|
Media keys (rewind, play/pause, fast forward on Mac function keys) are
different from normal keys. These use a different API, and sending
events to simulate those keys is different.
Here's a first stab at getting something working for posting simulated
media key events. This will be used for new special keys in mapping
actions. Haven't tested this at all yet, just happy that it finally
compiles.
Follow the two Stack Overflow answers referenced in the comments (from
Albert https://stackoverflow.com/users/133374/albert and Nick Sweeting
https://stackoverflow.com/users/2156113/nick-sweeting).
Add the `core-graphics` crate to give us access to `CGEvent`,
`CGKeyCode`, and related types.
Also include some commented `CGKeyCode` definitions for future use.
|
|
Decided to do command-line option parsing in Rust instead of C as it
seemed like it would be easier this way.
|
|
Facilitate logging to stderr.
|
|
Facilitate interacting with config files in XDG directories.
|
|
To simulate key presses.
|
|
Add a new wrapper function for `run_key_action` that uses C appropriate
inputs & outputs and calls into our Rusty `run_key_action`. This new
function now correctly gets a header generated for it by 'cbindgen'.
Immense thanks to Jake Goulding on the Rust FFI Omnibus for showing me
how to pass a slice argument from C:
http://jakegoulding.com/rust-ffi-omnibus/slice_arguments/
In order to pass the slice from C, we need to pass a C array and its
length to the function. Cool.
|
|
* Add the 'cbindgen' crate to help us auto-generate a C header for our
exported FFI enums/structs/functions
* Add a `build.rs` to generate the C header using cbindgen
* Add a rough config for 'cbindgen'
* Export everything from the `cocoa_bridge` crate to include the
`KeyActionResult` struct
* Commit the C header generated by 'cbindgen'
Looks promising. We do, however, have some things to correct. We can't
use `Option` in C, for instance, so we'll need to fix that in our
`KeyActionResult`. Similarly, we need to rework the `run_key_action()`
function to make it accessible as a C interface. Right now it returns an
`Option`, which isn't going to work, and I'm not sure if the slice input
translates. That (any maybe more) is why it doesn't get generated by
'cbindgen' into the header output file.
|
|
* Add `#[repr(C)]` on `HeadphoneButton` to hopefully be able to use it
outside Rust
* Add `#[no_mangle]` to `run_key_action()`
* Export `run_key_action()` as a public function
* Build the crate as a static library
(But holy cow, a 19 MB library file?)
|
|
This will enable us to use Foundation data structures to hopefully
export into a Cocoa project.
|
|
For parsing.
|
|
$ cargo init --lib
$ rustc --version
rustc 1.28.0 (9634041f0 2018-07-30)
|