refactor: rework extension API for iron-remote-desktop#762
Merged
Benoît Cortier (CBenoit) merged 1 commit intoApr 21, 2025
Conversation
Comment on lines
+207
to
212
| iron_remote_desktop::extension_match! { | ||
| match ext; | ||
| |pcb: String| { self.0.borrow_mut().pcb = Some(pcb) }; | ||
| |kdc_proxy_url: String| { self.0.borrow_mut().kdc_proxy_url = Some(kdc_proxy_url) }; | ||
| |display_control: bool| { self.0.borrow_mut().use_display_control = display_control }; | ||
| } |
Member
Author
There was a problem hiding this comment.
We directly use JsValue API without any smart trick.
No extra dependency required for that.
For now there is no extension requiring to pass an "object", but if we had one, we could use the Reflect module of js_sys, that we already depend on, to get the individual fields.
Coverage Report 🤖 ⚙️Past: New: Diff: -0.03% [this comment will be updated automatically] |
Comment on lines
+4
to
+40
| #[macro_export] | ||
| macro_rules! extension_match { | ||
| ( @ $jsval:expr, $value:ident, String, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_string() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, f64, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_f64() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, bool, $operation:block ) => {{ | ||
| if let Some($value) = $jsval.as_bool() { | ||
| $operation | ||
| } else { | ||
| warn!("Unexpected value for extension {}", stringify!($ident)); | ||
| } | ||
| }}; | ||
| ( @ $jsval:expr, $value:ident, JsValue, $operation:block ) => {{ | ||
| let $value = $jsval; | ||
| $operation | ||
| }}; | ||
|
|
||
| ( match $ext:ident ; $( | $value:ident : $ty:ident | $operation:block ; )* ) => { | ||
| let ident = $ext.ident(); | ||
|
|
||
| match ident { | ||
| $( stringify!($value) => $crate::extension_match!( @ $ext.into_value(), $value, $ty, $operation ), )* | ||
| unknown_extension => ::tracing::warn!("Unknown extension: {unknown_extension}"), | ||
| } | ||
| }; | ||
| } |
Member
Author
There was a problem hiding this comment.
Helper macro to extract extension values. This is not strictly needed, but it’s less boilerplate in the consumer code.
Alex Yusiuk (RRRadicalEdward)
approved these changes
Apr 21, 2025
Collaborator
Alex Yusiuk (RRRadicalEdward)
left a comment
There was a problem hiding this comment.
LGTM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Rework the extension API for iron-remote-desktop as per #749 (review)
I used this PR as basis: #761