Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/deep-link-linux-errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
deep-link: patch
deep-link-js: patch
---

On Linux, improved error messages when OS commands fail.
3 changes: 3 additions & 0 deletions plugins/deep-link/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ pub enum Error {
#[cfg(target_os = "linux")]
#[error(transparent)]
ParseIni(#[from] ini::ParseError),
#[cfg(target_os = "linux")]
#[error("Failed to run OS command `{0}`: {1}")]
Execute(&'static str, #[source] std::io::Error),
#[cfg(mobile)]
#[error(transparent)]
PluginInvoke(#[from] tauri::plugin::mobile::PluginInvokeError),
Expand Down
11 changes: 8 additions & 3 deletions plugins/deep-link/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ mod imp {
///
/// ## Platform-specific:
///
/// - **Linux**: Needs the `xdg-mime` and `update-desktop-database` commands available on the system.
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
pub fn register<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<()> {
#[cfg(windows)]
Expand Down Expand Up @@ -332,11 +333,13 @@ mod imp {

Command::new("update-desktop-database")
.arg(target)
.status()?;
.status()
.map_err(|error| crate::Error::Execute("update-desktop-database", error))?;

Command::new("xdg-mime")
.args(["default", &file_name, mime_type.as_str()])
.status()?;
.status()
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;

Ok(())
}
Expand Down Expand Up @@ -405,6 +408,7 @@ mod imp {
///
/// ## Platform-specific:
///
/// - **Linux**: Needs the `xdg-mime` command available on the system.
/// - **macOS / Android / iOS**: Unsupported, will return [`Error::UnsupportedPlatform`](`crate::Error::UnsupportedPlatform`).
pub fn is_registered<S: AsRef<str>>(&self, _protocol: S) -> crate::Result<bool> {
#[cfg(windows)]
Expand Down Expand Up @@ -439,7 +443,8 @@ mod imp {
"default",
&format!("x-scheme-handler/{}", _protocol.as_ref()),
])
.output()?;
.output()
.map_err(|error| crate::Error::Execute("xdg-mime", error))?;

Ok(String::from_utf8_lossy(&output.stdout).contains(&file_name))
}
Expand Down
Loading