-
-
Notifications
You must be signed in to change notification settings - Fork 662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Rust example for the NVDA Controller Client #15771
Conversation
@DataTriny Given your previous investment in NVDA Controller examples and you're much more experienced with Rust than I am, could you have a quick look at the code please? |
Sure I will. I'm away from home until next wednesday though.
Le sam. 11 nov. 2023 à 11:26, Leonard de Ruijter ***@***.***>
a écrit :
… @DataTriny <https://github.com/DataTriny> Given your previous investment
in NVDA Controller examples and you're much more experienced with Rust than
I am, could you have a quick look at the code please?
—
Reply to this email directly, view it on GitHub
<#15771 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC3JTEFWVREFMBIVZ5WLJW3YD5HEJAVCNFSM6AAAAAA7HFBEUCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBWG43TMNRVGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestions from me. Looks good overall!
0 | ||
} | ||
|
||
fn main() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd try to have the main
function return Result<()>
and remove the calls to Result::unwrap
in favor of the ?
operator. The call to Result::expect
can stay since it provides a clearer error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good idea!
pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
||
pub fn test_if_running() -> Result<()> { | ||
let res = WIN32_ERROR(unsafe { nvdaController_testIfRunning() }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might be able to come up with a generic function to encapsulate your error handling logic and not repeat it everywhere right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do.
Ok(()) | ||
} | ||
|
||
pub fn braille_message(mesage: &str) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub fn braille_message(mesage: &str) -> Result<()> { | |
pub fn braille_message(message: &str) -> Result<()> { |
} | ||
|
||
pub fn braille_message(mesage: &str) -> Result<()> { | ||
let message = HSTRING::from(mesage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let message = HSTRING::from(mesage); | |
let message = HSTRING::from(message); |
@DataTriny Thanks a lot for your review. I think I have addressed everything. |
|
||
pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
||
fn is_succes(error: u32) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly you have a typo here. Maybe to_result(status: u32)
would be more appropriate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I'll rename accordingly.
pub type OnSsmlMarkReached = onSsmlMarkReachedFuncType; | ||
|
||
fn is_succes(error: u32) -> Result<()> { | ||
let res = WIN32_ERROR(error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having read windows-rs's doc, I think you should use WIN32_ERROR::ok
instead of your if
statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good catch, thanks! Function can now be a one liner.
Co-authored-by: Arnold Loubriat <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a good start for anyone interested in communicating with NVDA from a Rust program. Good job @LeonarddeR!
Thank you very much @DataTriny! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, I don't plan on reviewing the code itself, the only issue I picked up is with the code file licence headers
// Copyright(C) 2023 NV Access Limited, Leonard de Ruijter | ||
// This file is covered by the GNU Lesser General Public License, version 2.1. | ||
// See the file license.txt for more details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you use the more standard python headers? we don't have a license.txt, we use "COPYING"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a license.txt
in the controllerClient
folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, if the mention of licence.txt
is confusing, you can just use the copyright header for LGPL licensed code from our copyright headers wiki page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lukaszgo1, I wasn't aware of these guidelines on the wiki.
user_docs/en/changes.t2t
Outdated
@@ -125,6 +125,7 @@ Setting ``numCells`` is still supported for single line braille displays and ``n | |||
- Device info yielded by ``hwPortUtils.listUsbDevices`` now contain the bus reported description of the USB device (key ``busReportedDeviceDescription``). (#15764, @LeonarddeR) | |||
- For USB serial devices, ``bdDetect.getConnectedUsbDevicesForDriver`` and ``bdDetect.getDriversForConnectedUsbDevices`` now yield device matches containing a ``deviceInfo`` dictionary enriched with data about the USB device, such as ``busReportedDeviceDescription``. (#15764, @LeonarddeR) | |||
- When the configuration file ``nvda.ini`` is corrupted, a backup copy is saved before it is reinitialized. (#15779, @CyrilleB79) | |||
- Added an example to demonstrate using nvdaControllerClient.dll from Rust. (#15771, @LeonarddeR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be moved to "Changes to the NVDA Controller Client library:"
Link to issue number:
None
Summary of the issue:
The rust programming language is becoming more and more relevant, yet an example for the NVDA controller client is missing.
Description of user facing changes
None.
Description of development approach
Add a rust example, based on a workspace with two crates:
Testing strategy:
Test steps are in readme.md
Known issues with pull request:
This is blocked by #15734 for now.
Code Review Checklist: