|
@@ -6,9 +6,14 @@ use serde::Deserialize;
|
|
|
#[serde(tag = "cmd", rename_all = "camelCase")]
|
|
|
pub enum Cmd {
|
|
|
/// The execute script API.
|
|
|
- Execute { command: String, args: Vec<String> },
|
|
|
- /// The open URL in browser API
|
|
|
- Open { uri: String },
|
|
|
+ Execute {
|
|
|
+ command: String,
|
|
|
+ args: Vec<String>,
|
|
|
+ },
|
|
|
+ Open {
|
|
|
+ path: String,
|
|
|
+ with: Option<String>,
|
|
|
+ },
|
|
|
}
|
|
|
|
|
|
impl Cmd {
|
|
@@ -28,37 +33,16 @@ impl Cmd {
|
|
|
"shell > execute".to_string(),
|
|
|
))
|
|
|
}
|
|
|
- Self::Open { uri } => {
|
|
|
+ Self::Open { path, with } => {
|
|
|
#[cfg(shell_open)]
|
|
|
- {
|
|
|
- open_browser(uri);
|
|
|
- Ok(().into())
|
|
|
+ match crate::api::shell::open(path, with) {
|
|
|
+ Ok(_) => Ok(().into()),
|
|
|
+ Err(err) => Err(crate::Error::FailedToExecuteApi(err)),
|
|
|
}
|
|
|
+
|
|
|
#[cfg(not(shell_open))]
|
|
|
Err(crate::Error::ApiNotAllowlisted("shell > open".to_string()))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-#[cfg(shell_open)]
|
|
|
-pub fn open_browser(uri: String) {
|
|
|
- #[cfg(test)]
|
|
|
- assert!(uri.contains("http://"));
|
|
|
-
|
|
|
- #[cfg(not(test))]
|
|
|
- webbrowser::open(&uri).expect("Failed to open webbrowser with uri");
|
|
|
-}
|
|
|
-
|
|
|
-#[cfg(test)]
|
|
|
-mod test {
|
|
|
- use proptest::prelude::*;
|
|
|
- // Test the open func to see if proper uris can be opened by the browser.
|
|
|
- proptest! {
|
|
|
- #[cfg(shell_open)]
|
|
|
- #[test]
|
|
|
- fn check_open(uri in r"(http://)([\\w\\d\\.]+([\\w]{2,6})?)") {
|
|
|
- super::open_browser(uri);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|