mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-09-22 21:30:44 +02:00
refactor(deep-link)!: return Error::Execute when an OS command fails to run (#3603)
* refactor(deep-link)!: return Error::Execute when an OS command fails to run On Linux, `register`, `unregister` and `is_registered` now fail with the new `Error::Execute(command, io_error)` variant when `xdg-mime` or `update-desktop-database` cannot be spawned, instead of logging and returning the raw `Error::Io`. This is the change deferred to v3 in #2970. * docs(deep-link): unregister does not run OS commands
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"deep-link": major
|
||||||
|
---
|
||||||
|
|
||||||
|
**Breaking:** On Linux, failing to run `xdg-mime` or `update-desktop-database` in `register` and `is_registered` now returns the new `Error::Execute(command, io_error)` variant instead of logging the failure and returning the raw `Error::Io`.
|
||||||
@@ -23,21 +23,15 @@ pub enum Error {
|
|||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
ParseIni(#[from] ini::ParseError),
|
ParseIni(#[from] ini::ParseError),
|
||||||
|
/// Failed to run an OS command such as `xdg-mime` or `update-desktop-database`.
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[error("Failed to run OS command `{0}`: {1}")]
|
||||||
|
Execute(&'static str, #[source] std::io::Error),
|
||||||
#[cfg(mobile)]
|
#[cfg(mobile)]
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(v3): change this into an error in v3,
|
|
||||||
// see <https://github.com/tauri-apps/plugins-workspace/pull/2970#issuecomment-3244660138>.
|
|
||||||
#[inline]
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
pub(crate) fn inspect_command_error<'a>(command: &'a str) -> impl Fn(&std::io::Error) + 'a {
|
|
||||||
move |e| {
|
|
||||||
tracing::error!("Failed to run OS command `{command}`: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Serialize for Error {
|
impl Serialize for Error {
|
||||||
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -351,14 +351,12 @@ mod imp {
|
|||||||
Command::new("update-desktop-database")
|
Command::new("update-desktop-database")
|
||||||
.arg(target)
|
.arg(target)
|
||||||
.status()
|
.status()
|
||||||
.inspect_err(crate::error::inspect_command_error(
|
.map_err(|error| crate::Error::Execute("update-desktop-database", error))?;
|
||||||
"update-desktop-database",
|
|
||||||
))?;
|
|
||||||
|
|
||||||
Command::new("xdg-mime")
|
Command::new("xdg-mime")
|
||||||
.args(["default", &file_name, mime_type.as_str()])
|
.args(["default", &file_name, mime_type.as_str()])
|
||||||
.status()
|
.status()
|
||||||
.inspect_err(crate::error::inspect_command_error("xdg-mime"))?;
|
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -463,7 +461,7 @@ mod imp {
|
|||||||
&format!("x-scheme-handler/{}", _protocol.as_ref()),
|
&format!("x-scheme-handler/{}", _protocol.as_ref()),
|
||||||
])
|
])
|
||||||
.output()
|
.output()
|
||||||
.inspect_err(crate::error::inspect_command_error("xdg-mime"))?;
|
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;
|
||||||
|
|
||||||
Ok(String::from_utf8_lossy(&output.stdout).contains(&file_name))
|
Ok(String::from_utf8_lossy(&output.stdout).contains(&file_name))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user