| Age | Commit message (Collapse) | Author |
|
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.
|
|
|
|
Seemed to make more sense as it will be printed to the daemon's stderr
log when reloading mappings.
|
|
Don't panic on error. Instead display the error to the user.
|
|
Looking at the function, it makes more sense to put it inside
a `MapAction` impl since it operates on a `MapAction`.
|
|
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.
|
|
This was for the `KeyActionResult` struct, which no longer exists.
|
|
|
|
Instead of just unwrapping, print the error message in our error format.
|
|
Keep FFI functions separate from the rest.
|
|
|
|
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.
|
|
Give a namespace to our C functions to minimise chances of conflicts.
|
|
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.
|
|
warning: unused import: `TimeZone`
--> src/trial.rs:5:44
|
5 | use chrono::{DateTime, FixedOffset, Local, TimeZone};
| ^^^^^^^^
|
= note: #[warn(unused_imports)] on by default
|
|
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>
|
|
|
|
This argument is no longer used, as the current mode is tracked in
`State`.
|
|
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.
|
|
This function isn't used
|
|
No longer needed since 8369a753e24e1e2d986e9988793655f8923e182c. Forgot
to remove this line at the time.
|
|
|
|
Figured out how to persist the map group without re-parsing using the
`State` struct.
|
|
No longer used since we get maps from `State`.
|
|
Commented code and old code that's no longer relevant.
|
|
|
|
Wrap the function in an `extern "C"` function, make it public, and
export it.
|
|
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.
|
|
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.
|
|
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)
|
|
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
|
|
Make it clearer that the function exits.
|
|
|
|
Plus a little dumb pluralisation.
|
|
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.
|
|
Order them like imports, with `std` errors first, followed by extern
crate errors, followed by local errors, alphabetically.
|
|
I was getting these warnings:
warning: unreachable pattern
--> src/trial.rs:41:17
|
40 | DurationError => return trial_expired(),
| ------------- matches any value
41 | e => {
| ^ unreachable pattern
warning: unreachable pattern
--> src/trial.rs:55:9
|
54 | DurationError => trial_expired(),
| ------------- matches any value
55 | Err(e) => (),
| ^^^^^^ unreachable pattern
Wasn't correctly matching the `DurationError`s.
Add an 'error-chain' `ErrorKind` for `DurationError` to make it the same
type as the others matched in the first `match` pattern.
|
|
Don't apply an offset to converted local times as the offset will
incorrectly shift the correct time. Instead, treat the local time as
0/UTC so that no offset gets applied, even if that's not the correct
local timezone.
|
|
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.
|
|
|
|
Reads the encrypted timestamp from the trial file and returns a
`DateTime`.
|
|
Make it not as obvious that it's there.
|
|
The `File::open` function will truncate the file if it exists already:
> This function will create a file if it does not exist, and will
> truncate it if it does.
(https://doc.rust-lang.org/std/fs/struct.File.html#method.create)
We don't want this behaviour, as the file should only be created &
initialised a single time. The trial timestamp should always correspond
to the first trial launch of the program. It doesn't do us any good if
the file is overwritten by DomeKey and updates the trial start time to a
more current value.
Thanks to 'sarnold' (https://stackoverflow.com/users/377270/sarnold) on
Stack Overflow for the clean pattern matching code to match the
`std::io::ErrorKind::AlreadyExists` error:
https://stackoverflow.com/questions/28491759/matching-on-a-specific-error-type/43884600#43884600
|
|
Save an encoded timestamp to a file. This function should be run once if
no trial file is found. The encoded timestamp can then be read on
subsequent launches to determine whether the trial period is still in
effect.
Also add a few function stubs for other actions that seem relevant.
|
|
Make a custom error type because it's trickier to integrate with
'error-chain' given that 'magic-crypt''s `Error` type doesn't implement
the `std::error::Error` trait.
For the same reason, we can't use that as the `cause` for
`DateCryptError::Decrypt`.
This allows us to capture the errors without panicking.
Include some additional cleanups as a result of removing the `use
std::result` and `use errors::*` imports.
|
|
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.
|
|
For the same reason that we renamed the Rust version of this function to
`get_config`, rename this function also. (Since we're not necessarily
getting the config from a file.)
|
|
Enables us to get a `Config` struct from the config file in the
Objective-C app, which will then be passed to the `parse_args()`
function to be further filled in.
|
|
In that case, we should return the default config.
|