rust-reader icon indicating copy to clipboard operation
rust-reader copied to clipboard

Crashes if already running

Open steinbro opened this issue 1 year ago • 3 comments

If you try to launch rust-reader when it's already running, the second instance crashes: thread 'main' panicked at 'called Option::unwrap()on aNone value', src\main.rs:134:52

This is actually kind of the desired outcome (one instance remains running), but this behavior seems mostly accidental, and the crash has tripped me up a few times during testing. The error appears to be related to setting hotkeys, which I assume fails if that hotkey is already bound to the other instance of rust-reader.

Is there a "right" way to check if an instance is already running? Presumably setting the hotkey could fail for other reasons. FWIW, NVDA, by comparison, appears to terminate the previous instance when you launch a new one.

steinbro avatar Apr 18 '23 11:04 steinbro

It is an intended feature that it will not let you open more than one at a time. It is also really convenient that opening a new copy does not lose the document you are reading in the existing copy.

I vaguely remember researching the "right" way to do things, but not coming up with much. I am open to better solutions if you find them.

Also our general error handling code is not great, (This project predates ?) I would also be open to improving it. Either using modern crates (like anyhow) or even by replacing unwrap with expect.

Eh2406 avatar Apr 18 '23 15:04 Eh2406

Ah, good to know that I should be wary of inadvertently imitating bad error-handling habits here.

Speaking of modern crates, could wide_string.rs be entirely replaced by the widestring crate, or does the implementation here do anything special?

steinbro avatar Apr 18 '23 22:04 steinbro

I have not used the widestring crate. It is entirely possible that it does everything we need and more. If you would like to give it a try, let me know how it goes.

wide_string.rs has some code for efficiently converting a position between encodings. One place I intended to use it was for converting a position as reported by SAPI back to the position in the UTF8 string held by rust. I don't remember if I actually use that code. Another place I intended to use it, and I'm pretty sure I didn't, is to convert from the position SAPI reported in the wide string cleaned by the regex back to a position in the original string. I always planned to have a window that had the unaltered text, that highlighted what word was being read (even though the words being read had been cleaned up).

Eh2406 avatar Apr 19 '23 13:04 Eh2406